2. Examples

Example 3.1. Contextual menus

The example below is pretty useless however it shows how contextual menus can be implemented. It displays a special menu when text is selected and another special menu when root element is selected.

This example can be found in XXE_install_dir/doc/configure/samples2/contextualmenus.xxe.

  <command name="contextualMenu">
    <macro>
      <choice>
        <sequence>
          <test expression="$selectedChars != ''" />
          <command name="contextualMenu1" />
        </sequence>
        
        <sequence>
          <match context="$selectedElement" pattern="/*" />
          <command name="contextualMenu2" />
        </sequence>
        
        <command name="editMenu" />
      </choice>
    </macro>
  </command>

  <command name="contextualMenu1">
    <menu>
      <item label="To Upper Case"
            command="convertCase" parameter="upper" />
      <item label="To Lower Case" 
            command="convertCase" parameter="lower" />
      <item label="Capitalize Words" 
            command="convertCase" parameter="capital" />

      <editMenu />
    </menu>
  </command>

  <command name="contextualMenu2">
    <menu label="File">
      <editMenu />

      <item label="Open..." command="XXE.open" />
      <separator/>
      <item label="Save" command="XXE.save" />
      <item label="Save As..." command="XXE.saveAs" />
    </menu>
  </command>

  <binding>
    <mousePressed button="3"/>
    <command name="contextualMenu" />
  </binding>