Mercurial > hg > FirefoxAddon
changeset 0:9869cf47fcf8 default tip
initial commit of Firefox addon template
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/__init__.py Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,22 @@ +from paste.script import templates + +var = templates.var + +class FirefoxAddon(templates.Template): + _template_dir = 'template' + summary = 'template for a firefox addon' + vars = [ + var('description', 'One-line description of the package'), + var('author', 'Author name'), + var('url', 'URL of homepage'), + ] + + def pre(self, command, output_dir, vars): + """ + called before the template is applied + """ + + def post(self, command, output_dir, vars): + """ + called after the template is applied + """
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/README.txt Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,1 @@ +FirefoxAddon: template for a firefox addon
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/build.sh Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,128 @@ +#!/bin/bash +# build.sh -- builds JAR and XPI files for mozilla extensions +# by Nickolay Ponomarev <asqueella@gmail.com> +# (original version based on Nathan Yergler's build script) +# Most recent version is at <http://kb.mozillazine.org/Bash_build_script> + +# This script assumes the following directory structure: +# ./ +# chrome.manifest (optional - for newer extensions) +# install.rdf +# (other files listed in $ROOT_FILES) +# +# content/ | +# locale/ |} these can be named arbitrary and listed in $CHROME_PROVIDERS +# skin/ | +# +# defaults/ | +# components/ |} these must be listed in $ROOT_DIRS in order to be packaged +# ... | +# +# It uses a temporary directory ./build when building; don't use that! +# Script's output is: +# ./$APP_NAME.xpi +# ./$APP_NAME.jar (only if $KEEP_JAR=1) +# ./files -- the list of packaged files +# +# Note: It modifies chrome.manifest when packaging so that it points to +# chrome/$APP_NAME.jar!/* + +# +# default configuration file is ./config_build.sh, unless another file is +# specified in command-line. Available config variables: +APP_NAME= # short-name, jar and xpi files name. Must be lowercase with no spaces +CHROME_PROVIDERS= # which chrome providers we have (space-separated list) +CLEAN_UP= # delete the jar / "files" when done? (1/0) +ROOT_FILES= # put these files in root of xpi (space separated list of leaf filenames) +ROOT_DIRS= # ...and these directories (space separated list) +BEFORE_BUILD= # run this before building (bash command) +AFTER_BUILD= # ...and this after the build (bash command) + +if [ -z $1 ]; then + . ./config_build.sh +else + . $1 +fi + +if [ -z $APP_NAME ]; then + echo "You need to create build config file first!" + echo "Read comments at the beginning of this script for more info." + exit; +fi + +ROOT_DIR=`pwd` +TMP_DIR=build + +#uncomment to debug +#set -x + +# remove any left-over files from previous build +rm -f $APP_NAME.jar $APP_NAME.xpi files +rm -rf $TMP_DIR + +$BEFORE_BUILD + +mkdir --parents --verbose $TMP_DIR/chrome + +# generate the JAR file, excluding CVS and temporary files +JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar +echo "Generating $JAR_FILE..." +for CHROME_SUBDIR in $CHROME_PROVIDERS; do + find $CHROME_SUBDIR -path '*CVS*' -prune -o -type f -print | grep -v \~ >> files +done + +zip -0 -r $JAR_FILE `cat files` +# The following statement should be used instead if you don't wish to use the JAR file +#cp --verbose --parents `cat files` $TMP_DIR/chrome + +# prepare components and defaults +echo "Copying various files to $TMP_DIR folder..." +for DIR in $ROOT_DIRS; do + mkdir $TMP_DIR/$DIR + FILES="`find $DIR -path '*CVS*' -prune -o -type f -print | grep -v \~`" + echo $FILES >> files + cp --verbose --parents $FILES $TMP_DIR +done + +# Copy other files to the root of future XPI. +for ROOT_FILE in $ROOT_FILES install.rdf chrome.manifest; do + cp --verbose $ROOT_FILE $TMP_DIR + if [ -f $ROOT_FILE ]; then + echo $ROOT_FILE >> files + fi +done + +cd $TMP_DIR + +if [ -f "chrome.manifest" ]; then + echo "Preprocessing chrome.manifest..." + # You think this is scary? + #s/^(content\s+\S*\s+)(\S*\/)$/\1jar:chrome\/$APP_NAME\.jar!\/\2/ + #s/^(skin|locale)(\s+\S*\s+\S*\s+)(.*\/)$/\1\2jar:chrome\/$APP_NAME\.jar!\/\3/ + # + # Then try this! (Same, but with characters escaped for bash :) + sed -i -r s/^\(content\\s+\\S*\\s+\)\(\\S*\\/\)$/\\1jar:chrome\\/$APP_NAME\\.jar!\\/\\2/ chrome.manifest + sed -i -r s/^\(skin\|locale\)\(\\s+\\S*\\s+\\S*\\s+\)\(.*\\/\)$/\\1\\2jar:chrome\\/$APP_NAME\\.jar!\\/\\3/ chrome.manifest + + # (it simply adds jar:chrome/whatever.jar!/ at appropriate positions of chrome.manifest) +fi + +# generate the XPI file +echo "Generating $APP_NAME.xpi..." +zip -r ../$APP_NAME.xpi * + +cd "$ROOT_DIR" + +echo "Cleanup..." +if [ $CLEAN_UP = 0 ]; then + # save the jar file + mv $TMP_DIR/chrome/$APP_NAME.jar . +else + rm ./files +fi + +# remove the working files +rm -rf $TMP_DIR +echo "Done!" + +$AFTER_BUILD
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/chrome.manifest_tmpl Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,5 @@ +content ${package} content/ +locale ${package} en-US locale/en-US/ +skin ${package} classic/1.0 skin/ +overlay chrome://browser/content/browser.xul chrome://${package}/content/firefoxOverlay.xul +style chrome://global/content/customizeToolbar.xul chrome://${package}/skin/overlay.css
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/config_build.sh_tmpl Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,9 @@ +#!/bin/bash +# Build config for build.sh +APP_NAME=${package} +CHROME_PROVIDERS="content locale skin" +CLEAN_UP=1 +ROOT_FILES= +ROOT_DIRS="defaults" +BEFORE_BUILD= +AFTER_BUILD=
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/content/about.xul_tmpl Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> +<!DOCTYPE dialog SYSTEM "chrome://${package}/locale/about.dtd"> +<dialog title="&about; ${description}" orient="vertical" autostretch="always" onload="sizeToContent()" buttons="accept" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> +<!-- Original template by Jed Brown --> +<groupbox align="center" orient="horizontal"> +<vbox> + <text value="${description}" style="font-weight: bold; font-size: x-large;"/> + <text value="&version; 1.0"/> + <separator class="thin"/> + <text value="&createdBy;" style="font-weight: bold;"/> + <text value="${author}"/> + <separator class="thin"/> + <text value="&homepage;" style="font-weight: bold;"/> + <text value="${url}" + class="url" + onclick="window.open('${url}'); window.close();"/> + <separator class="thin"/> +</vbox> +</groupbox> +</dialog>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/content/firefoxOverlay.xul_tmpl Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?xml-stylesheet href="chrome://${package}/skin/overlay.css" type="text/css"?> +<!DOCTYPE overlay SYSTEM "chrome://${package}/locale/${package}.dtd"> +<overlay id="${package}-overlay" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script src="overlay.js"/> + <stringbundleset id="stringbundleset"> + <stringbundle id="${package}-strings" src="chrome://${package}/locale/${package}.properties"/> + </stringbundleset> + + <menupopup id="menu_ToolsPopup"> + <menuitem id="${package}-hello" label="&${package}.label;" + oncommand="${package}.onMenuItemCommand(event);"/> + </menupopup> + <popup id="contentAreaContextMenu"> + <menuitem id="context-${package}" label="&${package}Context.label;" + accesskey="&${package}Context.accesskey;" + insertafter="context-stop" + oncommand="${package}.onMenuItemCommand(event)"/> + </popup> + <toolbarpalette id="BrowserToolbarPalette"> + <toolbarbutton id="${package}-toolbar-button" + label="&${package}Toolbar.label;" + tooltiptext="&${package}Toolbar.tooltip;" + oncommand="${package}.onToolbarButtonCommand()" + class="toolbarbutton-1 chromeclass-toolbar-additional"/> + </toolbarpalette> +</overlay>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/content/options.xul_tmpl Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> +<!DOCTYPE prefwindow SYSTEM "chrome://${package}/locale/prefwindow.dtd"> +<prefwindow id="${package}Preferences" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" title="&prefwindow.title;"> + <prefpane id="pane1" label="&pane1.title;"> + <preferences> + <preference id="boolpref1" name="extensions.${package}.boolpref" type="bool"/> + <preference id="intpref1" name="extensions.${package}.intpref" type="int"/> + <preference id="stringpref1" name="extensions.${package}.stringpref" type="string"/> <!-- note that this is only an ASCII string - use unichar for unicode strings --> + </preferences> + <checkbox id="checkboolpref" preference="boolpref1" label="&checkboolpref.label;" accesskey="&checkboolpref.accesskey;"/> + <label accesskey="&intpref.accesskey;" control="textintpref">&intpref.label;</label><textbox id="textintpref" preference="intpref1"/> + <label accesskey="&stringpref.accesskey;" control="textstringpref">&stringpref.label;</label><textbox id="textstringpref" preference="stringpref1"/> + </prefpane> +</prefwindow>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/content/overlay.js_tmpl Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,27 @@ +var ${package} = { + onLoad: function() { + // initialization code + this.initialized = true; + this.strings = document.getElementById("${package}-strings"); + document.getElementById("contentAreaContextMenu") + .addEventListener("popupshowing", function(e) { this.showContextMenu(e); }, false); + }, + + showContextMenu: function(event) { + // show or hide the menuitem based on what the context menu is on + // see http://kb.mozillazine.org/Adding_items_to_menus + document.getElementById("context-${package}").hidden = gContextMenu.onImage; + }, + onMenuItemCommand: function(e) { + var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] + .getService(Components.interfaces.nsIPromptService); + promptService.alert(window, this.strings.getString("helloMessageTitle"), + this.strings.getString("helloMessage")); + }, + onToolbarButtonCommand: function(e) { + // just reuse the function above. you can change this, obviously! + ${package}.onMenuItemCommand(e); + } + +}; +window.addEventListener("load", function(e) { ${package}.onLoad(e); }, false);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/defaults/preferences/++package++.js_tmpl Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,5 @@ +pref("extensions.${package}.boolpref", false); +pref("extensions.${package}.intpref", 0); +pref("extensions.${package}.stringpref", "A string"); +// See http://kb.mozillazine.org/Localize_extension_descriptions +pref("extensions.${package}@jeff.hammel.description", "chrome://${package}/locale/${package}.properties");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/install.rdf_tmpl Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:em="http://www.mozilla.org/2004/em-rdf#"> + <Description about="urn:mozilla:install-manifest"> + <em:id>${package}@${'.'.join([i.lower() for i in author.split()])}</em:id> + <em:name>${project}</em:name> + <em:version>1.0</em:version> + <em:creator>${author}</em:creator> + <em:description>${description}</em:description> + <em:homepageURL>${url}</em:homepageURL> + <em:aboutURL>chrome://${package}/content/about.xul</em:aboutURL> + <em:optionsURL>chrome://${package}/content/options.xul</em:optionsURL> + <em:iconURL>chrome://${package}/content/${package}.jpg</em:iconURL> + <em:targetApplication> + <Description> + <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> <!-- firefox --> + <em:minVersion>1.5</em:minVersion> + <em:maxVersion>3.0.*</em:maxVersion> + </Description> + </em:targetApplication> + </Description> +</RDF>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/locale/en-US/++package++.dtd Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,5 @@ +<!ENTITY helloworld.label "Your localized menuitem"> +<!ENTITY helloworldContext.label "Your Menuitem"> +<!ENTITY helloworldContext.accesskey "Y"> +<!ENTITY helloworldToolbar.label "Your Toolbar Button"> +<!ENTITY helloworldToolbar.tooltip "This is your toolbar button!">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/locale/en-US/++package++.properties_tmpl Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,4 @@ +helloMessage=${project} +helloMessageTitle=hello +prefMessage=Int Pref Value: %d +extensions.helloworld.description=${description}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/locale/en-US/about.dtd Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,4 @@ +<!ENTITY about "About"> +<!ENTITY version "Version:"> +<!ENTITY createdBy "Created By:"> +<!ENTITY homepage "Home Page:">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/locale/en-US/prefwindow.dtd_tmpl Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,8 @@ +<!ENTITY prefwindow.title "${project} preferences"> +<!ENTITY pane1.title "${project} preferences"> +<!ENTITY checkboolpref.label "A Boolean Preference"> +<!ENTITY checkboolpref.accesskey "B"> +<!ENTITY intpref.label "An Integer Preference"> +<!ENTITY intpref.accesskey "I"> +<!ENTITY stringpref.label "A String Preference"> +<!ENTITY stringpref.accesskey "S">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/readme.txt Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,21 @@ +This extension was generated by the Extension Wizard at +http://ted.mielczarek.org/code/mozilla/extensionwiz/ . +This extension is compatible only with Firefox 1.5 and +above. Most of the files in this package are based on +the 'helloworld' extension from the Mozillazine Knowledge Base. + +You can build an XPI for installation by running the +build.sh script located in this folder. For development +you should do the following: + 1. Unzip the entire contents of this package to somewhere, + e.g, c:\dev or /home/user/dev + 2. Put the full path to the folder (e.g. c:\dev\helloworld on + Windows, /home/user/dev/helloworld on Linux) in a file named + helloworld@jeff.hammel and copy that file to + [your profile folder]\extensions\ + 3. Restart Firefox. + +For more information, see the Mozillazine Knowledge Base: +http://kb.mozillazine.org/Getting_started_with_extension_development + +-Ted Mielczarek <ted.mielczarek@gmail.com>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/firefoxaddon/template/skin/overlay.css_tmpl Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,22 @@ +/* This is just an example. You shouldn't do this. */ +#${package}-hello +{ + color: red ! important; +} +#${package}-toolbar-button +{ + list-style-image: url("chrome://${package}/skin/toolbar-button.png"); + -moz-image-region: rect(0px 24px 24px 0px); +} +#${package}-toolbar-button:hover +{ + -moz-image-region: rect(24px 24px 48px 0px); +} +[iconsize="small"] #${package}-toolbar-button +{ + -moz-image-region: rect( 0px 40px 16px 24px); +} +[iconsize="small"] #${package}-toolbar-button:hover +{ + -moz-image-region: rect(24px 40px 40px 24px); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Sun Mar 28 16:25:58 2010 -0400 @@ -0,0 +1,22 @@ +from setuptools import find_packages, setup + +version='0.0' + +setup(name='FirefoxAddon', + version=version, + description="template for a firefox addon", + author='Jeff Hammel', + author_email='jhammel@mozilla.com', + url='', + keywords='trac plugin', + license="", + packages=find_packages(exclude=['ez_setup', 'examples', 'tests*']), + include_package_data=True, + install_requires = [ 'PasteScript' ], + zip_safe=False, + entry_points = """ + [paste.paster_create_template] + firefoxaddon = firefoxaddon:FirefoxAddon + """, + ) +