User Guide

A simple menu command 161
A simple menu command
This simple menu command example shows how Undo and Redo menu commands might work.
The Undo menu item reverses the effect of a users editing operation, and the Redo item reverses
an Undo operation and restores the effect of the user’s last editing operation.
You can implement this example by performing the following steps:
1 Creating the menu items
2 Writing the JavaScript code
3 Placing the menu command file in the Menus folder
Creating the menu items
Add the following HTML menu tags to the end of the menus.xml file to create a menu called
MyMenu that contains the Undo and Redo menu items.
<menu name="MyMenu" id="MyMenu_Edit">
<menuitem name="MyUndo" key="Cmd+Z" file="Menus/MyMenu.htm" arguments="'undo'"
id="MyMenu_Edit_Undo" />
<menuitem name="MyRedo" key="Cmd+Y" file="Menus/MyMenu.htm" arguments="'redo'"
id="MyMenu_Edit_Redo" />
</menu>
The key attribute defines keyboard shortcut keys that the user can type to invoke the menu item.
The
file attribute specifies the name of the command file that Dreamweaver executes when
Dreamweaver invokes the menu item. The value of the
arguments attribute defines the
arguments that Dreamweaver will pass when it calls the
receiveArguments() function.
The following figure shows these menu items:
Writing the JavaScript code
When the user clicks either Undo or Redo on the MyMenu menu, Dreamweaver calls the
MyMenu.htm command file, which is specified by the
file attribute of the menuitem tag. Create
the MyMenu.htm command file in the Dreamweaver Configuration/Menus folder and add the
three menu command API function,
canAcceptCommand(), receiveArguments(), and
setMenuText(), to implement the logic associated with the Undo and Redo menu items. The
following sections describe these functions.