Macromedia dreamweaver 8-extending dreamweaver 사용자 설명서
198
Menus and Menu Commands
Creating the menu commands
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.
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"
<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 selects either Undo or Redo on the MyMenu menu, Dreamweaver calls the
MyMenu.htm command file, which is specified by 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 functions,
and add the three menu command API functions,
canAcceptCommand()
,
receiveArguments()
,
and
setMenuText()
, to implement the logic associated with the
Undo and Redo menu items
.
The following sections describe these functions.
canAcceptCommand()
Dreamweaver calls the
canAcceptCommand()
function for each menu item in the MyMenu
menu to determine whether it should be enabled or disabled. In the MyMenu.htm file, the
canAcceptCommand()
function checks the value of
arguments[0]
to determine whether
Dreamweaver is processing a Redo menu item or an Undo menu item. If the argument is
"undo"
, the
canAcceptCommand()
function calls the enabler function
dw.canUndo()
and
returns the returned value, which is either
true
or
false
. Likewise, if the argument is
"redo"
, the
canAcceptCommand()
function calls the enabler function
dw.canRedo()
and
returns its value to Dreamweaver. If the
canAcceptCommand()
function returns the value
false
, Dreamweaver dims the menu item for which it called the function. The following
example shows the code for the
canAcceptCommand()
function: