Editing C⁠+⁠+ Code

The OMNeT⁠+⁠+ IDE comes with a C/C⁠+⁠+ editor. In addition to standard editing features, the C/C⁠+⁠+ editor provides syntax highlighting, content assistance, and other C⁠+⁠+ specific functionality. The source is continually parsed as you type, and errors and warnings are displayed as markers on the editor rulers.

Figure 5.6. C⁠+⁠+ source editor

C⁠+⁠+ source editor

The C⁠+⁠+ Editor

The C⁠+⁠+ source editor provides the usual features of Eclipse-based text editors, such as syntax highlighting, clipboard cut/copy/paste, unlimited undo/redo, folding, find/replace and incremental search.

The IDE scans and indexes the C⁠+⁠+ files in your project in the background, and provides navigation and code analysis features on top of that knowledge; this database is kept up to date as you edit the source.

Basic Functions

Some of the most useful features of the source editor:

  • Undo (Ctrl+Z), Redo (Ctrl+Y)

  • Switch between a C⁠+⁠+ source and its matching header file (Ctrl+TAB)

  • Indent/unindent code blocks (TAB/Shift+TAB)

  • Correct indentation (Ctrl+I)

  • Move lines (Alt+UP/DOWN)

  • Find (Ctrl+F), incremental search (Ctrl+J)

Tip

The following functions can help you explore the IDE:

  • Ctrl+Shift+L pops up a window that lists all keyboard bindings, and

  • Ctrl+3 brings up a filtered list of all available commands.

View Documentation

Hovering the mouse over an identifier will display its declaration and the documentation comment in a "tooltip" window. The window can be made persistent by hitting F2.

Tip

If you are on Ubuntu and you see all-black tooltips, you need to change the tooltip colors in Ubuntu; see the Ubuntu chapter of the OMNeT⁠+⁠+ Installation Guide for details.

Content Assist

If you need help, just press Ctrl+SPACE. The editor will offer possible completions (variable names, type names, argument lists, etc.).

Navigation

Hitting F3 or holding the Ctrl key and clicking an identifier will jump to the definition/declaration.

The Eclipse platform's bookmarking and navigation history facilities are also available in the C⁠+⁠+ editor.

Commenting

To comment out the selected lines, press Ctrl+/. To remove the comment, press Ctrl+/ again.

Open Type

Pressing Ctrl+Shift+T will bring up the Open Element dialog which lets you type a class name, method name or other identifier, and opens its declaration in a new editor.

Exploring the Code

The editor offers various ways to explore the code: Open Declaration (F3), Open Type Hierarchy (F4), Open Call Hierarchy (Ctrl+Alt+H), Quick Outline (Ctrl+O), Quick Type Hierarchy (Ctrl+T), Explore Macro Expansion (Ctrl+=), Search for References (Ctrl+Shift+G), etc.

Refactoring

Several refactoring operations are available, for example Rename (Shift+Alt+R).

Note

Several features such as content assist, go to definition, type hierarchy and refactorings rely on the Index. The index contains the locations of all functions, classes, enums, defines, etc. in the project and referenced projects. Initial indexing of large projects may take a significant amount of time. The index is kept up to date mostly automatically, but occasionally it may be necessary to manually request reindexing the project. Index-related actions can be found in the Index submenu of the project's context menu.

Include Browser View

Dropping a C⁠+⁠+ file into the Include Browser View displays the include files used by the C⁠+⁠+ file (either directly or indirectly).

Figure 5.7. Include Browser

Include Browser

Outline View

During source editing, the Outline View gives you an overview of the structure of your source file and can be used to quickly navigate inside the file.

Figure 5.8. Navigating with Outline View

Navigating with Outline View

Type Hierarchy View

Displaying the C⁠+⁠+ type hierarchy may be helpful for understanding the inheritance relationships among your classes (and among OMNeT⁠+⁠+ classes).

Figure 5.9. C⁠+⁠+ Type hierarchy

C⁠+⁠+ Type hierarchy