Overlays in XUL - Adjusting the overlay to your application
(Page 3 of 4 )
If you use a locale with your application and read in things like menuitem labels, you should do the same with any overlays, so in this example, I should change the menu code within the overlay file to something like:
<menuitem id="menuitem1" label="&newlabel1;"/>
<menuitem id="menuitem1" label="&newlabel2;"/>
<menuitem id="menuitem1" label="&newlabel3;"/>
<menuitem id="menuitem1" label="&newlabel4;"/>
Then create a new DTD file with the code:
<!ENTITY newlabel1 "New item 1">
<!ENTITY newlabel2 "New item 2">
<!ENTITY newlabel3 "New item 3">
<!ENTITY newlabel4 "New item 4">
This DTD file should be saved with the name newmenuOverlay.dtd to match the overlay file and should be saved in your existing locale directory. This way, you won’t have to register the new DTD file with the chrome either; although before it can be used, you’ll need to add the following DOCTYPE declaration to your newmenuOverlay.xul file:
<!DOCTYPE overlay SYSTEM
"chrome://interface/locale/newmenuOverlay.dtd">
So now, any window that needs to contain this menu can simply have the statement that imports the overlay, and an ID matched menu element (or whatever element is being overlaid), and it can make use of the overlay file. This is also the same means by which files can be taken from Mozilla itself to cut down on the amount of coding that is required. You know that Mozilla is going to be installed on the end users system in order for XUL to work, so when creating XUL applications for deployment, you can rely on being able to borrow elements like these from Mozilla.
Overlays can also overlay other overlay files as well as JavaScript or CSS files, so when using Mozilla content in your own applications not only can you overlay the elements used to build the desired menus, you can also use overlays to import the functionality which can cut down massively on the amount of coding you need to do, especially when it comes to some of the complicated XPCOM interfaces that are required in order to build things like the file open/save functionality that is often required in applications.
Next: Creating a dynamic overlay >>
More XML Articles
More By Dan Wellman