Code Hints are menus that Adobe® Dreamweaver® CS5 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, Dreamweaver does not have a JavaScript hook to open a color picker, so it 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 a menu tag with the same pattern and document type exists, this function adds items to the existing menu.
Arguments
menuGroupId, pattern, labelArray, {valueArray}, {iconArray}, {doctypes}, {casesensitive}, {object}, {descriptionArray}, {dismissChars}, {allowWhitespacePrefix}, {restriction}, {type}, {bForcedOnly}, {allowMultipleTimes}, {docURI}, {alias}
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 must be of 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 document. If the string to be inserted is always the same as the menu label, this argument can 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. This menu appears only if the text that the user types 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.
The object argument specifies the name of the string. This argument is optional. It is used when the object is of type "static."
The descriptionArray argument describes in detail the items that appear in code hints. This argument is optional.
The dismissChars argument specifies the nonstandard characters that the user types to dismiss the Code Hints menu. This argument is optional.
The allowWhitespacePrefix argument is a Boolean value that allows whitespace before the hint. This argument is optional and the default value is false.
The restriction argument is a string. This argument is optional and if not specified it does not place any constraint. On a web page that contains both client-side and server-side languages, you can use this argument to restrict the use of code hints to one of the following:
A specific language section
A code block
The type argument is used to define user interface menu types. This argument is optional and the default value is "Enumerated drop down UI." Other possible values are color, font, and url.
The bForcedOnly is a Boolean value. If true, the Code Hints menu pops up only when the keyboard shortcut (Ctrl+Space) is used. This argument is optional and the default value is false.
The allowMultipleTimes argument is a Boolean value. If true, it allows the same menu to pop up multiple times. This argument is optional and the default value is false.
The docURI argument enables the user to constrain the code hints to a specific document by providing the document URI (native OS file path). This argument is optional and if the document URI is not specified, it does not impose any constraint.
The alias argument enables the user to invoke code hints with an alternate pattern other than the one listed in pattern or classpattern argument. This argument is optional.
Returns
Nothing.
Example
If the user creates a recordset 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 pop-up 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 exists a function tag with the same pattern and document type, this function replaces the existing function tag.
Arguments
menuGroupId, pattern, {doctypes}, {casesensitive}, {object}, {description}, {icon}, source, {docURI}, {bClassPattern}, {bAddToObjectMethodList}, {restriction}
The menuGroupId argument is the ID string attribute of the 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. This menu appears only if the text that the user types 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.
The object argument specifies the name of the string. This argument is optional. It is used when the object is of type "static."
The description argument contains a detailed description for the function. This argument is optional.
The icon argument specifies the custom icon path to use in function drop down. This argument is optional.
The source argument contains a value that the second column of code hint displays. The default of this argument is empty.
The docURI argument enables the user to constrain the code hints to a specific document by providing the document URI (native OS File Path). This argument is optional and if the document URI is not specified, it does not impose any constraint.
The bClassPattern argument is a Boolean value. If set to true, states that the function belongs to a "class" instance and is not static. The default value is false. This argument is optional.
The bAddToObjectMethodList argument is a Boolean. If set to true, it enables the user to add a list of static functions. The default value is true. This argument is optional.
The restriction argument is a string. This argument is optional and if not specified, it does not place any constraint. On a web page that contains both client-side and server-side languages, you can use this argument to restrict the use of code hints to one of the following:
A specific language section
A code block
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()