Status: Draft

Snippet Reference


A snippet is a programming term for a set of re-usable source code.
Snippets are often used to minimize the use of repeated code.

Desktop Studio can generate code to avoid tedious and repetitive operations, simplify maintenance, and improve productivity.
Snippets complement other ways to generate code:

  • Application / page / item declarations,
  • Scenario management,
  • Structure declarations,
  • and so on

The functionality is accessible:

  • Via the context menu from an editor view,
  • Via the context menu from the 'Page Viewer', 'Project' view,

Some parameters are reserved and can be dynamically replaced, depending on the entity selected:

  • app : application name,
  • page : page name,
  • item : item name,


Types of Snippet

Snippet templates are defined in configuration files, which can evolve and be enriched.
They are grouped by category:

'Language' basic snippets for the various Desktop Studio language verbs.
'Menus' Snippets used to edit 'systray' menu : add/remove, and so on
'Item' Snippets used for item declarations
Page' Snippets used for page declarations
'Scenario' Snippets used for scenario declarations


Add Tray Menu Item

NameDescription
Usage Add a new menu in the systray menu.
Filter None.
Parameters
FunctionFunction name
Default value : current function,
Name Internal menu ID
Default value: 'evStart<function name>'
Caption Display label
Default value: 'Function < function name >'
Result Creates < function name > if it doesn't exist,
• Adds 'evStart<function name>' menu declaration,
• Adds a new CASE to handle 'evStart<function name>' event.


Item Snippets

Start Function on Button Click

NameDescription
UsageCreate an application event which is called when clicking an item.
FilterItem node
Parameters
FunctionFunction name
Default value : current function,
Source
ApplicationApplication.
Default value: application containing the selected node, otherwise empty.
Page Page.
Default value: page containing the selected node, otherwise empty.
Item Object.
Default value: name of the selected node.
Event Event to be called.
Default value: 'ev< function name >'.
Result Creates '<function name>' if it doesn't exist,
• Creates event in application,
• Creates a notification to 'Application:Event' when clicking on object 'Application:Page:Item'.


Global Structure

Snippet declaration files are located in the 'snippets' sub-folder.
This folder can contain any number of files, as long as each one complies with the correct structure.

The format of a snippet file is based on standard snippet format from Microsoft (see Code Snippets Schema Reference).

Each file contains:

  • The structure in term of menus / sub-menus for organizing the snippets
  • Some section declarations used to display parameters per category (called 'property groups'),
  • a collection of snippets:
    • a name and ID,
    • a filter (to display snippet only on specified nodes),
    • an icon,
    • a list of parameters to be edited by user,
    • a list of code parts to be generated and inserted in project,
<?xml version="1.0" encoding="ISO-8859-1" ?>
<snippets_definition>
 
  <!- property groups -->
  <property_groups>
    ...
  </property_groups>
 
  <!- snippet ... -->
  <snippet id="..." text="...">
    ...
  </snippet>
 
  <!- snippet ... -->
  <snippet id="..." text="...">
    ...
  </snippet>
 
  <!- menu declaration ... -->
  <snippets_access>
    ...
  </snippets_access>
</snippets_definition>


Associated Icons

A set of icons is provided to be optionally associated with each snippet: the icon is added by mentioning its index ('0' based).