在开幕时填写撰写邮件

时间:2014-10-12 16:39:50

标签: thunderbird-addon

我正在寻找一种方法,在打开时,在一个增强型(无重启)TB附加组件中填写撰写消息。

这是我在非引导加载项RemindIt

中所做的事情

感谢Superjos我能够管理不同的侦听器,并在打开时获得用自定义消息填充的撰写消息。

但是......这仅适用于新的(非再循环)窗户。如果我关闭一个撰写窗口,然后点击"新邮件",它会被回收(我猜)和#34;加载"事件未被解雇。

我尝试了不同的技巧(例如参见onComposeInit2),但最后,我无法改变非新窗口的撰写邮件,即使看起来我的插件正在调用编辑方法(这是人们在日志中可以看到的内容)。

有什么想法吗?

请参阅我的test / bootstrap.js代码:

function log(s){
    Components.classes["@mozilla.org/consoleservice;1"]
    .getService(Components.interfaces.nsIConsoleService).logStringMessage("test: "+s);
}
// Thanks (a lot ! ) to Superjos :
// https://stackoverflow.com/questions/25989864/get-sender-and-recipients-in-thunderbird-extension-upon-sending-message

var winListener={
    onOpenWindow: function(win){
    compose=win.docShell.
      QueryInterface(Components.interfaces.nsIInterfaceRequestor).
      getInterface(Components.interfaces.nsIDOMWindow);
    compose.addEventListener('compose-window-init', winListener.onComposeInit, true);

    },
    onComposeInit: function(event){
    var document=event.currentTarget.document;   
    var edit=document.getElementById("content-frame");
    edit.addEventListener("load",winListener.onComposeLoad,true);

    log("compose init "+event.currentTarget);

    event.currentTarget.removeEventListener(event.type,winListener.onComposeInit , true);

    },


    onComposeLoad: function(event){
    var edit=event.currentTarget;
    var editor=edit.getHTMLEditor(edit.contentWindow);
    log("compose load");
    winListener.alterMessage(editor);
    },
    alterMessage: function(editor){
    var msg="Hello<br>";
    editor.insertHTML(msg);
    log("alter message "+editor);
    },

    onComposeInit2: function(event){
    var document=event.currentTarget.document;   
    var edit=document.getElementById("content-frame");
    edit.addEventListener("load",winListener.onComposeLoad,true);

    log("compose init "+event.currentTarget);

    var editor=edit.getHTMLEditor(edit.contentWindow);
    if( editor!=null ){
        // the editor is ready, remove load event listener
        edit.removeEventListener("load",winListener.onComposeLoad,true);
        // and call the method to alter message
        winListener.alterMessage(editor);
    }
    //edit.addEventListener("focus",winListener.onFocus,true);
    event.currentTarget.removeEventListener(event.type,winListener.onComposeInit2 , true);

    },
    /*
    onFocus: function(event){
    event.currentTarget.removeEventListener("focus",winListener.onFocus,true);
    var edit=event.currentTarget;
    var editor=edit.getHTMLEditor(edit.contentWindow);
    winListener.alterMessage(editor);
    log("focus");
    },
    onComposeClose: function(event){
    var document=event.currentTarget.document;   
    var edit=document.getElementById("content-frame");
    edit.addEventListener("focus",winListener.onFocus,true);
    log("close");

    }
*/

}



function startup(aData, aReason) {
    log("startup");

var windowMediator = Components.classes['@mozilla.org/appshell/window-mediator;1'].
  getService(Components.interfaces.nsIWindowMediator);

windowMediator.addListener(winListener);


}

function shutdown(aData, aReason) {
    log("shutdown");
    var windowMediator = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);  
    windowMediator.removeListener(winListener);

}

function install(aData, aReason) { 

    log("install");


}

function uninstall(aData, aReason) {
    log("uninstall");


 }

1 个答案:

答案 0 :(得分:0)

我找到了http://forums.mozillazine.org/viewtopic.php?f=19&t=450474的解决方案 重新打开窗口时会触发一个compose-window-reopen事件。