Adding Context Menu Items

You can expose actions to the user by adding items to the context menu that is displayed when the user right-clicks the panel. Whenever these items are clicked, Desktop Sidebar will notify your panel by executing a certain function.

1. Define Commands

Before adding an item to the context menu, you have to define a command. First, create the <commands> element as a child of the main <plugin> element (note: it is not inside the element). Inside the <commands> element, create a <command> element that will represent your command.

The <command> element has the following attributes:

Following is an example of the structure of a plugin with the <commands> element.

<?xml version="1.0" encoding="utf-8"?> <plugin> <panel> <!-- Various panel elements go here... --> </panel> <commands> <command name="MyPanel.Command1" action="command1Executed" /> <command name="MyPanel.DoSomething" action="doSomething" /> <!-- More commands go here... --> </commands> </plugin>

2. Aggregate Commands in a Menu

After you declare all your commands, you need to put them in a menu together. First, create the <menus> element (again, inside the <plugin> element). Inside the <menus> element, create a <menu> element to represent your panel's context menu. The <menu> element has a name attribute. Same as with the command's name, this identifier should be unique, so give it the name of "PanelName.ContextMenu" (e.g. "GmailPanel.ContextMenu"). Inside the <menu> element, specify an <option> element for each of the commands you defined above. Add to the <option> element a cmd attribute, and give it the name of a command (as it was specified in the <command> element's name attribute). After all the menu items, add a <separator /> element to your menu, in order to separate your panel's own items from general Desktop Sidebar items that are automatically added to your menu. Example of the structure of the <menus> element:

<menus> <menu name="MyPanelMenu"> <option cmd="MyPanel.Command1" /> <option cmd="MyPanel.DoSomething" /> <separator /> </menu> </menus>