In RAD Studio 10.3.1, we’ve added two new really useful productivity tools to the IDE, which improve navigation: finding your code, and moving around within your code. A couple of days ago, we looked at Bookmarks; today, let’s look at Navigator.
These two were previously third-party tools that were very popular with thousands of Delphi and C++Builder developers, and which we’re glad to integrate into the IDE itself to bring these useful features to every customer today. These features are provided via GetIt: open the Tools menu and choose GetIt Package Manager, and then once it’s loaded click the IDE Plugins section on the left. Or, you can use the search box to locate and install them.
Table of Contents
The Go To window (Delphi)
When you’re writing code or debugging, it’s very common to want to find specific items in your code, such as methods that interact with the code you’re currently looking at, or the uses clause to add a unit, or similar. Do you ever ask yourself question like,
- I want to go to method Foo now – where is it?
- I need to add a unit. Let me scroll to the uses clause
- What is the getter method for property TMyForm.MyProperty?
Usually, developers scroll, or remember roughly where a method is, or use methods like Ctrl+Shift+Up to go to a class, scroll to find the method definition, and same shortcut (or +Down) to go to the method implementation itself, or just search the unit (F3, F3, F3, F3, twenty times to find where a method is located not just where it’s called.) All of these work, but they’re not great.
Navigator solves this. Navigator speaks Delphi, so it knows what the useful things in your unit are. Press Ctrl+G – G for Go – and you will get a list of all the useful parts of the current unit.
Here you can see the window as it appears straight after pressing Ctrl+G (in this case, in the main form of the Mazes application which you can download from our github.) This window lists:
- All classes (such as TForm1), records, enums, and other types
- All methods, properties, and fields in those classes and records
- All global variables and constants (and optionally, method-local constants too)
- All standalone methods
- All useful unit sections (uses clauses, type clauses, interface section, implementation section, etc)
In other words, everywhere that you might want to go to, it knows about. Select anything, press Enter, and it will take you there. You can type in the search field and it filters, and press up or down arrow keys to change which of the filtered results is selected without focus leaving the search edit box.
This window can be filtered. Just start typing. For example, suppose that in the above code, you know there’s a function ‘ShouldStopPlaying’ and you want to go there. Type ‘stop’ and you immediately get down to five results:
and if you want to filter further, to show just the function, start typing ‘func’…
and press Enter. You will go to that method.
You can do similar things to search for a field, a procedure, a method on a class (start typing the method, but you can also type part of the class name). It filters on the fly and you rarely have to type very much for it to show the item you’re looking for.
The window shows all matching items and usually selects the top result by default, but if you have an exact match, such as typing a class name in full, it will always highlight that exact match. For methods that are in both the interface and implementation section, it will also show entries for both those places. This behaviour (both interface and implementation, and matching with a class name too) can be changed in the settings – as can many other items; the settings are comprehensive and you can configure Navigator’s Go To window to your liking.
It has a number of very Delphi-aware items. One example is knowing that properties can be backed by fields and methods. Here’s a short video of searching for a property and seeing the getter and setter listed to. Note that in the video, although I could type ‘get’ (or ‘getter’, or even just enough letters to filter it) to filter for the getter, Navigator is aware that in Delphi terminology, properties have a read and a write backer. So, in this video I type ‘read’ which also matches.
What you’re watching is video a developer asking, “take me to however this property’s getter is implemented”. It shows it, press Enter, you’re there. This is really useful.
Note that this means you can navigate entirely using the keyboard. You do not need to use the mouse at all. Not switching between the keyboard and mouse can really improve productivity, especially if you’re a developer who prefers using only the keyboard.
Minimap (Delphi and C++)
Navigator adds one other useful tool to the IDE: visual navigation in the code editor. You may be familiar with minimaps from other IDEs. A minimap is a small preview of the code in the entire file that sits on one edge of the editor, and can be used to navigate like a scrollbar. It is, effectively, a marked-up scrollbar showing the code in the entire unit.
In this image, you can see there is a minimap on the right hand side of the editor. This shows the entire unit, in small form, syntax highlighted for both Delphi and C++Builder. The currently visible part – that is, the code visible in the editor – is the same background color as the editor itself; the bits that are offscreen above and below are dimmed. You can mouse over and a popup hint appears showing you the code at any part of the unit, so it’s a really fast way to scroll through and see the content of the unit without even scrolling. You can click anywhere to scroll there, or click and drag to scroll as well.
All of this is configurable – for example, you can choose to highlight the visible area, instead of dimming the non-visible area, or change the scale at which the minimap is drawn. You’ll also notice that in this screenshot the editor scrollbar isn’t visible, and that’s because the minimap is an excellent replacement. You can turn that back on as well, though, if you want. This same setting also controls optionally hiding the horizontal scrollbar, which, when enabled (the default) changed the editor from always showing the horizontal scrollbar to only showing it if necessary, such as if there is a long line of code, or if you are already scrolled. Hiding the scrollbars when they’re not necessary makes the look and feel of the editor much cleaner.
One nice touch is that when the Go To window is open, all filtered results are highlighted in light orange on the minimap, with the currently selected one in more solid orange. This lets you see visually where the items you’re going to are located.
You can access the Navigator settings by clicking the gear icon at the bottom of the minimap, the Settings button on the Go To window, or through the Tools > Options menu item. It is currently in the Third Party section, since it was recently integrated from a third party product.
Settings are very extensive and allow you to customise the items shown in the Go To window very extensively, the shortcut, if a caret bookmark is dropped before navigating (see Bookmarks – this allows you to go somewhere and press Escape to return), the minimap scale, its preview hint, the colors it uses, how it highlights the visible and off-screen areas, and even how it renders (you can, if you wish, make it render the actual unit text very very small, instead of rendering only the syntax highlighted colours as it does today.)
Useful things to remember:
- Ctrl+G to go
- Filter by typing, and you don’t need to type the complete words. “func foo” will likely be enough to show you “function TForm1.FooBar : Integer”
- You can filter by anything shown in the text, such as the class name, the return type, etc
- The minimap is a great scrollbar replacement
Navigator is a fantastic addition to the IDE, and really helps you move around your code fast. Being able to jump to any useful area of code, say to a specific method, wholly from the keyboard with no mouse interaction is very useful. The minimap is a modern touch and a useful visual way of navigating your code. A large variety of settings and tweaks help you customise it perfectly to your workflow.
To install, open the Tools menu and choose GetIt Package Manager, and then once it’s loaded click the IDE Plugins section on the left and you’ll see Navigator listed. Or, you can use the search box to locate it. Select it, and click Install.
We hope you’ll find this a great addition to the IDE! Don’t forget to check out the other productivity addon to the 10.3.1, Bookmarks.