The Menu Commands API

 < Day Day Up > 

The custom functions in the Menu Commands API are not required.

canAcceptCommand()

Description

Determines whether the menu item is active or dimmed.

Arguments

 {arg1}, {arg2},...{argN}} 

  • If it is a dynamic menu item, the unique ID that the getdynamicContents() function specifies is the only argument. Otherwise, if the arguments attribute is defined for a menuitem tag, the value of that attribute passes to the canAcceptCommand() function (and to the isCommandChecked(), receiveArguments(), and setMenuText() functions) as one or more arguments. The arguments attribute is useful for distinguishing between two menu items that call the same menu command.

NOTE

The arguments attribute is ignored for dynamic menu items.


Returns

Dreamweaver expects a Boolean value: true if the item should be enabled; false otherwise.

commandButtons()

Description

Defines the buttons that appear on the right side of the Options dialog box and their behavior when they are clicked. If this function is not defined, no buttons appear, and the BODY section of the Menu Commands file expands to fill the entire dialog box.

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 manner.

Example

The following example of the commandButtons() function defines the OK, Cancel, and Help buttons:

function commandButtons(){ return new Array("OK" , "doCommand()" , "Cancel" , "window.close()" , "Help" , "showHelp ()"); }

getDynamicContent()

Description

Retrieves the content for the dynamic portion of the menu.

Arguments

 menuID 

  • The menuID argument is the value of the id attribute in the menuitem tag that is associated with the item.

Returns

Dreamweaver expects an array of strings where each string contains the name of a menu item and its unique ID, separated by a semicolon. If the function returns a null value, the menu does not change.

Example

The following example of the geTDynamicContent() function returns an array of four menu items (My Menu Item 1, My Menu Item 2, My Menu Item 3, and My Menu Item 4):

 function getDynamicContent(){   var stringArray= new Array();   var i=0;   var numItems = 4;        for (i=0; i<numItems;i++)     stringArray[i] = new String("My Menu Item " + i + "; id='My-MenuItem" + i + "'");   return stringArray; } 

isCommandChecked()

Description

Determines whether to display a check mark next to the menu item.

Arguments

 {arg1}, {arg2},...{argN} 

  • If it is a dynamic menu item, the unique ID that the geTDynamicContents() function specifies is the only argument. Otherwise, if the arguments attribute is defined for a menuitem tag, the value of that attribute passes to the isCommandChecked() function (and to the canAcceptCommand(), receiveArguments(), and setMenuText() functions) as one or more arguments. The arguments attribute is useful for distinguishing between two menu items that call the same menu command.

NOTE

The arguments attribute is ignored for dynamic menu items.


Returns

Dreamweaver expects a Boolean value: true if a check mark should appear next to the menu item; false otherwise.

Example

 function isCommandChecked() {   var bChecked = false;   var cssStyle = arguments[0];   if (dw.getDocumentDOM() == null)      return false;   if (cssStyle == "(None)")   {     return dw.cssStylePalette.getSelectedStyle() == '';   }   else   {     return dw.cssStylePalette.getSelectedStyle() == cssStyle;   }     return bChecked; } 

receiveArguments()

Description

Processes any arguments passed from a menu item or from the dw.runCommand() function. If it is a dynamic menu item, it processes the dynamic menu item ID.

Arguments

 {arg1}, {arg2},...{argN} 

  • If it is a dynamic menu item, the unique ID that the getdynamicContents() function specifies is the only argument. Otherwise, if the arguments attribute is defined for a menuitem tag, the value of that attribute passes to the receiveArguments() function (and to the canAcceptCommand(), isCommandChecked(), and setMenuText() functions) as one or more arguments. The arguments attribute is useful for distinguishing between two menu items that call the same menu command.

NOTE

The arguments attribute is ignored for dynamic menu items.


Returns

Dreamweaver expects nothing.

Example

 function receiveArguments() {   var styleName = arguments[0];   if (styleName == "(None)")     dw.getDocumentDOM('document').applyCSSStyle('','');   else     dw.getDocumentDOM('document').applyCSSStyle('',styleName); } 

setMenuText()

Description

Specifies the text that should appear in the menu.

NOTE

Do not use this function if you are using getDynamicContent().


Arguments

 {arg1}, {arg2},...{argN} 

  • If the arguments attribute is defined for a menuitem tag, the value of that attribute passes to the setMenuText() function (and to the canAcceptCommand(), isCommandChecked(), and receiveArguments() functions) as one or more arguments. The arguments attribute is useful for distinguishing between two menu items that call the same menu command.

Returns

Dreamweaver expects the string that should appear in the menu.

Example

 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 ""; } 

windowDimensions()

Description

Sets specific dimensions for the Parameters dialog box. If this function is not defined, the window dimensions are computed automatically.

NOTE

Do not define this function unless you want a dialog box that is larger than 640 x 480 pixels.


Arguments

 platform 

  • The value of the platform argument is either "macintosh" or "windows", depending on the user's platform.

Returns

Dreamweaver expects a string of the form "widthInPixels,heightInPixels".

The returned dimensions are smaller than the size of the entire dialog box because they do not include the area for the OK and Cancel buttons. If the returned dimensions do not accommodate all options, scroll bars appear.

Example

The following example of windowDimensions() sets the dimensions of the Parameters dialog box to 648 x 520 pixels:

 function windowDimensions(){   return "648,520"; } 

     < Day Day Up > 


    Developing Extensions for Macromedia Dreamweaver 8
    Developing Extensions for Macromedia Dreamweaver 8
    ISBN: 0321395409
    EAN: 2147483647
    Year: 2005
    Pages: 282

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net