User Guide
A simple menu command 163
For more information about the dw.undo() and dw.redo() functions, see the Dreamweaver API
Reference.
In this command, the
receiveArguments() function processes the arguments and executes the
command. More complex menu commands might call different functions to execute the
command. For example, the following code checks whether the first argument is
"foo"; if it is, it
calls the
doOperationX() function and passes it the second argument. If the first argument is
"bar", it calls the doOperationY() function and passes it the second argument. The
doOperationX() or doOperationY() function is responsible for executing the command.
function receiveArguments(){
if (arguments.length != 2) return;
var whatToDo = arguments[0];
if (whatToDo == "foo"){
doOperationX(arguments[1]);
}else if (whatToDo == "bar"){
doOperationX(arguments[1]);
}
}
setMenuText()
Dreamweaver calls the
setMenuText() function to determine what text appears for the menu
item. If you do not define the
setMenuText() function, Dreamweaver uses the text that you
specified on the name attribute of the
menuitem tag.
The
setMenuText() function checks the value of the argument that Dreamweaver passes,
arguments[0]. If the value of the argument is "undo", Dreamweaver calls the
dw.getUndoText() function; if it is "redo", Dreamweaver calls dw.getRedoText(). The
dw.getUndoText() function returns text that specifies the operation that Dreamweaver will
undo. For example, if the user executes multiple Redo operations,
dw.getUndoText() could
return the menu text, Undo Edit Source. Likewise, the
dw.getRedoText() function returns text
that specifies the operation that Dreamweaver will redo. If the user executes multiple Undo
operations, the
dw.RedoText() function could return the menu text, Redo Edit Source.
The
setMenuText() function looks like the following example code:
function setMenuText()
{
if (arguments.length != 1) return "";
var whatToDo = arguments[0];
if (whatToDo == "undo")
return dw.getUndoText();
else if (whatToDo == "redo")
return dw.getRedoText();
else return "";
}