The Source Code Viewer

Access: View | Other Element Tools | Source Code.

The Source Code viewer can be used to view any source code you are opening. If a Class is selected, it shows the source code for that Class, provided it has already been generated. For C++ a second tab displays to show the implementation file.

Note:

You view source code for an element by selecting menu options in a number of places, or by pressing either [Ctrl]+[E] or [F12]. If the element does not have a generation file (that is, code has not been or cannot be generated, such as for a Use Case), Enterprise Architect checks whether the element has a link to either an operation or an attribute of another element. If such a link exists, and that other element has source code, the code for that element displays.

A number of options change the way the Source Code viewer works. They can be altered via the Options dialog (select the Tools | Options | Source Code Engineering | Code Editors menu option).

By default the Source Code viewer is set to:

  • Parse all opened files, and show a tree of the results
  • Show line numbers.

The Source Code viewer also displays any DDL generated for a selected table in your diagram.

External File Editor

A very similar code editor for editing external code, XML and DDL files (that is, code not selected from the Project Browser) is available through the File | Open Source File menu option, or by pressing [Ctrl]+[Alt]+[O]. This editor does not have a toolbar; basic editing options are available through a right-click context menu.

To save changes, press [Ctrl]+[S]; also, if you try to close the window or select another file, the editor prompts you to save your changes.

File Parsing

The Source Code viewer parses files for a number of reasons. The first is to enable it to jump to the location in the file at which the currently selected item is found.

Additionally, parsing displays a structure tree showing an overview of the file in a similar fashion to the main Project Browser. You can also select anything in that and jump to the appropriate line in the editor.

The viewer cannot parse DDL, and therefore does not show the structure tree for a DDL file.

SourceCodeViewer

The Source Code Viewer Toolbar Buttons

The toolbar buttons in the Source Code viewer enable you to edit, view and interact with the code contained in the Source Code viewer. The function of each button is described below:

SourceTool

  • Structure Tree - shows or hides the element hierarchy panel (the left panel of the Source Code viewer)
  • Line Numbers - shows or hides the line numbers against the lines of code
  • Source Code Engineering Properties - displays the Source Code Engineering page of the Options dialog, from which you can configure display and behavior options for source code engineering
  • Editor Functions - provides quick access to the following functions:
  • Open Corresponding File - opens the header or implementation file associated with the currently-open file
  • Go to Matching Brace - for a selected opening or closing brace, highlights the corresponding closing or opening brace in the pair
  • Go to Line - displays a small dialog on which you select the number of the line to highlight; click on the OK button to move the cursor to that line
  • Cursor History Previous - the Source Code viewer keeps a history of the previous 50 cursor positions, creating a record when the cursor is moved either more than 10 lines away from its previous position, or in a find-and-replace operation; the menu option moves the cursor to the position in the immediately-previous cursor history record
  • Cursor History Next - moves the cursor to the position in the immediately-following cursor history record
  • Toggle Line Comment - comments out (//) or re-establishes the code for each full line in which text is highlighted
  • Toggle Stream Comment - inserts a stream comment (/* */) at the cursor position or comments out the highlighted characters and lines, or re-establishes the commented text as code
  • Toggle Whitespace Characters - shows or hides the spacing characters: --> (tab space) and . (character space)
  • Toggle EOL Characters - shows or hides the end-of-line characters: CR (carriage return) and LF (line feed)
  • Save Source and Resynchronize Class - saves the source code and resynchronizes the Class
  • Code Templates - accesses the Code Templates Editor
  • Find in Project Browser - for a selected line of code, highlights the appropriate structure in the Project Browser; if there is more than one possibility the Possible Matches dialog displays, listing the occurrences of the appropriate structure from which you can select the required one
  • Search in Files - searches for the selected object name in associated files and displays the results of the search on the File Search window
  • Search in Model - searches for the selected text  throughout the model, and displays the results of the search on the Model Search window.
  • Go to Declaration - locates the declaration of a symbol in the source code
  • Go to Definition - locates the definition of a symbol in the source code (applicable to languages where symbols are declared and defined in separate files e.g. C++, Delphi)
  • Autocomplete List - displays the autocompletion list of possible values; double-click on a value to select it
  • Parameter Information - when the cursor is between the parentheses of an operation's parameter list, displays the operation's signature, highlighting the current parameter
  • Find Current Class in Project Browser - displays the name of the currently-selected Class in the code, and highlights that name in the Project Browser; if there is more than one possibility the Possible Matches dialog displays, listing the occurrences of the Class from which you can select the required one
  • Find Member - displays the name of the currently-selected attribute or method in the code, and highlights that name in the Project Browser; if there is more than one possibility the Possible Matches dialog displays, listing the occurrences of the feature from which you can select the required one.

Context Menu

See the Code Editor Context Menu topic.