RAD Studio Delphi Productivity Tips: Bookmarks and Navigator Plugins

ADSoft

Местный
Регистрация
1 Окт 2007
Сообщения
223
Реакции
86
Credits
1,062

Delphi Productivity Tips: Bookmarks and Navigator Plugins

Posted by david on Thursday, 26 August 2021

A couple of years ago, I blogged about my Для просмотра ссылки Войди или Зарегистрируйся, which included two plugins, originally by Parnassus but Для просмотра ссылки Войди или Зарегистрируйся. I would like to highlight them again and go into a little more detail to continue in my "Delphi Productivity Tips" series. The two plugins are Для просмотра ссылки Войди или Зарегистрируйся and Для просмотра ссылки Войди или Зарегистрируйся, both free and available on GetIt for Delphi 10.3 and up.

If I had to choose only one of these plugins, it would be hard. They work very well together and are an example of the phrase, "the whole is greater than the sum of the parts." I'll start with Bookmarks.

Bookmarks​

Delphi has had multiple bookmarks in its code editor for a long time. Simply hit Ctrl+Shift+[number] to set one and then Ctrl+[number] to jump to it. They are specific to the file within they were set (in other words, you can't jump to one from a different file) but you can use numbers 1-9 and use the same numbers for different bookmarked places in different files.

If you're like me, you can only remember a few bookmarks at a time. Sometimes, in a long unit, with several similar sections of code, I'll set up to 5 or 6 bookmarks and if I use them in a consistent or logical manner, can actually remember where each of them go--it's useful to bounce between them. But I seldom remember, much less use, that many bookmarks.

The idea of bookmarks is great. The most useful aspect, though--jumping back to where you were editing--is often overshadowed by the fact you often have to jump to a different unit; standard bookmarks only work within the current file. So, before you can use the bookmark to return to your editing, you have to first get back to the unit where the bookmark was created. If you have several files open and you were browsing through other parts of the project, you may not remember the unit name--at least I find that to be the case.

The Bookmarks plugin adds a most useful feature to the standard bookmarks that addresses all these issues: stack bookmarks! The idea is you place a single bookmark, go browse somewhere else in the same or different unit, then hit Escape and pop right back to where you were. This means you don't have to remember what number you assigned and you don't have to remember which file you were in because stack-based bookmarks work across files! Additionally, you can place additional stack-based bookmarks and they add up, popping back off as you use them.

BookmarksPlugin.png
The standard hotkey for setting (or dropping) one is based on the ancient WordStar-style hotkeys, Ctrl+K and Ctrl+G and to pick it back up, Ctrl+Q and Ctrl+G. There were a few of these Ctrl-based hotkeys I remembered years ago but there got to be so many of them that they're all a blur now. Fortunately, the new Bookmarks plugin has options to change this.

After installing the Parnassus Bookmarks plugin from GetIt, open Tools | Options and expand Third Party | Parnassus and select Bookmarks. There are several options for configuring how they work and how the Bookmarks pane in the IDE looks--which is nicely enhanced with this plugin. You can also configure some shortcuts.

There are a couple of hotkeys I use most often:

  • Ctrl+Shift+B: Add or remove a caret bookmark. This is the stack-based bookmark I have described above. The default is pretty easy to remember.
  • Esc: Jump to previous caret. This "picks up" or "collects" the stack-based bookmark and removes it. The default is what I would expect to back out of something or return.
So while editing, I can hit Ctrl+Shift+B, navigate somewhere else, even a different file, then just hit Escape and I'm immediately back where I was editing. Cool!

Speaking of navigating, let's talk about the partner plugin, also originally from Parnassus, that aids in getting around in the code: Navigator.

Navigator​

NavigatorPlugin.png

The Navigator plugin has two main features: Для просмотра ссылки Войди или Зарегистрируйся and Для просмотра ссылки Войди или Зарегистрируйся. The "Go To" feature, combined with stack-based (or "caret") bookmarks, is where the plugin combo shines.

The default shortcut key is Ctrl+G which activates a pop-up "Go To" window with incremental searching for a list of the current file's contents. But it's not general text search, it knows about the sections of your Delphi unit, about classes, methods, properties and more. And as you type, it filters the list and then you can use the arrow keys to select the item you need, hit Enter and two wonderful things happen: 1) a stack-based bookmark is dropped where you currently are in the code, and 2) you're immediately taken to the selected line in the file. When you're done, just hit Escape (or your configured Bookmarks shortcut for picking up the last caret bookmark to resume editing where you left off.

What I use this for most is to add units to the uses clause as I need them. For example, I start to use a method from the TPath class for the first time in a unit; all I do is hit Ctrl+G, type "impl" (the first few letters of the word "implementation"), hit DownArrow once to select "uses" (or just go to the implementation section if there's no uses clause in that unit yet), add System.IOUtils to the unit list, and hit Escape to continue coding right where I left off!

This is a big time saver--so much more convenient than dropping a numbered bookmark, searching for the implementation section, adding the unit, then trying to remember the numbered book mark I had just set!

NavMiniMap.png
The Mini Map feature of the Navigator plugin is also very nice. It provides a side-bar in the editor window with a tiny overview of the entire file with the currently viewed lines as a darkened area of the map to indicate where you are in the file. At a quick glance, you can tell if you're near the top of the file, somewhere in the middle, or near the bottom. Plus, it's interactive: you can drag the darkened rectangular area on the map up or down to quickly scroll the file to a different place in the file--without moving the cursor from it's current edit place. This is nice to scroll up and take a look at something without needing to set a bookmark--and is much faster than doing this with the mouse wheel, especially for large files. You can also hover the mouse over the mini map and see the lines of text corresponding to the lines under the mouse in a hovering window that disappears as soon as you move the mouse off the mini map.

There are options to set the size of the mini map and change the default colors.

Together, these two plugins add amazing convenience and time-saving capabilities to Delphi's code editor. Both are free and install quickly from GetIt (Для просмотра ссылки Войди или Зарегистрируйся; Для просмотра ссылки Войди или Зарегистрируйся).