Adobe Extending Dreamweaver CS4 Manuale Utente Pagina 159

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 387
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 158
153
EXTENDING DREAMWEAVER CS4
Menus and menu commands
12 The dialog box remains visible until one of the scripts in the menu commands file calls the window.close()
function.
A simple menu command example
This simple menu command example shows how Undo and Redo menu commands might work. The Undo menu
command reverses the effect of a user’s editing operation, and the Redo item reverses an Undo operation and restores
the effect of the user’s last editing operation.
You implement this example by creating the menu commands, writing the JavaScript code, and placing the command
file in the Menu folder.
Create a menu command
To create a menu called MyMenu that contains the Undo and Redo menu commands, add the following HTML menu
tags. Add the tags after the last closing
</menu> in menus.xml.
<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 shortcuts that the user can type to load the menu command. The file attribute
specifies the name of the menu command file that Dreamweaver executes when Dreamweaver loads the command.
The value of the
arguments attribute defines the arguments that Dreamweaver passes when it calls the
receiveArguments() function.
The following figure shows these menu commands:
JavaScript code for the menu
When the user selects 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 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:
Vedere la pagina 158
1 2 ... 154 155 156 157 158 159 160 161 162 163 164 ... 386 387

Commenti su questo manuale

Nessun commento