The Deep End

go to graworks.com! email!

Friday, July 29, 2005

Xul: Creating toolbar buttons

Mozillazine has a great article on creating toolbar buttons. One thing they sort of go into is toolbar palettes -- here are the toolbar palettes I've run across:

MailToolbarPalette: the toolbar in Thunderbird's main window

MsgComposeToolbarPalette: the toolbar for a Thunderbird compose window

AddressBookToolbarPalette: the toolbar for the address book toolbar palette, but if you're trying to write an overlay for the address book, you'll need to modify your contents.rdf file to add an overlay for the address book .xul file.

Tuesday, July 26, 2005

Arrays in Javascript

Arrays in Javascript are awesome. Just look at all the things you can do with them:

you can pop,
you can push,
you can remove,
you can splice,
you can unshift (which adds new elements to the front and returns the length)
you can sort
you can reverse the entire array

you can define it like new Array("this", "this", "this", "this")
or like = ["jaa","whaa","gaaa"]

they're beautiful

about:Config Extension

In previous Reloadchromezilla-related posts the process to add the nglayout.debug.disable_xul_cache preference is a little laborious -- it turns out that you can just download the about:config extension for Thunderbird! You can read more about the about:config extension here. It's a great extension, and from my experience, worked a lot better than the preferential extension (which consistently crashed Thunderbird while building a tree of preferences)

Thursday, July 14, 2005

How do you download messages from an IMAP folder??

How do you download messages from a folder on an IMAP server?? Specifically, with an XPCOM component of some kind...

using folder.DownloadMessagesForOffline(msgHdrArray,msgWindow); doesn't work.

nsIImapService has a downloadMessagesForOffline(),but the parameters are really confusing-- a "char *" of messageIds?? Does that mean that I'm supposed to do something like var messageIds = id1 + "," +id2?? How would I even get a messageId if none of the messages have been downloaded yet (the getMessages function returns an empty nsISimpleEnumerator)

What the heck?

Monday, July 11, 2005

I wrote an extension!!

It's called Reloadchromezilla (yep) and it can be downloaded here at Mozilla Update.

It adds a "Reload Chrome" option to the context menu and a toolbar button.

As far as version 0.0.3 is concerned, you'll still need to set things up before Reloadchromezilla will work (see previous posts), but eventually Reloadchromezilla may do this on its own.

Wednesday, July 06, 2005

PART TWO: No More Restarts to Thunderbird Ext...

This post deals with some features of the new Reloadchromezilla extension and how to set up your development environment for Reloadchromezilla to work. Part One deals with how Reloadchromezilla actually works.


You'll have to configure a lot of stuff in Thunderbird:

(1) go to the Mozillazine Knowledgebase entry, "Setting Up the Extension Development Environment" Everything here is pretty straightforward--basically, there are just a few handy options which I don't actually use.

(2) Disable The "XUL Cache" This is another Knowledgebase entry. Disabling the XUL cache is a must for the "Reload Chrome" feature to work. Basically, you need to find your extension in your profile directory, unpack the .jar file, and remove references to the jar file in the chrome.rdf and install.rdf files--read the article.

As the article states, you will also have to set a preference in your user.js, which Thunderbird does not automatically create. So you might need to:

(3) Create a user.js file: First, get to your profile -- for example, c:\documents and settings\{user}\Application Data\Thunderbird\Profiles\{your profile--if there's more than one, explore around to find the one that's yours}
Next, create a file called user.js with something like Notepad, and add,
user_pref("nglayout.debug.disable_xul_cache", true);
You've just created a user.js file and disabled the XUL cache!

However, as Disable The "XUL Cache" further states, you'll also need to edit install.rdf and chrome.rdf. The article also goes on to state something about injecting Javascript, but I'm not sure how this would work if you have a large and complicated extension--I ignored it.

And you should be done! The files that you edit from now on should be the files in your profile's extensions folder--find your GUID, open that folder, open some files and extend away! Unfortunately, the Reloadchromezilla extension (which follows the procedure outlined in previous posts) will not update changes you make to your install.rdf file. I'm guessing that the reason for this is that because the install.rdf file is not in what would normally be your .jar, it is outside the chrome. If you want to change the install.rdf file, you'll need to reinstall your extenesion the normal way, with the "Extension Builder" option of the Extension Builder's Extension

Note: as the knowledgebase articles state, you'll need to unpack your .jar file in your extension directory (which is located in your profile directory)

Tuesday, July 05, 2005

PART ONE: No More Restarts for Installing Thunderbird Extensions

What came of this post was theReloadchromezilla extension; if you're looking for how to set up Thunderbird to use Reloadchromezilla, see Part Two--Part One deals with how the extension actually works.


As I wandered the Internet for how to not have to package your .xpi, install, and restart thunderbird, I happened across Ted Mielczarek's Extension Developer's Extension. Apparently, this program works beautifully and effortlessly for Firefox, but unfortunately I develop for Thunderbird. Mr. Mielczarek seemed to be having a problem with getting this to work in Thunderbird, so I opened up the .xpi (hope you don't mind; thanks for the great extension) and poked around until I got it to work.

The feature of the Extension Developer's Extension that allows you to see your changes without restarting is the "Reload All Chrome" feature. The "Reload All Chrome" feature consists of getting an instance of a @mozilla.org/chrome/chrome-registry;1 component, like this:
var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"].
getService(Components.interfaces.nsIXULChromeRegistry);
The nsIXulChromeRegistry interface is the one with the reloadChrome method.

Because the method's name is "reloadChrome," you would expect this to work. However, calling this will just mutate your Thunderbird window into a mass of deformity which is summarily unresponsive to doing whatever you normally do with Thunderbird.

I think the moral of this brief and ultimately fulfilling story is to never give up, even when confronted by the most insane difficulties. Basically, you just call reloadChrome() again!

here's the code:
function reloadTheChromeDammit(){
try {

var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"].
getService(Components.interfaces.nsIXULChromeRegistry);

chromeRegistry.reloadChrome();

var params ={out: ""};

window.open("chrome://reloadchromezilla/content/pleasewaitdialog.xul",
"_blank",
"chrome,close,titlebar,modal,centerscreen");

} catch(e) { }
}
The "dialog" pleasewaitdialog.xul is really just a window. The .xul file looks like this:



<page id="please-wait-dialog" title="Please Wait" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="pleaseWaitLoad();">
<description value="Please wait while whatever aweseome modifications you've made to your chrome are loaded">
<script src= "chrome://reloadchromezilla/content/reloadchromezillaoverlay.js">
</script>
</description></page>
The function pleaseWaitLoad() looks like this:
function pleaseWaitLoad(){
try{
var dialog = document.getElementById("please-wait-dialog");
setTimeout(function(){try{ var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"].
getService(Components.interfaces.nsIXULChromeRegistry);
chromeRegistry.reloadChrome(); window.close(); }catch(e){alert(e)}},2000);
}catch(e){
alert("in pleasewaitload "+e);
}
}
this is necessary because without setTimeout, Thunderbird executes the two reloadChrome() functions too quickly--apparently, you have to wait until Thunderbird has completely hosed itself from the first reloadChrome() before you can bring it back with another call to reloadChrome().

Hopefully this was useful to someone; an extension may follow.

Again, thank you Ted Mielczarek for being a lot better at developing Mozilla than I am!

Friday, July 01, 2005

JavaScript Guide

Found a great link while searching for info on the throw statement in Javascript--if you need to clarify something about Javascript's syntax, go to the Core JavaScript Guide. And hey, you can even download it!