msgcomposecommands.js

来自「现在很火的邮件客户端软件thunderbird的源码」· JavaScript 代码 · 共 1,865 行 · 第 1/5 页

JS
1,865
字号
    onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage)    {      // Looks like it's possible that we get call while the document has been already delete!      // therefore we need to protect ourself by using try/catch      try {        statusText = document.getElementById("statusText");        if (statusText)          statusText.setAttribute("label", aMessage);      } catch (ex) {}    },    onSecurityChange: function(aWebProgress, aRequest, state)    {      // we can ignore this notification    },    QueryInterface : function(iid)    {      if (iid.equals(Components.interfaces.nsIWebProgressListener) ||          iid.equals(Components.interfaces.nsISupportsWeakReference) ||          iid.equals(Components.interfaces.nsISupports))        return this;           throw Components.results.NS_NOINTERFACE;    }};var defaultController ={  supportsCommand: function(command)  {    switch (command)    {      //File Menu      case "cmd_attachFile":      case "cmd_attachPage":      case "cmd_close":      case "cmd_saveDefault":      case "cmd_saveAsFile":      case "cmd_saveAsDraft":      case "cmd_saveAsTemplate":      case "cmd_sendButton":      case "cmd_sendNow":      case "cmd_sendWithCheck":      case "cmd_sendLater":      case "cmd_printSetup":      case "cmd_print":      case "cmd_quit":      //Edit Menu      case "cmd_delete":      case "cmd_selectAll":      case "cmd_openAttachment":      case "cmd_account":      //View Menu      case "cmd_showComposeToolbar":      case "cmd_showFormatToolbar":      //Options Menu      case "cmd_selectAddress":      case "cmd_outputFormat":      case "cmd_quoteMessage":        return true;      default://        dump("##MsgCompose: command " + command + "no supported!\n");        return false;    }  },  isCommandEnabled: function(command)  {    var composeHTML = gMsgCompose && gMsgCompose.composeHTML;    switch (command)    {      //File Menu      case "cmd_attachFile":      case "cmd_attachPage":      case "cmd_close":      case "cmd_saveDefault":      case "cmd_saveAsFile":      case "cmd_saveAsDraft":      case "cmd_saveAsTemplate":      case "cmd_sendButton":      case "cmd_sendLater":      case "cmd_printSetup":      case "cmd_print":      case "cmd_sendWithCheck":        return !gWindowLocked;      case "cmd_sendNow":        return !(gWindowLocked || gIsOffline);      case "cmd_quit":        return true;      //Edit Menu      case "cmd_delete":        return MessageGetNumSelectedAttachments();      case "cmd_selectAll":        return MessageHasAttachments();      case "cmd_openAttachment":        return MessageGetNumSelectedAttachments() == 1;      case "cmd_account":      //View Menu      case "cmd_showComposeToolbar":        return true;      case "cmd_showFormatToolbar":        return composeHTML;      //Options Menu      case "cmd_selectAddress":        return !gWindowLocked;      case "cmd_outputFormat":        return composeHTML;      case "cmd_quoteMessage":        var selectedURIs = GetSelectedMessages();        if (selectedURIs && selectedURIs.length > 0)          return true;        return false;      default://        dump("##MsgCompose: command " + command + " disabled!\n");        return false;    }  },  doCommand: function(command)  {     switch (command)    {      //File Menu      case "cmd_attachFile"         : if (defaultController.isCommandEnabled(command)) AttachFile();           break;      case "cmd_attachPage"         : AttachPage();           break;      case "cmd_close"              : DoCommandClose();       break;      case "cmd_saveDefault"        : Save();                 break;      case "cmd_saveAsFile"         : SaveAsFile(true);       break;      case "cmd_saveAsDraft"        : SaveAsDraft();          break;      case "cmd_saveAsTemplate"     : SaveAsTemplate();       break;      case "cmd_sendButton"         :        if (defaultController.isCommandEnabled(command))        {          if (gIOService && gIOService.offline)            SendMessageLater();          else            SendMessage();        }        break;      case "cmd_sendNow"            : if (defaultController.isCommandEnabled(command)) SendMessage();          break;      case "cmd_sendWithCheck"   : if (defaultController.isCommandEnabled(command)) SendMessageWithCheck();          break;      case "cmd_sendLater"          : if (defaultController.isCommandEnabled(command)) SendMessageLater();     break;      case "cmd_printSetup"         : NSPrintSetup(); break;      case "cmd_print"              : DoCommandPrint(); break;      //Edit Menu      case "cmd_delete"             : if (MessageGetNumSelectedAttachments()) RemoveSelectedAttachment();         break;      case "cmd_selectAll"          : if (MessageHasAttachments()) SelectAllAttachments();                     break;      case "cmd_openAttachment"     : if (MessageGetNumSelectedAttachments() == 1) OpenSelectedAttachment();          break;      case "cmd_account"            : MsgAccountManager(null); break;      //View Menu      case "cmd_showComposeToolbar" : goToggleToolbar('composeToolbar2', 'menu_showComposeToolbar'); break;      case "cmd_showFormatToolbar"  : goToggleToolbar('FormatToolbar', 'menu_showFormatToolbar');   break;      //Options Menu      case "cmd_selectAddress"      : if (defaultController.isCommandEnabled(command)) SelectAddress();         break;      case "cmd_quoteMessage"       : if (defaultController.isCommandEnabled(command)) QuoteSelectedMessage();  break;      default://        dump("##MsgCompose: don't know what to do with command " + command + "!\n");        return;    }  },  onEvent: function(event)  {//    dump("DefaultController:onEvent\n");  }}function goOpenNewMessage(){  // if there is a MsgNewMessage function in scope  // and we should use it, so that we choose the proper  // identity, based on the selected message or folder  // if not, bring up the compose window to the default identity  if ("MsgNewMessage" in window) {    MsgNewMessage(null);    return;   }   var msgComposeService = Components.classes["@mozilla.org/messengercompose;1"].getService();   msgComposeService = msgComposeService.QueryInterface(Components.interfaces.nsIMsgComposeService);   msgComposeService.OpenComposeWindow(null, null,                                       Components.interfaces.nsIMsgCompType.New,                                       Components.interfaces.nsIMsgCompFormat.Default,                                       null, null);}function QuoteSelectedMessage(){  var selectedURIs = GetSelectedMessages();  if (selectedURIs)    for (i = 0; i < selectedURIs.length; i++)      gMsgCompose.quoteMessage(selectedURIs[i]);}function GetSelectedMessages(){  if (gMsgCompose) {    var mailWindow = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService()                     .QueryInterface(Components.interfaces.nsIWindowMediator)                     .getMostRecentWindow("mail:3pane");    if (mailWindow) {      return mailWindow.GetSelectedMessages();    }  }  return null;}function SetupCommandUpdateHandlers(){  top.controllers.insertControllerAt(0, defaultController);}function CommandUpdate_MsgCompose(){  var focusedWindow = top.document.commandDispatcher.focusedWindow;  // we're just setting focus to where it was before  if (focusedWindow == gLastWindowToHaveFocus) {    //dump("XXX skip\n");    return;  }  gLastWindowToHaveFocus = focusedWindow;  //dump("XXX update, focus on " + focusedWindow + "\n");    updateComposeItems();}function updateComposeItems(){  try {    // Edit Menu    goUpdateCommand("cmd_rewrap");    // Insert Menu    if (gMsgCompose && gMsgCompose.composeHTML)    {      goUpdateCommand("cmd_renderedHTMLEnabler");      goUpdateCommand("cmd_decreaseFont");      goUpdateCommand("cmd_increaseFont");      goUpdateCommand("cmd_bold");      goUpdateCommand("cmd_italic");      goUpdateCommand("cmd_underline");      goUpdateCommand("cmd_ul");      goUpdateCommand("cmd_ol");      goUpdateCommand("cmd_indent");      goUpdateCommand("cmd_outdent");      goUpdateCommand("cmd_align");      goUpdateCommand("cmd_smiley");    }    // Options Menu    goUpdateCommand("cmd_spelling");    goUpdateCommand("cmd_quoteMessage");  } catch(e) {}}function openEditorContextMenu(){  // if we have a mispelled word, do one thing, otherwise show the usual context menu  var spellCheckNoSuggestionsItem = document.getElementById('spellCheckNoSuggestions');  var word;  var misspelledWordStatus = InlineSpellChecker.updateSuggestionsMenu(document.getElementById('msgComposeContext'), spellCheckNoSuggestionsItem,                              word);    var hideSpellingItems = (misspelledWordStatus == kSpellNoMispelling);  spellCheckNoSuggestionsItem.hidden = hideSpellingItems || misspelledWordStatus != kSpellNoSuggestionsFound;  document.getElementById('spellCheckAddToDictionary').hidden = hideSpellingItems;  document.getElementById('spellCheckIgnoreWord').hidden = hideSpellingItems;  document.getElementById('spellCheckAddSep').hidden = hideSpellingItems;  document.getElementById('spellCheckSuggestionsSeparator').hidden = hideSpellingItems;  updateEditItems();}function updateEditItems(){  goUpdateCommand("cmd_pasteNoFormatting");  goUpdateCommand("cmd_pasteQuote");  goUpdateCommand("cmd_delete");  goUpdateCommand("cmd_selectAll");  goUpdateCommand("cmd_openAttachment");  goUpdateCommand("cmd_find");  goUpdateCommand("cmd_findNext");  goUpdateCommand("cmd_findPrev");}var messageComposeOfflineObserver = {  observe: function(subject, topic, state)   {    // sanity checks    if (topic != "network:offline-status-changed")       return;    gIsOffline = state == "offline";    MessageComposeOfflineStateChanged(gIsOffline);    try {        setupLdapAutocompleteSession();    } catch (ex) {        // catch the exception and ignore it, so that if LDAP setup         // fails, the entire compose window stuff doesn't get aborted    }  }}function AddMessageComposeOfflineObserver(){  var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);  observerService.addObserver(messageComposeOfflineObserver, "network:offline-status-changed", false);    gIsOffline = gIOService.offline;  // set the initial state of the send button  MessageComposeOfflineStateChanged(gIsOffline);}function RemoveMessageComposeOfflineObserver(){  var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);  observerService.removeObserver(messageComposeOfflineObserver,"network:offline-status-changed");}function MessageComposeOfflineStateChanged(goingOffline){  try {    var sendButton = document.getElementById("button-send");    var sendNowMenuItem = document.getElementById("menu-item-send-now");    if (!gSavedSendNowKey) {      gSavedSendNowKey = sendNowMenuItem.getAttribute('key');    }    // don't use goUpdateCommand here ... the defaultController might not be installed yet    goSetCommandEnabled("cmd_sendNow", defaultController.isCommandEnabled("cmd_sendNow"));    if (goingOffline)    {      sendButton.label = sendButton.getAttribute('later_label');      sendButton.setAttribute('tooltiptext', sendButton.getAttribute('later_tooltiptext'));      sendNowMenuItem.removeAttribute('key');    }    else    {      sendButton.label = sendButton.getAttribute('now_label');      sendButton.setAttribute('tooltiptext', sendButton.getAttribute('now_tooltiptext'));      if (gSavedSendNowKey) {        sendNowMenuItem.setAttribute('key', gSavedSendNowKey);      }    }  } catch(e) {}}var directoryServerObserver = {  observe: function(subject, topic, value) {      try {          setupLdapAutocompleteSession();      } catch (ex) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?