msgmail3panewindow.js

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

JS
1,852
字号
# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-# ***** BEGIN LICENSE BLOCK *****# Version: MPL 1.1/GPL 2.0/LGPL 2.1## The contents of this file are subject to the Mozilla Public License Version# 1.1 (the "License"); you may not use this file except in compliance with# the License. You may obtain a copy of the License at# http://www.mozilla.org/MPL/## Software distributed under the License is distributed on an "AS IS" basis,# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License# for the specific language governing rights and limitations under the# License.## The Original Code is Mozilla Communicator client code, released# March 31, 1998.## The Initial Developer of the Original Code is# Netscape Communications Corporation.# Portions created by the Initial Developer are Copyright (C) 1998-1999# the Initial Developer. All Rights Reserved.## Contributor(s):#   Jan Varga (varga@nixcorp.com)#   H錵an Waara (hwaara@chello.se)#   Neil Rashbrook (neil@parkwaycc.co.uk)#   Seth Spitzer <sspitzer@netscape.com>#   David Bienvenu <bienvenu@nventure.com>## Alternatively, the contents of this file may be used under the terms of# either the GNU General Public License Version 2 or later (the "GPL"), or# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),# in which case the provisions of the GPL or the LGPL are applicable instead# of those above. If you wish to allow use of your version of this file only# under the terms of either the GPL or the LGPL, and not to allow others to# use your version of this file under the terms of the MPL, indicate your# decision by deleting the provisions above and replace them with the notice# and other provisions required by the GPL or the LGPL. If you do not delete# the provisions above, a recipient may use your version of this file under# the terms of any one of the MPL, the GPL or the LGPL.## ***** END LICENSE BLOCK *****/* This is where functions related to the 3 pane window are kept */// from MailNewsTypes.hconst nsMsgKey_None = 0xFFFFFFFF;const nsMsgViewIndex_None = 0xFFFFFFFF;const kMailCheckOncePrefName = "mail.startup.enabledMailCheckOnce";const kStandardPaneConfig = 0;const kWidePaneConfig = 1;const kVerticalPaneConfig = 2;const kWideThreadPaneConfig = 3;const kNumFolderViews = 4; // total number of folder views// from nsMsgFolderFlags.hconst MSG_FOLDER_FLAG_ELIDED = 0x10;var gFolderTree; var gMessagePane;var gThreadTree;var gSearchInput;var gThreadAndMessagePaneSplitter = null;var gUnreadCount = null;var gTotalCount = null;var gCurrentPaneConfig = 0;var gCurrentFolderView;  var gCurrentLoadingFolderURI;var gCurrentFolderToReroot;var gCurrentLoadingFolderSortType = 0;var gCurrentLoadingFolderSortOrder = 0;var gCurrentLoadingFolderViewType = 0;var gCurrentLoadingFolderViewFlags = 0;var gRerootOnFolderLoad = false;var gNextMessageAfterDelete = null;var gNextMessageAfterLoad = null;var gNextMessageViewIndexAfterDelete = -2;var gSelectedIndexWhenDeleting = -1;var gCurrentlyDisplayedMessage=nsMsgViewIndex_None;var gStartFolderUri = null;var gStartMsgKey = nsMsgKey_None;var gSearchEmailAddress = null;var gRightMouseButtonDown = false;// Global var to keep track of which row in the thread pane has been selected// This is used to make sure that the row with the currentIndex has the selection// after a Delete or Move of a message that has a row index less than currentIndex.var gThreadPaneCurrentSelectedIndex = -1;var gLoadStartFolder = true;var gNewAccountToLoad = null;// Global var to keep track of if the 'Delete Message' or 'Move To' thread pane// context menu item was triggered.  This helps prevent the tree view from// not updating on one of those menu item commands.var gThreadPaneDeleteOrMoveOccurred = false;//If we've loaded a message, set to true.  Helps us keep the start page around.var gHaveLoadedMessage;var gDisplayStartupPage = false;var gNotifyDefaultInboxLoadedOnStartup = false;function SelectAndScrollToKey(aMsgKey){  // select the desired message  // if the key isn't found, we won't select anything  gDBView.selectMsgByKey(aMsgKey);    // is there a selection?  // if not, bail out.  var indicies = GetSelectedIndices(gDBView);  if (!indicies || !indicies.length)    return false;  // now scroll to it  EnsureRowInThreadTreeIsVisible(indicies[0]);  return true;}// A helper routine called after a folder is loaded to make sure// we select and scroll to the correct message (could be the first new message,// could be the last displayed message, etc.)// returns true if we ended up scrolling to a messagefunction ScrollToMessageAfterFolderLoad (folder){  var scrolled = pref.getBoolPref("mailnews.scroll_to_new_message") &&      ScrollToMessage(nsMsgNavigationType.firstNew, true, false /* selectMessage */);  if (!scrolled && folder && pref.getBoolPref("mailnews.remember_selected_message"))   {    // if we failed to scroll to a new message,    // reselect the last selected message    var lastMessageLoaded = folder.lastMessageLoaded;    if (lastMessageLoaded != nsMsgKey_None)      scrolled = SelectAndScrollToKey(lastMessageLoaded);  }    if (!scrolled)   {    // if we still haven't scrolled,    // scroll to the newest, which might be the top or the bottom    // depending on our sort order and sort type    if (gDBView.sortOrder == nsMsgViewSortOrder.ascending)     {      switch (gDBView.sortType)       {        case nsMsgViewSortType.byDate:         case nsMsgViewSortType.byId:         case nsMsgViewSortType.byThread:          scrolled = ScrollToMessage(nsMsgNavigationType.lastMessage, true, false /* selectMessage */);         break;      }    }          // if still we haven't scrolled,    // scroll to the top.    if (!scrolled)      EnsureRowInThreadTreeIsVisible(0);  }       return scrolled;}// the folderListener objectvar folderListener = {    OnItemAdded: function(parentItem, item) { },    OnItemRemoved: function(parentItem, item) { },    OnItemPropertyChanged: function(item, property, oldValue, newValue) { },    OnItemIntPropertyChanged: function(item, property, oldValue, newValue) {      if (item == gMsgFolderSelected) {        if(property.toString() == "TotalMessages" || property.toString() == "TotalUnreadMessages") {          UpdateStatusMessageCounts(gMsgFolderSelected);          UpdateFolderLocationPicker(item);        }            }    },    OnItemBoolPropertyChanged: function(item, property, oldValue, newValue) { },    OnItemUnicharPropertyChanged: function(item, property, oldValue, newValue) { },    OnItemPropertyFlagChanged: function(item, property, oldFlag, newFlag) { },    OnItemEvent: function(folder, event) {       var eventType = event.toString();       if (eventType == "FolderLoaded") {         if (folder) {           var msgFolder = folder.QueryInterface(Components.interfaces.nsIMsgFolder);           var uri = folder.URI;           var rerootingFolder = (uri == gCurrentFolderToReroot);           if (rerootingFolder) {             viewDebug("uri = gCurrentFolderToReroot, setting gQSViewIsDirty\n");             gQSViewIsDirty = true;             gCurrentFolderToReroot = null;             if(msgFolder) {               msgFolder.endFolderLoading();               UpdateStatusQuota(msgFolder);               // suppress command updating when rerooting the folder               // when rerooting, we'll be clearing the selection               // which will cause us to update commands.               if (gDBView) {                 gDBView.suppressCommandUpdating = true;                 // if the db's view isn't set, something went wrong and we should reroot                 // the folder, which will re-open the view.                 if (!gDBView.db)                   gRerootOnFolderLoad = true;               }               if (gRerootOnFolderLoad)                 RerootFolder(uri, msgFolder, gCurrentLoadingFolderViewType, gCurrentLoadingFolderViewFlags, gCurrentLoadingFolderSortType, gCurrentLoadingFolderSortOrder);               var db = msgFolder.getMsgDatabase(msgWindow);               if (db)                  db.resetHdrCacheSize(100);                                if (gDBView) {                 gDBView.suppressCommandUpdating = false;               }               gCurrentLoadingFolderSortType = 0;               gCurrentLoadingFolderSortOrder = 0;               gCurrentLoadingFolderViewType = 0;               gCurrentLoadingFolderViewFlags = 0;               var scrolled = false;               LoadCurrentlyDisplayedMessage();  //used for rename folder msg loading after folder is loaded.               if (gStartMsgKey != nsMsgKey_None) {                 scrolled = SelectAndScrollToKey(gStartMsgKey);                 gStartMsgKey = nsMsgKey_None;               }               if (gNextMessageAfterLoad) {                 var type = gNextMessageAfterLoad;                 gNextMessageAfterLoad = null;                 // scroll to and select the proper message                 scrolled = ScrollToMessage(type, true, true /* selectMessage */);               }             }           }           if (uri == gCurrentLoadingFolderURI) {             viewDebug("uri == current loading folder uri\n");             gCurrentLoadingFolderURI = "";             scrolled = ScrollToMessageAfterFolderLoad(msgFolder);                SetBusyCursor(window, false);           }           if (gNotifyDefaultInboxLoadedOnStartup && (folder.flags & 0x1000))           {              var defaultAccount = accountManager.defaultAccount;              defaultServer = defaultAccount.incomingServer;              var inboxFolder = GetInboxFolder(defaultServer);              if (inboxFolder && inboxFolder.URI == folder.URI)              {                NotifyObservers(null,"defaultInboxLoadedOnStartup",null);                gNotifyDefaultInboxLoadedOnStartup = false;              }           }           //folder loading is over, now issue quick search if there is an email address           viewDebug("in folder loaded gVirtualFolderTerms = " + gVirtualFolderTerms + "\n");           viewDebug("in folder loaded gMsgFolderSelected = " + gMsgFolderSelected.URI + "\n");           if (rerootingFolder)           {             if (gSearchEmailAddress)             {               Search(gSearchEmailAddress);               gSearchEmailAddress = null;             }              else if (gVirtualFolderTerms)             {                gDefaultSearchViewTerms = null;                viewDebug("searching gVirtualFolderTerms\n");                gDBView.viewFolder = gMsgFolderSelected;                ViewChangeByFolder(gMsgFolderSelected);             }             else if (gMsgFolderSelected.flags & MSG_FOLDER_FLAG_VIRTUAL)             {                viewDebug("selected folder is virtual\n");                gDefaultSearchViewTerms = null;             }             else             {                              // get the view value from the folder               if (msgFolder)               {                 // if our new view is the same as the old view and we already have the list of search terms built up                 // for the old view, just re-use it                 var result = GetMailViewForFolder(msgFolder);                 if (GetSearchInput() && gCurrentViewValue == result && gDefaultSearchViewTerms)                 {                   viewDebug("searching gDefaultSearchViewTerms and rerootingFolder\n");                   Search("");                 }                 else if (document.getElementById("mailviews-container")) // only load the folder view if the views toolbar is visible                 {                   viewDebug("changing view by value\n");                   ViewChangeByValue(result);                 }               }             }           }         }       }        else if (eventType == "ImapHdrDownloaded") {         if (folder) {           var imapFolder = folder.QueryInterface(Components.interfaces.nsIMsgImapMailFolder);           if (imapFolder) {            var hdrParser = imapFolder.hdrParser;            if (hdrParser) {              var msgHdr = hdrParser.GetNewMsgHdr();              if (msgHdr)              {                var hdrs = hdrParser.headers;                if (hdrs && hdrs.indexOf("X-attachment-size:") > 0) {                  msgHdr.OrFlags(0x10000000);  // 0x10000000 is MSG_FLAG_ATTACHMENT                }                if (hdrs && hdrs.indexOf("X-image-size:") > 0) {                  msgHdr.setStringProperty("imageSize", "1");                }              }            }           }         }       }       else if (eventType == "DeleteOrMoveMsgCompleted") {         HandleDeleteOrMoveMsgCompleted(folder);       }            else if (eventType == "DeleteOrMoveMsgFailed") {         HandleDeleteOrMoveMsgFailed(folder);       }       else if (eventType == "AboutToCompact") {        if (gDBView)          gCurrentlyDisplayedMessage = gDBView.currentlyDisplayedMessage;       }       else if (eventType == "CompactCompleted") {         HandleCompactCompleted(folder);       }       else if (eventType == "RenameCompleted") {         SelectFolder(folder.URI);       }       else if (eventType == "JunkStatusChanged") {         HandleJunkStatusChanged(folder);       }    }}var folderObserver = {    canDrop: function(index, orientation)    {        return CanDropOnFolderTree(index, orientation);    },    onDrop: function(row, orientation)    {        DropOnFolderTree(row, orientation);    },    onToggleOpenState: function(index)    {      var folderTree = GetFolderTree();      // Nothing to do when collapsing an item.      if (folderTree.view.isContainerOpen(index))        return;

⌨️ 快捷键说明

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