Custom Menu

This document details the Sonnet custom menu file format. This file allows you to add a custom menu to Sonnet which allows you to launch other programs including other Sonnet applications, third party programs, or personalized scripts. This file also allows you to define a tool bar button for one of the items in the custom menu. You may define up to 20 menu items but are limited to created a button for only one of the menu items.

The file is an XML file format with an extension of .xml. A example file, custom_menu.xml is provided with your software installation and may be found by selecting Admin > Diagnostics > Explore Sonnet Data Folder. The custom_menu.xml file is located in the data subfolder. An example is also given at the end of this article.

The custom menu file may be named anything you wish.

Specifying a Custom Menu File

To specify a custom menu file, select Edit > Preferences > [Advanced] from any Sonnet tab and enter the following text into the text box:

CustomMenu=<filename>

where <filename> is the full path to your custom menu file. If there are spaces included in the path or filename, then the name should be enclosed in double-quotes ("). For example if you wish to use the custom menu file C:\sonnet customizations\my_custom_menu.xml, you would enter the following line:

CustomMenu="C:\sonnet customizations\my_custom_menu.xml"

After you click OK, any new tab you open will include your custom menu.

Custom Menu File Syntax

Prologue

The first line of a custom menu file is required to be: 

<?xml version="1.0" standalone="yes"?>

<custom_menu> Root Element

The <custom_menu> element is the root element, and it defines the name of the menu and, optionally, a shortcut key to access the menu. It must be the second line in your file.

Syntax:

<custom_menu name="[menu_name]" accel="[hotkey]">

  • [menu_name]: A character string that defines the name of the menu.
  • [hotkey]: A single alphabetic character which defines the shortcut key which may be used to open the menu. When the user presses ALT+[hotkey], the menu is opened. Note that the accel attribute is optional. However, if you do not define a hotkey for the menu, then no keyboard shortcuts may be defined for any menu items.

The <custom_menu> element contains one or more <menu_item> child elements.

<menu_item> Element

The <menu_item> element defines a command which appears in the menu. You may define up to 20 commands, but only one command may use a button. The commands will be listed in the menu in the same order in which they are entered in this file.

Syntax:

<menu_item name="[item_name]" accel="[hotkey]" use_button="on|off">

  • [item_name]: The name you wish to have appear in the custom menu for this item.
  • [hotkey]: A single alphabetic character which defines the shortcut key that may be used in combination with the Alt key to execute this menu item. Note that the accel attribute is optional.
  • use_button="on|off": If use_button is set to on, then a button is added to the tool bar of the application that will execute this menu item. Note that if it does not appear, it defaults to off. You may only set use_button to on for one menu item in your file.

The <menu_item> element may contain the following child elements:

<exe> Child Element

Syntax:

<exe>[program]</exe>

[program]: The full path to the external program that the menu item will run. See also, Sonnet Variables.

<arguments> Child Element

The <arguments> element defines any arguments that will be passed to the program.

Syntax:

<arguments>[project_arguments]</arguments>

  • [project_arguments]: Defines the arguments of the program. Any text here is passed to the program. In order to pass any open Sonnet project file names to the program you can add one of two Sonnet variables: $PROJECT or $ALL_PROJECTS. See Sonnet Variables.
<launch_path> Child Element

The <launch_path> element is optional and defines the path upon which you wish to launch the executable. If this entry does not appear, then the default path is used. See also, Sonnet Variables.

Syntax:

<launch_path>[path]</launch_path> 

<button_graphic> Child Element

The <button_graphic> element is optional, and is only used if the use_button attribute of the <menu_item> element is set to on. If use_button is on and this entry does not appear, then a default button is used. If you wish to use a custom graphic for your button, then this statement should be included.

Syntax:

<button_graphic>[custom_button]</button_graphic>

 

  • [custom_button]: The full path to a bitmap file to be used for the button. The file must be a .bmp file and exactly 24 X 22 pixels in size. See also, Sonnet Variables.

Comments 

Note that you may enter comments in your file. Comment lines should start with the characters "<!-- " and end with the characters "--> " to identify the entry as a comment. 

You may not insert a comment above the <custom_menu> entry.

Sonnet Variables

The following Sonnet variables may be used in the custom menu file:

  • $SONNET_DIR: The full directory path to the Sonnet installation. The Sonnet executable files are located in the bin subdirectory. If you wish to call a Sonnet program, see Command Line Programs.
  • $PROJECT: The full path name of the present Sonnet project. For graphs with more than one project loaded, the project associated with the selected curve is used.
  • $ALL_PROJECTS: The full path name of all Sonnet projects open in your Session. For graphs with more than one project loaded, the project associated with the selected curve is used.
  • $PRJ_PATH: The directory path to the present Sonnet project.
  • $PRJ_DATA_DIR: The directory path to the data directory of the Sonnet project. For example, if your project name is filter1.sonx, $PRJ_DATA_DIR will return the path to the folder called filter1 located in the subfolder sondata.
  • $PRJ_BASE_NAME: The base name of the present Sonnet project. For example, if your project name is filter1.sonx, $PRJ_BASE_NAME will return "filter1".

Example

Below is short example of custom menu file that creates a menu called "My Menu" containing two menu items. The first menu item is called "Edit" and opens a text editor on the presently selected project file. The second menu item is called "My Script" and runs a script on all the open projects. A custom graphic is used for a button for the second menu item.

<?xml version="1.0" standalone="yes"?>

<custom_menu name="My Menu" accel="M">

  <menu_item name="Edit" accel="E"> 

    <exe>C:\Program Files\Acme\texteditor.exe</exe>

    <arguments>$PROJECT</arguments>

  </menu_item>

    <menu_item name="My Script" accel="S" use_button="on"> 

    <exe>C:\Scripts\MyScript.cmd</exe>

    <arguments>$ALL_PROJECTS</arguments>

    <button_graphic>c:\images\myimage.bmp<button_graphic> 

  </menu_item> 

</custom_menu>