Code functions

 < Day Day Up > 

Code Hints are menus that Macromedia Dreamweaver 8 opens when you type certain character patterns in Code view. Code Hints provide a typing shortcut by offering a list of strings that potentially complete the string you are typing. If the string you are typing appears in the menu, you can scroll to it and press Enter or Return to complete your entry. For example, when you type <, a pop-up menu shows a list of tag names. Instead of typing the rest of the tag name, you can select the tag from the menu to include it in your text.

You can add Code Hints menus to Dreamweaver by defining them in the CodeHints.xml file. For information on the CodeHints.xml file, see Extending Dreamweaver.

You can also add new Code Hints menus dynamically through JavaScript after Dreamweaver loads the contents of the CodeHints.xml file. For example, JavaScript code populates the list of session variables in the Bindings panel. You can use the same code to add a Code Hints menu, so when a user types Session in Code view, Dreamweaver displays a menu of session variables.

The CodeHints.xml file and the JavaScript API expose a useful subset of the Code Hints engine, but some Dreamweaver functionality is not accessible. For example, there is no JavaScript hook to open a color picker, so Dreamweaver cannot express the Attribute Values menu using JavaScript. You can only open a menu of text items from which you can insert text.

Code Coloring lets you specify code color styles and to modify existing code coloring schemes or create new ones. You can specify code coloring styles and schemes by modifying the Colors.xml and code coloring scheme files. For more information on these files, see Extending Dreamweaver.

The JavaScript API for Code Hints and Code Coloring consists of the following functions.

dreamweaver.codeHints.addMenu()

Availability

Dreamweaver MX.

Description

Dynamically defines a new menu tag in the CodeHints.xml file. If there is an existing menu tag that has the same pattern and document type, this function adds items to the existing menu.

Arguments

 menuGroupId, pattern, labelArray, {valueArray}, {iconArray}, {doctypes}, {casesensitive} 

  • The menuGroupId argument is the ID attribute for one of the menugroup tags.

  • The pattern argument is the pattern attribute for the new menu tag.

  • The labelArray argument is an array of strings. Each string is the text for a single menu item in the pop-up menu.

  • The valueArray argument, which is optional, is an array of strings, which should be the same length as the labelArray argument. When a user selects an item from the pop-up menu, the string in this array is inserted in the user's document. If the string to be inserted is always the same as the menu label, this argument might have a null value.

  • The iconArray argument, which is optional, is either a string or an array of strings. If it is a string, it specifies the URL for a single image file that Dreamweaver uses for all items in the menu. If it is an array of strings, it must be the same length as the labelArray argument. Each string is a URL, relative to the Dreamweaver Configuration folder, for an image file that Dreamweaver uses as an icon for the corresponding menu item. If this argument is a null value, Dreamweaver displays the menu without icons.

  • The doctypes argument, which is optional, specifies that this menu is active for only certain document types. You can specify the doctypes argument as a comma-separated list of document type IDs. For a list of Dreamweaver document types, see the Dreamweaver Configuration/Documenttypes/MMDocumentTypes.xml file.

  • The casesensitive argument, which is optional, specifies whether the pattern is case-sensitive. The possible values for the casesensitive argument are the Boolean values true or false. The value defaults to false if you omit this argument. If the casesensitive argument is a TRue value, the Code Hints menu appears only if the text that the user types exactly matches the pattern that the pattern attribute specifies. If the casesensitive argument is a false value, the menu appears even if the pattern is lowercase and the text is uppercase.

Returns

Nothing.

Example

If the user creates a record set called "myRs", the following code would create a menu for myRS:

 dw.codeHints.addMenu(   "CodeHints_object_methods",  // menu is enabled if object methods are enabled   "myRS.",                       // pop up menu if user types "myRS."   new Array("firstName", "lastName"),  // items in drop-down menu for myRS   new Array("firstName", "lastName"),  // text to actually insert in document   null,              // no icons for this menu   "ASP_VB, ASP_JS"); // specific to the ASP doc types 

dreamweaver.codeHints.addFunction()

Availability

Dreamweaver MX.

Description

Dynamically defines a new function tag. If there is an existing function tag with the same pattern and document type, this function replaces the existing function tag.

Arguments

 menuGroupId, pattern, {doctypes}, {casesensitive} 

  • The menuGroupId argument is the ID string attribute of a menugroup tag.

  • The pattern argument is a string that specifies the pattern attribute for the new function tag.

  • The doctypes argument, which is optional, specifies that this function is active for only certain document types. You can specify the doctypes argument as a comma-separated list of document type IDs. For a list of Dreamweaver document types, see the Dreamweaver Configuration/Documenttypes/MMDocumentTypes.xml file.

  • The casesensitive argument, which is optional, specifies whether the pattern is case-sensitive. The possible values for the casesensitive argument are the Boolean values true or false. The value defaults to false if you omit this argument. If the casesensitive argument is a true value, the Code Hints menu appears only if the text that the user types exactly matches the pattern that the pattern attribute specifies. If casesensitive is a false value, the menu appears even if the pattern is lowercase and the text is uppercase.

Returns

Nothing.

Example

The following example of the dw.codeHints.addFunction() function adds the function name pattern out.newLine() to the Code Hints menu group CodeHints_Object_Methods and makes it active only for JSP document types:

 dw.codeHints.addFunction(    "CodeHints_Object_Methods",    "out.newLine()",    "JSP") 

dreamweaver.codeHints.resetMenu()

Availability

Dreamweaver MX.

Description

Resets the specified menu tag or function tag to its state immediately after Dreamweaver reads the CodeHints.xml file. In other words, a call to this function erases the effect of previous calls to the addMenu() and addFunction() functions.

Arguments

 menuGroupId, pattern, {doctypes} 

  • The menuGroupId argument is the ID string attribute of a menugroup tag.

  • The pattern argument is a string that specifies the pattern attribute for the new menu or function tag to be reset.

  • The doctypes argument, which is optional, specifies that this menu is active for only certain document types. You can specify the doctypes argument as a comma-separated list of document type IDs. For a list of Dreamweaver document types, see the Dreamweaver Configuration/Documenttypes/MMDocumentTypes.xml file.

Returns

Nothing.

Example

Your JavaScript code might build a Code Hints menu that contains user-defined session variables. Each time the list of session variables changes, that code needs to update the menu. Before the code can load the new list of session variables into the menu, it needs to remove the old list. Calling this function removes the old session variables.

dreamweaver.codeHints.showCodeHints()

Availability

Dreamweaver MX.

Description

Dreamweaver calls this function when the user opens the Edit > Show Code Hints menu item. The function opens the Code Hints menu at the current selection location in Code view.

Arguments

None.

Returns

Nothing.

Example

The following example opens the Code Hints menu at the current insertion point in the document when it is in Code view.

 dw.codeHints.showCodeHints() 

dreamweaver.reloadCodeColoring()

Description

Reloads code coloring files from the Dreamweaver Configuration/Code Coloring folder.

Arguments

None.

Returns

Nothing.

Example

 dreamweaver.reloadCodeColoring() 

     < 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