Source View is a simple text editor supplied in the CASEVision environment that displays the lines of text in a source code file. You can start Source View from most CASEVision tools by choosing the appropriate menu command, usually “Source View.” In some tools, you can double-click icons representing source code to start Source View. Source View displays the source code, scrolled to the appropriate place.
This chapter covers these topics:
The basic Source View window is shown in Figure 4-1 with its two standard menus displayed and major areas indicated.
All Source View windows have these components:
| menu bar |
| |
| display area |
| |
| annotation column |
| |
| annotated scroll bar |
| |
| file specification field |
| |
| source status indicator |
|
The Source View menus and annotation margin icons vary depending on the tool from which Source View is accessed. For example, the Source View window executed from the CASEVision/WorkShop Debugger has margin annotations for traps and a program counter. and two additional menus: Traps and PC. The Source View window from Profiling View in the WorkShop Performance Analyzer displays usage statistics in the annotation margin.
| “Open...” |
| ||
| “Save” |
| ||
| “Save As...” |
| ||
| “Save As Text...” |
| ||
| “Open Separate...” |
| ||
| “Insert File...” |
| ||
| “Clone” |
| ||
| “Fork Editor” |
| ||
| “Recompile” |
| ||
| “Make Editable”/“Make Read Only” |
| ||
| “Search...” |
| ||
| “Go To Line...” |
You can enter a line number or use the slider at the top of the box to select a line number. You do not have to display line numbers to use this feature. | ||
| “Versioning” |
The “Versioning” submenu appears in Figure 4-4. Selecting any of these options displays a shell in which you can access the configuration management tool. The selections in the submenu are: | ||
| “Versioning”:“CheckIn” |
| ||
| “Versioning”:“CheckOut” |
| ||
| “Versioning”:“UncheckOut” |
| ||
| “Close” |
|
| “Show Line Numbers”/“Hide Line Numbers” |
| |
| “Preferences...” |
|
To start Source View, choose “Source View” from the Views menu (if your current CASEVision tool does not have a Views menu, consult the appropriate user guide to find out how to access Source View). In most CASEVision graphical views, double-clicking a node (rectangle) displays a Source View window containing the selected code.
Some alternative methods for starting Source View from the CASEVision WorkShop tool are:
In the Performance Analyzer, clicking the Source button in the main window, double-clicking a node in Call Graph View, or double-clicking a call stack in Heap View all display Source View.
In the Static Analyzer, choosing “Edit Selected Item” from the Admin menu, or double-clicking an element in the Static Analyzer's main display brings up Source View.
When you start the Source View window from a CASEVision tool, Source View displays the source code selected from the parent tool. To access a different source code file, choose “Open...” from the File menu and make a selection from the File Browser.
You can also open a new file using the file specification field in the bottom left corner of the Source View window. Move the cursor into the area, type the new file's pathname, and press <Enter>. If you enter a filename that doesn't already exist, Source View creates a new file using that filename.
The Source View window displays source code in its display area, the central area of the window. Use the scroll bar at the right to scroll through the lines of text. To see the full length of each line of code, drag any corner of the window out to increase the window width. If you're working with exceptionally long lines of code, or want to keep the Source View window small, you can add a horizontal scroll bar to the Source View window by adding the line
*textEdit.scrollHorizontal: True |
to your .Xdefaults file before you start Source View. Deleting the line from .Xdefaults or changing True to False removes the horizontal scroll bar the next time you start Source View.
To view a specific line of code in Source View, choose “Go To Line...” from the File menu to open the Go To Line dialog box shown in Figure 4-3.
You can enter the line number in either of two ways:
Drag the slider in the top of the window to the desired line number.
Move the cursor into the Go to line field and type the line number you want.
Once you set the line number, either click the OK button or press <Enter> to close the window and jump to the line number in Source View's display area. If you click the Cancel button, you close the Go To Line dialog box without scrolling the text in the display area.
Source View can display more than just the text of a source code file. It displays additional information in its annotation margin, which you control through Display menu commands. If you choose “Show Line Numbers,” you'll see icons specific to the CASEVision tool. For example, Figure 4-7 shows a program counter at a stop trap, a stop trap, and a sample trap in a WorkShop Debugger Source View window.
By default, the annotation margin automatically shows icons. To hide the icons or the line numbers, choose either “Hide Icons” or “Hide Line Numbers” from the Display menu.
To search for text in a source code file, choose “Search” from the File menu, which opens the Search dialog box (shown in Figure 4-8).
The Search dialog box provides a Search field where you can enter a target string. It also has a set of buttons that offers three search types:
| Literal Case Sensitive |
| |
| Literal Case Insensitive |
| |
| Regular Expression |
|
To search for text, move the cursor into the Search field and enter the search text; then click the search option you want if it's not already set. Press <Enter> or click the Apply button to start the search. Source View searches through the entire file for matching text and indicates matches by highlighting the text where they occur. To show you where matches occur throughout the file, Source View displays search target indicators along the length of the scroll bar as shown in Figure 4-8. To scroll to a match, either click the indicator with the middle mouse button or drag the scroll handle to it. If a search is unsuccessful, no search target indicators appear on the scroll bar.
Each time you press <Enter> or click Apply, Source View removes any existing search highlighting and indicators and adds new highlighting and indicators as the result of the new search. To clear highlights and indicators without starting a new search, click the Reset button, which clears the search text from the Search text area and removes highlights and indicators.
To close the Search window, click on either the Cancel or the Close button. Cancel closes the window and removes any highlighting and indicators left in the display area by the last search. Close closes the window and leaves highlighting and indicators in place.
A source code file viewed in Source View has one of the two modifiable statuses: Read Only or Editable. When the status is Read Only, you can't edit the source code file. When the status is Editable, you can edit text and make changes to the source code file. The source status indicator, located below the display area on the right side of the window, shows the status of the current source code file. It also displays Modified if you've made changes to the source code that haven't yet been saved
Generally, when you start Source View from a CASEVision tool, it displays the source code involved in the session, set to Read Only. To change the write status, choose “Make Editable” from the File menu. To change a file from Editable back to Read Only, choose “Make Read Only” from the File menu.
Editing text in an editable file follows typical text editing conventions. To select a block of text, drag from the beginning to the end of the text you want. To select a word, double-click the word. To select a line, triple-click the line.
Once you've selected text, you can delete it by pressing <Back Space>. If you type new characters while text is selected, you replace the selected text with the new text. To copy selected text to another location, move the cursor to the new location and middle-click. As long as the original text is selected, you can keep middle-clicking to insert copies of it into new locations.
To insert new text in the display area, click at the insertion point, then type new text. You can press the <Back Space> key to delete characters to the left of the insertion point.
If you want to insert an entire file as new text, click on the point where you want to insert, then choose “Insert File...” from the File menu. A file browser opens, where you can choose the file you want to insert. When you click OK to close the browser and load the file, Source View inserts the text of the file at the insertion point in the existing file.
Once you've made changes to a source code file, you can save them using any of three commands in the File menu:
| “Save” |
| |
| “Save As...” |
| |
| “Save As Text...” |
|
If you'd rather edit a source code file using a text editor other than Source View, choose “Fork Editor” from the File menu. By default, this command opens a new shell that runs vi and works on the file in Source View. To set up Source View so that it uses a different editor when you choose “Fork Editor,” add a line to the .Xdefaults file:
*editorCommand: <editor> |
where <editor> is the text editor you wish to start. The default is
*editorCommand: xwsh -e vi +%d |
which opens an X shell, executes vi using the current file as its target, and scrolls to the line number supplied after %d if there is one. You might try
*editorCommand: gnuemacs +%d |
or even
*editorCommand: jot |
if you want to edit using either gnuemacs or jot.
Source View allows you to open other Source View windows by choosing either “Clone” or “Open Separate...” in the File menu. “Clone” opens a Source View window that displays the same file in the same location that you're viewing in the original window. “Open Separate...” opens a file browser where you can choose another source code file, and then opens a Source View window that displays the newly chosen file.
If you've started Source View from another CASEVision tool, such as the WorkShop Debugger or Static Analyzer, then it may display traps or search target indicators created by the parent tool. When you clone a Source View window showing this additional information, the information also appears in the cloned Source View window. Whenever you change a trap or work with the program counter in one of the cloned Source View windows, the trap and PC icons in the other Source View windows are updated to match.
Editing changes or viewpoint changes in one cloned Source View window aren't reflected, however, in other clones. When you scroll to a new location or change the text in one window, those changes don't appear in the other windows. Source View does provide a safeguard, though, and announces changes made to a file by one window with messages about the change that appear in the cloned windows.