Code Snippets Reference

Overview

A snippet is a programming term for a set of re-usable source code. Snippets are often used to minimize the repeated use of the same 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

Snippet Generation

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

Predefined Snippets

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

Menu Snippets

Add Tray Menu Item

Name

Description

Usage

Add a new menu in the systray menu.

Filter

None.

Parameters

Function

Function 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 clicking a button

Name

Description

Usage

Create an application event which is called when clicking an item.

Filter

Item node

Parameters

Function

Function name

Default value : current function

Source

Application

Application

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 already exist,

creates event in application,

creates a notification to ‘Application:Event’ when object ‘Application:Page:Item’ is clicked.

Editing Snippets

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.

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 into the project

Associated Icons

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