Page 23 - MSDN Magazine, November 2017
P. 23

detected. In addition, the scrollbar provides the so-called Minimap mode. When this mode is enabled, the scrollbar displays a preview of the source code for easy navigation, as shown in Figure 5.
You enable Minimap mode by right-clicking the scrollbar and selecting Show Minimap. You can click an area on the map and the code editor will move the cursor to the appropriate point. To disable Minimap mode, you right-click the scrollbar again and select Show Tasks. Minimap mode is particularly useful with long files and helps you have a visual representation of the whole file.
Browsing Objects in a Code File
Visual Studio for Mac offers visual ways to easily browse type and members within a code file. Each code editor window shows breadcrumbs that you can click to see a list of the types defined in
the active editor; when you select a type, an additional tab allows you to display the list of its members. Additionally, you can use the Document Outline pad to get a visual representation of the type structure in the active file (see Figure 6).
Minimap mode is particularly useful with long files and helps you have a visual representation of the whole file.
Notice how different icons represent the differ- ent kinds of members. You might already know the Document Outline pad for its capabilities to show the visual hierarchy of the UI, but you can also use it to get a view of a type’s structure, which is very helpful. You can simply double-click an object within Document Outline and the editor will move the cursor to its definition.
Working with Code Snippets
Visual Studio for Mac supports IntelliSense code snip- pets—pre-written code block templates that can be customized to match your needs. If you have expe- rience with Visual Studio on Windows, you already know what code snippets are. In Visual Studio for Mac, you have two options to insert a code snippet. The first option is right-clicking the code editor and then selecting Insert Template. A list of available code snippets will appear and you just select the one you need. The second option is picking up a code snip- pet from the IntelliSense completion list as you type. Figure 7 shows an example where a code snippet is highlighted (you press Tab twice to insert the snippet).
Code snippets are represented with the (...) icon, which makes them immediately recognizable. In both cases, a tooltip describes the code snippet’s purpose when you hover over its name with the mouse. Visual Studio for Mac also lets you create new custom code snippets and edit existing ones from within the IDE, without the need of external tools. To accomplish this, select Preferences in the Visual Studio menu, then in the Preferences dialog locate and select the Code Snippets item under Text Editor. There you’ll see a list of code snippets grouped by language. If you select an existing snippet, you just press the Edit button to edit the code. If you instead click Add, you will have the option to create a new code snippet. This is done in the New template dialog, where you provide a keyboard shortcut, a description, a MIME type, a language group and, of course, the source code. Figure 8 shows an example.
November 2017 19
Figure 5 The Scrollbar Minimap Mode
Figure 6 Browsing Objects in a Code File msdnmagazine.com






















































































   21   22   23   24   25