User Guide
164 Chapter 8: Menus and Menu Commands
Placing the command file in the Menu folder
To implement the menu Undo and Redo menu items, you must save the MyMenu.htm
command file in the Dreamweaver Configuration/Menus folder or a subfolder that you create.
The location of the file must agree with the location that you specified on the
menuitem tag. To
make it accessible to Dreamweaver, either restart Dreamweaver or reload extensions. For
information on how to reload extensions, see “Running the command” on page 144.
To run the menu commands, select the menu item when it is enabled. Dreamweaver will invoke
the functions in the command file, as described in “How menu commands work” on page 155.
A dynamic menu
This example implements the Dreamweaver Preview in Browser submenu that displays a list of
available browsers. The example also opens the current file, or the selected files in the Site panel,
in the user-specified browser. Implementing this dynamic menu consists of the following steps:
1 Creating the dynamic menu items
2 Writing the JavaScript code
Creating the dynamic menu items
The following menu tags in the menus.xml file define the Preview in Browser submenu of the
File menu:
<menu name="_Preview in Browser" id="DWMenu_File_PIB">
<menuitem dynamic name="No Browsers Selected"
file="Menus/MM/PIB_Dynamic.htm" arguments="'No Browsers'"
id="DWMenu_File_PIB_Default" />
<separator />
<menuitem name="_Edit Browser List..." enabled="true"
command="dw.editBrowserList()" id="DWMenu_File_PIB_EditBrowserList" />
</menu>
The first menuitem tag defines the default menu item No Browsers Selected, which appears on
the submenu if you have not specified any browsers for the Preview in Browser item in
Preferences. If you specified the Internet Explorer browser, however, the submenu would look like
the following figure:
The
name attribute for the first menu item specifies the command file PIB_Dynamic.htm. This
file contains the following line:
<SCRIPT LANGUAGE="javascript" SRC="PIB_Dynamic.js"></SCRIPT>
The script tag includes the JavaScript code in the PIB_Dynamic.js file, which supplies the
JavaScript code that interacts with the Preview in Browser submenu. This code could be saved
directly in the PIB_Dynamic.htm file, but storing it in a separate file allows multiple commands
to include the same code.