
Appendix B. Development Tools- P1
This book describes how to create applications using Mozilla. Generally, all
parts that go into an application (including XUL, CSS, XBL, and DTD files)
need to be built by hand since no complete ready-made development tools or
development applications are available that would make these manual
processes easier.
Creating all these files by hand is a great way to familiarize yourself with the
way Mozilla works, and becoming more familiar with the inner workings of
a Mozilla application certainly helps you see how the various parts fit
together. Once you are comfortable creating these files by hand, using the
platform becomes much easier and Mozilla fulfills its promise as a rich
application development framework.
Development tools are important, though, and platforms like Mozilla can't
obtain the sort of developer base they deserve until tools that make
application creation easier are available. Although some people want to learn
everything there is to know about creating applications with Mozilla, many
simply want to create something without a lot of fuss.
Mozilla does not yet have a full set of development tools, but currently
several development projects help with part of the application creation
process. These tools don't make up a full-featured development
environment, but they are useful. They also point the way to an area in
Mozilla development that has a bright future and is worth watching.
This appendix describes some of the new tools -- including XULKit, Patch
Maker, the DOM Inspector, the JavaScript Debugger, and MozillaTranslator

-- that are already becoming a part of the regular repertoire of Mozilla
developers. By learning about how to use these tools for your own project,
you can radically simplify the application development process, especially
when you combine these tools.
B.1. XULKit
Much of the manual editing described in Chapters Chapter 6, Chapter 7, and
Chapter 8 can be automated with special scripts and templates being
developed in the Mozilla source tree's tools/wizards section (these
files are referred to collectively as the XULKit and can be found at
http://www.hacksrus.com/~ginda/xulkit/doc/).
These tools help you develop your Mozilla application by generating as
much of the basic content, structure, and packaging of an application as
possible, leaving you free to work only on the aspects of your application
that you care about. We mention XULKit first because it can make setting
up new Mozilla applications a snap.
XULKit is essentially a set of two scripts: new-from-template.pl,
which creates a new application framework, and makexpi.pl, which
packages your application once you finish developing it.
B.1.1. new-from-template.pl Script
Though it's not named very elegantly, the new-from-template.pl Perl
script takes information you provide in the form of a simple text file and
uses it to create various parts of a Mozilla application. These parts include
the XUL content, which has a basic menubar you can add to; an overlay that
puts an item for your application into the Tools menu in the Mozilla
browser; CSS for your XUL; and an installation script for the application

package. You can base your application off of a couple of different
templates, including a sophisticated one that lets you generate XPCOM
interfaces for components you wish to use in your application, described
below.
Using these scripts, you can add content and logic to your application,
restyle it, or build your application however you would like. You can also
register the resulting directory with the chrome registry to see it working in
your local copy of Mozilla, and when you finish developing it, the
application directory is already structured in exactly the way it must be to be
checked into the Mozilla source tree's extensions directory (if you want to
check it into this common location for applications that become a part of
Mozilla). When you want to distribute your application as described in
Chapter 6, you can use the other script in the XULKit, makexpi.pl, to
package your application files into a cross-platform archive that can be
installed from a regular web page.
To use the new-from-template.pl script, point it at a template that
you filled out with your own information. It then generates the basic
application code in the appropriate subdirectory structure:
new-from-template.pl -t FILE [-o DIRECTORY] [-
f[d]] [-h] [-?]
When you run the script, the XULKit creates a new top-level application
directory. In this directory, the script creates the three main package
directories, and it places some basic content in each one: a CSS file called
mozreg.css in the skins subdirectory, a few XUL files in the
content directory (including the overlay that defines a new menu item for

the main browser that opens this new application), and localizable data in the
mozref.dtd file in the locale subdirectory.
In addition to these files, the XULKit script creates contents.rdf files
that describe each package, some Makefiles that instruct the Mozilla build
process how to integrate this application into the build (which is a later step
and not necessary to run the application), and an install.js file that
executes the installation of this application when it appears in a XPI. (See
Chapter 6 for more information about XPI, Mozilla's cross-platform
installation file format.)
If you look at Example B-1 -- xul-app.tpl, which comes with the
distribution of new-from-template.pl -- you can see how easy it is to
fill out the basic information and create your own template.
Example B-1. Sample application template
# load default template for a XUL app
include "${top_wizard_dir}templates/xul-app.tpl"
# short app name (can not contain spaces.)
# until
http://bugzilla.mozilla.org/show_bug.cgi?id=75670
is fixed, this needs
# to be all lowercase.
app_name_short=xulsample
# long app name (spaces are OK.)
app_name_long=Sample XUL Application (generated
from sample.xul-app.tpl)

# name as it should appear in the menu
app_name_menu=Sample XUL App
# version to tell the .xpi installer
app_version=1.0
# author, used in various chrome and app
registration calls
app_author=mozilla.org
# size of the package when installed, in kilobytes.
# this number is used by the install.js script to
check for enough disk space
# before the .xpi is installed. You can just guess
for now, or put 1, and fix it
# in install.js before you make your .xpi file.
install_size_kilobytes=1
You can adapt the xul-app.tpl for your own purposes or use the
sample.xul-app.tpl that is already filled out. Table B-1 details
different options for new-from-template.pl.
Table B-1. Options for the new-from-template.pl script
Option Description
-d
Recursively deletes the output
directory before starting; requires the
-f option.