Recommendations for code editing

A DevOps Model RealTime model contains snippets of code in many places where actions and expressions can be specified. There are four ways in which such code snippets can be edited:

  1. Using the Code view
    The Code view is mainly intended to be used for viewing code snippets and to make small modifications to them. The Code view can only show one code snippet at a time and you can only have one Code view open.

  2. Using the Code editor
    The Code editor is recommended for general editing of code snippets. You can have multiple code editors open at the same time and all common benefits with Eclipse editors also apply for code editors. The Code editor can either show one specific code snippet, or all code snippets for the element. See Working with multiple code snippets in the Code Editor.

  3. Using the CDT source editor
    You can use this editor after you have transformed your model into C++ code. The CDT editor shows a generated C++ file in its entirety and this file might contain multiple code snippets. The code snippets are enclosed within USR comment blocks. Here is an example of what it might look like:

//{{{USR platform:/resource/Sample/HelloWorld.emx#_ZT0WMI7mEeG--Krzx7QXSQ
log.show("Hi!");
//}}}USR

A benefit of editing code snippets in the CDT editor is that you can see the full context where the code snippet is located. This might make it easier to understand the code, than when just looking at the code snippet in isolation (as you do with the Code view and Code editor).

  1. Using an external text editor
    In the Code view preferences you can specify which external text editor to use.

When editing a code snippet using the Code view or Code editor, keep the following in mind:

In the former case, the code snippet is located in the model. In the latter case, the code snippet is located in a generated file.

By default, the Code view or editor tries to locate a generated file for a code snippet as soon as it gets focus. This behavior is controlled by a preference (RealTime Development - Code Editing - Auto load generated source when focus gained). It is recommended that you do not turn off this preference.

However, even if this preference is enabled, there are cases when the generated file cannot be automatically loaded. So, if you find that a code snippet that you are about to edit is located in the model, it is recommended to try and manually load the generated file so that the Code view or editor edits the code snippet stored in the generated file. To manually load the generated file, invoke the command Load Generated Source, which is available in the context menu of the Code view or editor. If the loading of the generated file fails (for reasons mentioned above), you have no other choice than to edit the code snippet located in the model.

When you edit a code snippet (or multiple code snippets) using an external or internal source editor (such as the CDT editor), keep the following in mind:

The code in the Old Source view shows the code snippet as stored in the model. The New Source view shows the modified code snippet that will be committed to the model when you click Commit. If you do not want to commit some of the updated code snippets, you can deselect the checkbox for that code snippet before clicking Commit. If you press Cancel, no code snippets are updated, and all changes are lost the next time the file is regenerated.

To summarize the most important recommendations mentioned above: