beautypg.com

Canacceptcommand(), Commandbuttons() – Adobe Extending Dreamweaver CS4 User Manual

Page 144

background image

138

EXTENDING DREAMWEAVER CS4

Commands

canAcceptCommand()

Description
This function 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; if the value is

false

, Dreamweaver dims 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
This function defines the buttons that appear on 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 command file expands to fill the entire
dialog box.

By default, these buttons appear at the top of the dialog box. You can choose to display these buttons at the bottom of
the dialog box by specifying two additional values in the

commandButtons()

function.

Buttons are right-aligned by default. Specifying the value,

PutButtonsOnLeft

, aligns subsequent buttons to the left

on the same line.

Arguments
None.

Returns
Dreamweaver expects an array that contains an even number of elements. The first element is a string that contains
the label for the topmost button. The second element is a string of JavaScript code that defines the behavior of the
topmost button when it is clicked. The remaining elements define additional buttons in the same way.

This manual is related to the following products: