Source Code Template Editor is accessible from menu Tools / Templates / Source Codes. (This feature is available only in Ultimate edition)
Templates are grouped in languages (C#, Java, Visual Basic, etc.). Software Ideas Modeler allows you to create also your own languages, which are not yet supported in the official package. Commands for work with languages are accessible from Language toolbar in Source Code Template Management window. This toolbar consists of langauge drop-down list and three buttons:
- Add Language – shows a dialog which allows you to add a new template language (set of templates).
- Edit Language – edits the language selected in the drop down list, the displayed dialog allows you to change name and description of language.
- Delete Language – removes the language selected in the drop down list.
If you click on Add Language button, Language dialog will show and it allows you to add a new template language (set of templates). It contains three fields:
- Name (1) – specifies a name of the new source code template language.
- ID (2) – specifies an unique ID of the new language.
- Description (3) – allows you to set a brief description of the new language.
The new language will be added after clicking OK button (4) or it will be discarded if you click on Cancel button (5).
Souce Code Template Management window shows the list of templates defined for the language selected in the drop down list in top toolbar. If no language is selected then no templates are listed and it is also not possible to add any new templates (each template has to be listed under some language).
1 - list of all templates for selected language, 2 - Settings tab with settings for the selected template, 3 - Files tab with files, which are included in the selected template
The list of templates is placed on the left side of the window and offers three buttons:
- Add – adds a new template for the active language.
- Delete – deletes the selected template.
- More – offers a submenu with these items:
- Duplicate – duplicates the selected template.
- Import – copies a file with template to the source code library.
- Export – exports the selected template to the chosen file.
Add Source Code Template
If you click on Add button in Template panel, Source Code Template dialog will show and it allows you to add a new source code template for the active language. It contains these fields:
- Name (1) – specifies a name of the new source code template.
- ID (2) – specifies an unique ID of the new source code template.
- Author (3) – specifies the name of the template author.
- Description (4) – allows you to set a brief description of the new source code template.
The new source code will be created and added to the template library after clicking OK button (5) or it will be discarded if you click on Cancel button (6).
If you select the template in the left list, its details will be displayed in the right side of the window. There are two tabs Settings and Files. The Settings tab allows you to change name, author and description of the selected template. If you want to save the made changes, you have to click on Save button in top toolbar of Settings tab.
1 - List of template files, 2 - Preview of the selected template file
The second tab (Files) consists of three parts:
- Toolbar – has three buttons for file manipulation:
- Add File – adds a new file to template
- Edit File – edits the selected file using template editor
- Rename File – allows you to change the name of the selected file
- Delete File – removes the selected file from the template (it will be deleted from disk)
- List of files – displays all files that are part of the selected template.
- Preview pane – displays preview of the selected template file.
Add Template File
If you click on Add File button in toolbar in Files tab, New Template File dialog will show and it allows you to add a new file to the edited source code template. Type the name to the File name field (1), confirm it with OK button (2) and new template file will be created. If you don't want to create a new file, but you open the New Template File dialog, you can close it with Cancel button (3).
Source Code Template Editor
Source Code Template Editor allows to easily create and edit the template files for source code generation. Its window consists of three main parts:
- left side bar with the list of commands
- right top pane with editors
- right bottom pane with preview of generated output based on the currently edited template
The right top part of windows contains the tab control with three tabs, which allows you to edit the content of the existing template:
- Template tab
- Source code tab
- Settings tab
This tab offers the graphical template editor. It allows you to create and edit the open template file using mouse and drag&drop – you can move, reorder, add and delete the template parts. It also clearly shows the hierarchy of cycles and conditional parts.
Source code tab
This tab contains the text editor with command highlighting. It allows you to fast edit the source code of the template.
This tab allows you to adjust the following settings:
- Template type – defines the context of template, which can be Element or Diagram.
- Output name – defines the name of outpu file generated by this template.
- Name adjustment – offers several options for file name adjustments:
- Camel Case
- Remove Spaces
- Add Underscores
- Default type – specifies the name of type, which will be used for cases when no type is explicitly set.
- Filter – sets the filter which determines in which cases can be used the template (e.g. only for classes or for all elements with some stereotype)