User Guide
136 Chapter 7: Commands
Adding commands to the Commands menu
Dreamweaver automatically adds any files that are inside the Configuration/Commands folder to
the bottom of the Commands menu. To prevent a command from appearing in the Commands
menu, insert the following comment on the first line of the file:
<!-- MENU-LOCATION=NONE -->
When this line is present, Dreamweaver does not create a menu item for the file, and you must
call
dw.runCommand() to execute the command.
The Commands API
The custom functions in the Commands API are not required.
canAcceptCommand()
Description
Determines whether the command is appropriate for the current selection.
Note: Do not define canAcceptCommand() unless it returns a value of false in at least one case. If the
function is not defined, the command is assumed to be appropriate. Making this assumption saves
time and improves performance.
Arguments
None.
Returns
Dreamweaver expects a true value if the command is allowed; false otherwise, dimming the
command in the menu.
Example
The following example of the canAcceptCommand() function makes the command available only
when the selection is a table:
function canAcceptCommand(){
var retval=false;
var selObj=dw.getDocumentDOM.getSelectedNode();
return (selObj.nodeType == Node.ELEMENT_NODE && ¬
selObj.tagName=="TABLE");{
retval=true;
}
return retval;
}
commandButtons()
Description
Defines the buttons that should appear on the right side of the Options dialog box and their
behaviors when they are clicked. If this function is not defined, no buttons appear, and the
BODY
section of the Commands file expands to fill the entire dialog box.
Arguments
None.