Chapter 35
Figure 35-45
More information on using the Data Sources window is covered in Chapters 30 and 31.
Workspace Navigation
This section describes a few tricks you can employ when navigating within Visual Studio 2005 that can help you write and debug your application.
Full Screen Mode
Most developers at some stage or another have cursed because no matter how big their monitor is, they can’t quite fit everything onto the screen. Visual Studio 2005 supports running in full screen mode, which will give you back those lost centimeters. This can be invoked from the View menu, and a Full Screen release button appears in the menu bar. By default, none of the extra windows, such as the Toolbox or the Solution Explorer, are visible. These can be displayed from the View menu, and the configuration will be automatically saved for the next time you work in full screen mode.
In Figure 35-46 you can see the Full Screen release button at the top of the window. Notice that, as you would expect, Visual Studio 2005 takes up the entire screen.
Navigation Keys
Although using the mouse is good for dragging around controls on a form or designing an XML schema using the visual designer, when you write code it is inconvenient to have to switch back to the mouse to navigate. This section shares a couple of shortcuts that can make navigating with the keyboard easier than with the mouse. In some cases the keyboard shortcuts are modified as part of the profile you have selected. If the shortcuts mentioned in this section do not work, use the Keyboard node in the Options window to find the command and the associated keyboard shortcut.
Forward/Backward
As you move within and between files, Visual Studio 2005 tracks where you have been, in a similar way that a web browser tracks the sites you have visited. Using the Navigate Forward and Navigate Backward items from the View menu you can easily go back and forth between files that you are working on. The keyboard shortcut to navigate backward is Ctrl+–. To navigate forward again it is Ctrl+Shift+–.
Workspace Control
Figure 35-46
Next/Previous Task
The View menu has items to move to the Next and Previous tasks. In fact, there are also commands to move to the Next and Previous error. If the profile you selected has a keyboard shortcut assigned to these commands, they will appear next to the command in the View menu. To specify a shortcut, or to reassign the command to another keyboard combination, select the Keyboard node from the Options dialog, shown in Figure 35-47.
Chapter 35
In the “Show commands containing” text box, enter part of the command you are looking for — in this case, the NextTask command. Once the correct command has been located, you can assign a keyboard shortcut by pressing the new combination followed by the Assign button.
Between Windows
In a similar style to navigating between running programs using the Alt+Tab combination, you can use Ctrl+Tab to navigate between open files and windows within Visual Studio 2005. Once the navigation window is displayed, shown in the center of Figure 35-48, you can release the Tab key (keep holding the Ctrl key, though) and use the arrow keys to select the file or window you want.
Figure 35-48
Summar y
This chapter provided an overview of the numerous windows available in Visual Studio 2005. You also learned how to navigate using a couple of keyboard shortcuts, which will make you a more efficient developer.
The rest of this part of the book focuses on other aspects of Visual Studio 2005 that can save you time when building an application, such as Find and Replace, the topic of the next chapter.
Find and Replace
In the current wave of development technology, find and replace functionality is expected as a fundamental part of the toolset, and Visual Studio 2005 delivers on that expectation. However, unlike other development environments that enable you to perform only simple searches against the active code module, the Visual Studio IDE includes the capability to perform rapid find and replace actions on the active code module, the active project, or right across the solution.
It then goes an extra step by giving you the capability to search external files and even whole folder hierarchies for different kinds of search terms and to perform replacement actions on the results automatically. This chapter shows you how to invoke and control this powerful tool.
Introducing Find and Replace
The find and replace functionality in Visual Studio 2005 is split into two broad tiers with a shared dialog and similar features: Quick Find, and the associated Quick Replace, is for searches that you need to perform quickly on the document or project currently open in the IDE. The two tools have limited options to filter and extend the search, but as you’ll see in a moment, even those options provide a powerful search engine that is beyond that you’ll find in most applications.
The second, extended tier is the Find in Files and Replace in Files commands. These functions enable you to broaden the search beyond the current solution to whole folders and folder structures, and even perform mass replacements on any matches for the given criteria and filters. Additional options are available to you when using these commands, and search results can be placed in one of two tool windows so you can easily navigate them.
Chapter 36
In addition to these two groups of find and replace tools, Visual Studio also offers two other ways to navigate code:
Find Symbols: Rather than strings of text, you can use Find Symbols to locate the symbols of various objects and members within your code.
Bookmarks: You can bookmark any location throughout your code and then easily go back to it, either with the Bookmarks window or by using the Bookmark menu and toolbar commands.
Quick Find
Quick Find is the term that Visual Studio 2005 uses to refer to the most basic search functionality. By default, it enables you to search for a simple word or phrase of text within the current document, but even Quick Find has additional options that can extend the search beyond the active module, or even to use wildcards and regular expressions in the search criteria.
To start a find action, press the standard keyboard shortcut Ctrl+F or select the Edit Quick Find menu command. Visual Studio will display the basic Find and Replace dialog, with the default Quick Find action selected (see Figure 36-1).
Figure 36-1
Type the search criteria into the Find What text box, or select from previous searches by clicking on the drop-down arrow and scrolling through the list of criteria that have been used. By default, the scope of the search is restricted to the current document or window you’re editing, but the Look In drop-down list gives you additional options based on the context of the search itself. For instance, if you’re editing a Visual Basic code module, you’ll see additional scopes such as Current Block, while searching within a tool window will display a Current Window option.
The various scopes available to you in a typical search action are as follows:
Selection: Only available when you have a section of text selected, this option restricts the search to only selected text in the active document.
Current Block: Searches the current block of code. This could be a subroutine or other procedure, a class definition, or even an entire module file, depending on where the current cursor is.
Current Document: Allows you to search the active document in its entirety
Current Window: Used for tool window searches
Find and Replace
All Open Documents: Use this option to restrict the search to all documents that you currently have open in the workspace.
Current Project: Searches with this option selected will be conducted against every file (visible or not) in the project to which the active document belongs.
Find and replace actions will always wrap around the selected scope looking for the search terms, stopping only when the find process has reached the starting point again. As Visual Studio finds each result, it will highlight the match and scroll the code window so you can view it.
If the match is already visible in the code window, Visual Studio will not scroll the code. Instead, it will just highlight the new match. However, if it does need to scroll the window, it will attempt to position the listing so the match is in the middle of the code editor window.
If the next match happens to be in a document other than the active one, Visual Studio will open the new document in a new tab in the workspace.
Quick Replace
Performing a Quick Replace action is similar to performing a Quick Find. You can switch between Quick Find and Quick Replace by clicking their respective buttons at the top of the dialog window. If you want to go directly to Quick Replace, you can do so with the keyboard shortcut Ctrl+H or the menu command Edit Quick Replace. The Quick Replace options (see Figure 36-2) are the same as those for Quick Find, but with an additional field to allow you to specify what text should be used in the replacement.
Figure 36-2
The Replace With field works in the same way as Find What — you can either type a new replacement string or choose one from any you’ve previously entered with the drop-down list provided.
Quick Find and Replace Dialog Options
Sometimes you will want to filter the search results in different ways, and that’s where the find options come into play. First, to display the options section (available in all find and replace actions), click the expand icon next to Find Options. The dialog will expand to show a set of checkbox options and dropdown lists from which you can choose, as shown in Figure 36-3.
Chapter 36
Figure 36-3
These options enable you to filter the search results as follows:
Option |
Purpose |
|
|
Match case |
The match will only be made if it meets the exact case that you enter |
|
for the criteria. |
Match whole word |
Only finds matches that are made up of exactly the term you enter. |
|
This allows you to filter out embedded words; for example, searching |
|
for the won’t return then or there. |
Search up |
Search from the current point and up. This mode will still wrap |
|
around, but allows you to find previous matches easily. |
Search hidden text |
Searches in collapsed regions of the code. By default, this option is |
|
inactive, and any matches that are in collapsed sections of the docu- |
|
ment are not returned. |
Use |
In addition to regular text searches, you can choose to perform |
|
searches that include either regular expressions or wildcards. |
|
|
Wildcards
Wildcards are simple text symbols that represent one or more characters, and are familiar to many users of Windows applications. The following table lists wildcard characters and what they represent:
Wildcard Symbol |
Expression |
Purpose |
|
|
|
? (Question Mark) |
Single character |
Matches any single character. It must |
|
|
match at least one. |
# (Hash) |
Single digit |
Same as ? but only matches digits |
|
|
|
|
|
|
Find and Replace |
|
|
|
|
|
Wildcard Symbol |
Expression |
Purpose |
|
|
|
|
|
* (Asterisk) |
Zero or more |
Matches any number of characters, |
|
|
|
including zero. For example, my*car will |
|
|
|
find mycar, my car, and my own car. |
|
[ ] (Square Brackets) |
Any one character in the set |
Matches any one character listed |
|
|
|
between the square braces. Use [! ] to |
|
|
|
invert the match to only find characters |
|
|
|
not in the list. |
|
\ (Backslash) |
Escape |
Indicates that the next character should |
|
|
|
be treated as a literal. For example, \? |
|
|
|
will match a question mark. |
|
|
|
|
Regular Expressions
Regular expressions take searching to a whole new level, with the capability to do complex text matching based on the full RegEx engine built into Visual Studio 2005. Chapter 39 deals with regular expressions in depth, so you’re encouraged to read through that chapter if you want to use this mode.
However, it’s worth mentioning the additional help provided by the Find and Replace dialog if you choose to use regular expressions in your search terms. When regular expressions are active, a small right-pointing arrow is enabled next to the Find What area (and Replace With if the dialog is in Replace mode). Clicking on this arrow shows the expression builder menu shown in Figure 36-4. From here you can easily build your regular expressions with the most commonly used regular expression phrases and symbols, with English descriptions of each in the menu.
Figure 36-4
Chapter 36
Find in Files
The really powerful part of the search engine built into Visual Studio is found in the Find in Files command. Rather than restrict yourself to a single document or project, Find in Files gives you the ability to search entire folders (along with all of their subfolders), looking for files that contain the search criteria.
The Find in Files dialog can be invoked via the menu command Edit Quick Find. Initially, the Quick Find dialog is shown, as described previously in this chapter. To switch over to the Find in Files mode, click the small drop-down arrow next to Quick Find and choose Find in Files. Alternatively, a much quicker method to show the dialog is to use the keyboard shortcut Ctrl+Shift+F.
Most of the Quick Find options are still available to you (see Figure 36-3), including the wildcard and regular expression searching, but instead of choosing a scope from the project or solution, the Look In field is used to specify where the search is to be performed. Either type the location you wish to search or click the ellipses to display the Choose Search Folders dialog, shown in Figure 36-5.
Figure 36-5
You can navigate through the entire file system, including networked drives, and add the folders you want to the search scope. This enables you to add disparate folder hierarchies to the one single search action, and, as Figure 36-5 implies, name them as a specific folder set that you can retrieve for future searches.
Find Dialog Options
Because the search is being performed on files that are not normally open within the IDE, the two find options normally used for open files — namely, Search up and Search hidden text — are not present. However, in their place is a filter that can be used to search only on specific file types.
The Look at These File Types drop-down list contains several extension sets, each associated with a particular language, making it easy to search for code in Visual Basic, C#, J#, and other language-based projects. You can type in your own extensions too, so if you’re working in a non-Microsoft language, or just
Find and Replace
want to use the Find in Files feature for non-development purposes, you can still filter the search results only to those that correspond to the file types you want.
In addition to the Find options, there are also configuration settings for how the results should be displayed. For searching only, you can choose one of two different results windows, which enables you to perform a subsequent search without losing your initial action. The results can be quite lengthy if you show the full output of the search, but if you’re interested only in finding out which files contain the information you’re looking for, check the Display File Names Only option and the results window will only be populated with one line per file, as shown in Figure 36-6.
Figure 36-6
Results Window
When performing a Find in Files action, results are displayed in one of two Find Results windows. These windows appear as open tool windows docked to the bottom of the IDE workspace. For each line that contained the search criteria, the results window displays a full line of information, containing the filename and path, the line number that contained the match, and the actual line of text itself so you can instantly see the context (see Figure 36-7).
Figure 36-7