?? commandglue.js
字號:
# -*- Mode: C++; 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)# 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 *****/* * Command-specific code. This stuff should be called by the widgets *///NOTE: gMessengerBundle and gBrandBundle must be defined and set// for this Overlay to work properlyvar gFolderJustSwitched = false;var gBeforeFolderLoadTime;var gRDFNamespace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";var gVirtualFolderTerms;var gXFVirtualFolderTerms;var gCurrentVirtualFolderUri;var gPrevFolderFlags;var gPrevSelectedFolder;var gMsgFolderSelected;/* keep in sync with nsMsgFolderFlags.h */var MSG_FOLDER_FLAG_VIRTUAL = 0x0020;var MSG_FOLDER_FLAG_TRASH = 0x0100;var MSG_FOLDER_FLAG_SENTMAIL = 0x0200;var MSG_FOLDER_FLAG_DRAFTS = 0x0400;var MSG_FOLDER_FLAG_QUEUE = 0x0800;var MSG_FOLDER_FLAG_INBOX = 0x1000;var MSG_FOLDER_FLAG_TEMPLATES = 0x400000;var MSG_FOLDER_FLAG_JUNK = 0x40000000;var MSG_FOLDER_FLAG_FAVORITE = 0x80000000;function GetMsgFolderFromResource(folderResource){ if (!folderResource) return null; var msgFolder = folderResource.QueryInterface(Components.interfaces.nsIMsgFolder); if (msgFolder && (msgFolder.parent || msgFolder.isServer)) return msgFolder; else return null;}function GetServer(uri){ if (!uri) return null; try { var folder = GetMsgFolderFromUri(uri, true); return folder.server; } catch (ex) { dump("GetServer("+uri+") failed, ex="+ex+"\n"); } return null;}function setTitleFromFolder(msgfolder, subject){ var wintype = document.firstChild.getAttribute('windowtype'); var title; // If we are showing the mail:3pane. Never include the subject of the selected // message in the title. ("Inbox for greenlantern@mozilla.org - Mozilla Thunderbird") // If we are a stand alone message window, we should show the Subject // and the product but not the account name: "Re: New window Title - Mozilla Thunderbird" if (wintype == "mail:messageWindow") title = subject ? subject : ""; else if (msgfolder) { title = msgfolder.prettyName; if (!msgfolder.isServer) { var server = msgfolder.server; var middle; var end; if (server.type == "nntp") { // <folder> on <hostname> middle = gMessengerBundle.getString("titleNewsPreHost"); end = server.hostName; } else { var identity; try { var identities = accountManager.GetIdentitiesForServer(server); identity = identities.QueryElementAt(0, Components.interfaces.nsIMsgIdentity); // <folder> for <email> middle = gMessengerBundle.getString("titleMailPreHost"); end = identity.email; } catch (ex) {} } if (middle) title += " " + middle; if (end) title += " " + end; } }#ifndef XP_MACOSX title += " - " + gBrandBundle.getString("brandShortName");#endif document.title = title;}function UpdateMailToolbar(caller){ //dump("XXX update mail-toolbar " + caller + "\n"); document.commandDispatcher.updateCommands('mail-toolbar'); // hook for extra toolbar items var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); observerService.notifyObservers(window, "mail:updateToolbarItems", null);}function ChangeFolderByURI(uri, viewType, viewFlags, sortType, sortOrder){ viewDebug("In ChangeFolderByURI uri = " + uri + " sortType = " + sortType + "\n"); if (uri == gCurrentLoadingFolderURI) return; // hook for extra toolbar items var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); observerService.notifyObservers(window, "mail:setupToolbarItems", uri); var resource = RDF.GetResource(uri); var msgfolder = resource.QueryInterface(Components.interfaces.nsIMsgFolder); try { setTitleFromFolder(msgfolder, null); } catch (ex) { dump("error setting title: " + ex + "\n"); } //if it's a server, clear the threadpane and don't bother trying to load. if(msgfolder.isServer) { msgWindow.openFolder = null; ClearThreadPane(); UpdateStatusQuota(null); // Load AccountCentral page here. ShowAccountCentral(); return; } else { if (msgfolder.server.displayStartupPage) { gDisplayStartupPage = true; msgfolder.server.displayStartupPage = false; } } // If the user clicks on msgfolder, time to display thread pane and message pane. ShowThreadPane(); gCurrentLoadingFolderURI = uri; gNextMessageAfterDelete = null; // forget what message to select, if any gCurrentFolderToReroot = uri; gCurrentLoadingFolderViewFlags = viewFlags; gCurrentLoadingFolderViewType = viewType; gCurrentLoadingFolderSortType = sortType; gCurrentLoadingFolderSortOrder = sortOrder; var showMessagesAfterLoading; try { var server = msgfolder.server; if (gPrefBranch.getBoolPref("mail.password_protect_local_cache")) { showMessagesAfterLoading = server.passwordPromptRequired; // servers w/o passwords (like local mail) will always be non-authenticated. // So we need to use the account manager for that case. } else if (server.redirectorType) { var prefString = server.type + "." + server.redirectorType + ".showMessagesAfterLoading"; showMessagesAfterLoading = gPrefBranch.getBoolPref(prefString); } else showMessagesAfterLoading = false; } catch (ex) { showMessagesAfterLoading = false; } if (viewType != nsMsgViewType.eShowVirtualFolderResults && (msgfolder.manyHeadersToDownload || showMessagesAfterLoading)) { gRerootOnFolderLoad = true; try { ClearThreadPane(); SetBusyCursor(window, true); msgfolder.startFolderLoading(); msgfolder.updateFolder(msgWindow); } catch(ex) { SetBusyCursor(window, false); dump("Error loading with many headers to download: " + ex + "\n"); } } else { if (viewType != nsMsgViewType.eShowVirtualFolderResults) SetBusyCursor(window, true); RerootFolder(uri, msgfolder, viewType, viewFlags, sortType, sortOrder); gRerootOnFolderLoad = false; msgfolder.startFolderLoading(); //Need to do this after rerooting folder. Otherwise possibility of receiving folder loaded //notification before folder has actually changed. if (viewType != nsMsgViewType.eShowVirtualFolderResults) msgfolder.updateFolder(msgWindow); }}function isNewsURI(uri){ if (!uri || uri[0] != 'n') { return false; } else { return ((uri.substring(0,6) == "news:/") || (uri.substring(0,14) == "news-message:/")); }}function RerootFolder(uri, newFolder, viewType, viewFlags, sortType, sortOrder){ viewDebug("In reroot folder, sortType = " + sortType + "viewType = " + viewType + "\n"); if (sortType == 0) { try { var msgdb = newFolder.getMsgDatabase(msgWindow); var dbFolderInfo = msgdb.dBFolderInfo; sortType = dbFolderInfo.sortType; sortOrder = dbFolderInfo.sortOrder; viewFlags = dbFolderInfo.viewFlags; viewType = dbFolderInfo.viewType; dbFolderInfo = null; } catch(ex) { dump("invalid db in RerootFolder: " + ex + "\n"); } } // workaround for #39655 gFolderJustSwitched = true; ClearThreadPaneSelection(); //Clear the new messages of the old folder var oldFolder = gPrevSelectedFolder; if (oldFolder) { oldFolder.clearNewMessages(); oldFolder.hasNewMessages = false; } //Set the window's new open folder. msgWindow.openFolder = newFolder; //the new folder being selected should have its biff state get cleared. if(newFolder) { newFolder.biffState = Components.interfaces.nsIMsgFolder.nsMsgBiffState_NoMail; } //Clear out the thread pane so that we can sort it with the new sort id without taking any time. // folder.setAttribute('ref', ""); // null this out, so we don't try sort. if (gDBView) { gDBView.close(); gDBView = null; } // cancel the pending mark as read timer ClearPendingReadTimer(); // if this is the drafts, sent, or send later folder, // we show "Recipient" instead of "Author" SetSentFolderColumns(IsSpecialFolder(newFolder, MSG_FOLDER_FLAG_SENTMAIL | MSG_FOLDER_FLAG_DRAFTS | MSG_FOLDER_FLAG_QUEUE, true)); ShowLocationColumn(viewType == nsMsgViewType.eShowVirtualFolderResults); // now create the db view, which will sort it. CreateDBView(newFolder, viewType, viewFlags, sortType, sortOrder); if (oldFolder) { /*we don't null out the db reference for inbox because inbox is like the "main" folder and performance outweighs footprint */ if (!IsSpecialFolder(oldFolder, MSG_FOLDER_FLAG_INBOX, false)) { if (oldFolder.URI != newFolder.URI) oldFolder.setMsgDatabase(null); } } // that should have initialized gDBView, now re-root the thread pane RerootThreadPane(); SetUpToolbarButtons(uri); UpdateFolderLocationPicker(gMsgFolderSelected); UpdateStatusMessageCounts(gMsgFolderSelected); // hook for extra toolbar items var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); observerService.notifyObservers(window, "mail:updateToolbarItems", null); // this is to kick off cross-folder searches for virtual folders. if (gSearchSession && !gVirtualFolderTerms) // another var might be better... { viewDebug("doing a xf folder search in rerootFolder\n"); ViewChangeByFolder(newFolder); gPreQuickSearchView = null; // don't remember the cross folder search ScrollToMessageAfterFolderLoad(newFolder); }}function SwitchView(command){ // when switching thread views, we might be coming out of quick search // or a message view. // first set view picker to all ViewChangeByValue(kViewItemAll); // clear the QS text, if we need to ClearQSIfNecessary(); // now switch views var oldSortType = gDBView ? gDBView.sortType : nsMsgViewSortType.byThread; var oldSortOrder = gDBView ? gDBView.sortOrder : nsMsgViewSortOrder.ascending; var viewFlags = gDBView ? gDBView.viewFlags : gCurViewFlags; // close existing view. if (gDBView) { gDBView.close(); gDBView = null; } switch(command) { case "cmd_viewUnreadMsgs": viewFlags = viewFlags | nsMsgViewFlagsType.kUnreadOnly; CreateDBView(msgWindow.openFolder, nsMsgViewType.eShowAllThreads, viewFlags, oldSortType, oldSortOrder ); break; case "cmd_viewAllMsgs": viewFlags = viewFlags & ~nsMsgViewFlagsType.kUnreadOnly; CreateDBView(msgWindow.openFolder, nsMsgViewType.eShowAllThreads, viewFlags, oldSortType, oldSortOrder); break; case "cmd_viewThreadsWithUnread": CreateDBView(msgWindow.openFolder, nsMsgViewType.eShowThreadsWithUnread, nsMsgViewFlagsType.kThreadedDisplay, nsMsgViewSortType.byThread, oldSortOrder); break; case "cmd_viewWatchedThreadsWithUnread": CreateDBView(msgWindow.openFolder, nsMsgViewType.eShowWatchedThreadsWithUnread, nsMsgViewFlagsType.kThreadedDisplay, nsMsgViewSortType.byThread, oldSortOrder); break; case "cmd_viewIgnoredThreads": if (viewFlags & nsMsgViewFlagsType.kShowIgnored) viewFlags = viewFlags & ~nsMsgViewFlagsType.kShowIgnored; else viewFlags = viewFlags | nsMsgViewFlagsType.kShowIgnored; CreateDBView(msgWindow.openFolder, nsMsgViewType.eShowAllThreads, viewFlags, oldSortType, oldSortOrder); break; } RerootThreadPane();}function SetSentFolderColumns(isSentFolder)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -