The Deep End

go to graworks.com! email!

Thursday, May 19, 2005

Thunderbird Extensions: Adding Stuff to the Editor Tag

This post describes how to add stuff to the message body textbox in a compose window. The message body textbox is really a XUL element called the editor tag. If you search around the mozilla source (line 692 of messengercompose.xul), you'll find
<editor type="content-primary" id="content-frame" src="about:blank" name="browser.message.body" flex="1">
Apparently, the editor tag is really, in Javascript, a nsIEditorBoxObject. The Mozilla Documentation has some highly informative information about this, although it didn't really help me.

What did help me was wandering helplessly around the Internet and XulPlanet until I found The Answer. Here it is:
var domndEditor = document.getElementById("content-frame");
var htmlEditor = domndEditor.getHTMLEditor(domndEditor.contentWindow); //htmlEditor is the same
// thing as nsiEditor!!!

//this means that the editor
//is a bizarre mixture
//of about a gazillion
//interfaces.

//there may be some better way to do this if(body.toUpperCase().indexOf("html")==-1){
htmlEditor = htmlEditor.QueryInterface(Components.interfaces.nsIPlaintextEditor);
//this is so weird. htmlEditor, I command you to become an //nsIPlainTextEditor!!!
//...
//it worked!




htmlEditor.insertText(body);
}
else htmlEditor.insertHTML(body); //body is whatever text you'd like to //insert into the editor tag (or "that textbox message body thing in a //compose window")

1 Comments:

Post a Comment

<< Home