Overlays are an important aspect of XUL, but this is a subject that Iíve barely mentioned in previous articles. Overlays can be used for a variety of purposes when designing/writing XUL applications and come in either explicit or dynamic flavors. Explicit overlays are used within your own application and form the basis of code modularization.
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:
<!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.