abcommon.js
来自「现在很火的邮件客户端软件thunderbird的源码」· JavaScript 代码 · 共 1,318 行 · 第 1/3 页
JS
1,318 行
# ***** 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 Addressbook.## The Initial Developer of the Original Code is# Netscape Communications Corp.# Portions created by the Initial Developer are Copyright (C) 1999-2001# the Initial Developer. All Rights Reserved.## Original Author:# Paul Hangas <hangas@netscape.com>## Contributor(s):# Seth Spitzer <sspitzer@netscape.com># Mark Banner <mark@standard8.demon.co.uk>## 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 *****var dirTree = 0;var abList = 0;var gAbResultsTree = null;var gAbView = null;var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);var gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);var gHeaderParser = Components.classes["@mozilla.org/messenger/headerparser;1"].getService(Components.interfaces.nsIMsgHeaderParser);const kDefaultSortColumn = "GeneratedName";const kDefaultAscending = "ascending";const kDefaultDescending = "descending";const kPersonalAddressbookURI = "moz-abmdbdirectory://abook.mab";const kCollectedAddressbookURI = "moz-abmdbdirectory://history.mab";// List/card selections in the results pane.const kNothingSelected = 0;const kListsAndCards = 1;const kMultipleListsOnly = 2;const kSingleListOnly = 3;const kCardsOnly = 4;// Controller object for Results Panevar ResultsPaneController ={ supportsCommand: function(command) { switch (command) { case "cmd_selectAll": case "cmd_delete": case "button_delete": case "button_edit": case "cmd_printcard": case "cmd_printcardpreview": return true; default: return false; } }, isCommandEnabled: function(command) { switch (command) { case "cmd_selectAll": return true; case "cmd_delete": case "button_delete": var numSelected; var enabled = false; if (gAbView && gAbView.selection) { if (gAbView.directory) enabled = gAbView.directory.operations & gAbView.directory.opWrite; numSelected = gAbView.selection.count; } else numSelected = 0; // fix me, don't update on isCommandEnabled if (command == "cmd_delete") { if (numSelected < 2) goSetMenuValue(command, "valueCard"); else goSetMenuValue(command, "valueCards"); } return (enabled && (numSelected > 0)); case "cmd_printcard": case "cmd_printcardpreview": case "button_edit": return (GetSelectedCardIndex() != -1); default: return false; } }, doCommand: function(command) { switch (command) { case "cmd_selectAll": if (gAbView) gAbView.selectAll(); break; case "cmd_delete": case "button_delete": AbDelete(); break; case "button_edit": AbEditSelectedCard(); break; case "cmd_printcard": AbPrintCard(); break; case "cmd_printcardpreview": AbPrintPreviewCard(); break; } }, onEvent: function(event) { // on blur events set the menu item texts back to the normal values if (event == "blur") goSetMenuValue("cmd_delete", "valueDefault"); }};// Controller object for Dir Panevar DirPaneController ={ supportsCommand: function(command) { switch (command) { case "cmd_selectAll": case "cmd_delete": case "button_delete": case "button_edit": case "cmd_printcard": case "cmd_printcardpreview": return true; default: return false; } }, isCommandEnabled: function(command) { var selectedDir; switch (command) { case "cmd_selectAll": // the dirTree pane // only handles single selection // so we forward select all to the results pane // but if there is no gAbView // don't bother sending to the results pane return (gAbView != null); case "cmd_delete": case "button_delete": if (command == "cmd_delete") goSetMenuValue(command, "valueAddressBook"); selectedDir = GetSelectedDirectory(); if (selectedDir == kPersonalAddressbookURI || selectedDir == kCollectedAddressbookURI) return false; if (selectedDir) { // If the selected directory is an ldap directory // and if the prefs for this directory are locked // disable the delete button. var ldapUrlPrefix = "moz-abldapdirectory://"; if ((selectedDir.indexOf(ldapUrlPrefix, 0)) == 0) { var prefName = selectedDir.substr(ldapUrlPrefix.length, selectedDir.length); var disable = false; try { disable = gPrefs.getBoolPref(prefName + ".disable_delete"); } catch(ex){ // if this preference is not set its ok. } if (disable) return false; } return true; } else return false; case "cmd_printcard": case "cmd_printcardpreview": return (GetSelectedCardIndex() != -1); case "button_edit": return (GetSelectedDirectory() != null); default: return false; } }, doCommand: function(command) { switch (command) { case "cmd_printcard": case "cmd_printcardpreview": case "cmd_selectAll": SendCommandToResultsPane(command); break; case "cmd_delete": case "button_delete": if (dirTree) AbDeleteDirectory(); break; case "button_edit": AbEditSelectedDirectory(); break; } }, onEvent: function(event) { // on blur events set the menu item texts back to the normal values if (event == "blur") goSetMenuValue("cmd_delete", "valueDefault"); }};function SendCommandToResultsPane(command){ ResultsPaneController.doCommand(command); // if we are sending the command so the results pane // we should focus the results pane gAbResultsTree.focus();}function AbEditSelectedDirectory(){ if (dirTree.view.selection.count == 1) { var selecteduri = GetSelectedDirectory(); var directory = GetDirectoryFromURI(selecteduri); if (directory.isMailList) { var dirUri = GetParentDirectoryFromMailingListURI(selecteduri); goEditListDialog(dirUri, null, selecteduri, UpdateCardView); } else { var properties = directory.directoryProperties; if (properties.dirType == kLDAPDirectory) { var ldapUrlPrefix = "moz-abldapdirectory://"; var args = { selectedDirectory: directory.dirName, selectedDirectoryString: null}; args.selectedDirectoryString = selecteduri.substr(ldapUrlPrefix.length, selecteduri.length); window.openDialog("chrome://messenger/content/addressbook/pref-directory-add.xul", "editDirectory", "chrome,modal=yes,resizable=no,centerscreen", args); } else { AbRenameAddressBook(); } } }}function GetParentRow(aTree, aRow){ var row = aRow; var level = aTree.view.getLevel(row); var parentLevel = level; while (parentLevel >= level) { row--; if (row == -1) return row; parentLevel = aTree.view.getLevel(row); } return row;} function InitCommonJS(){ dirTree = document.getElementById("dirTree"); abList = document.getElementById("addressbookList"); gAbResultsTree = document.getElementById("abResultsTree");}function SetupAbCommandUpdateHandlers(){ // dir pane if (dirTree) dirTree.controllers.appendController(DirPaneController); // results pane if (gAbResultsTree) gAbResultsTree.controllers.appendController(ResultsPaneController);}function GetSelectedCardTypes(){ var cards = GetSelectedAbCards(); if (!cards) return kNothingSelected; // no view var count = cards.length; if (!count) return kNothingSelected; // nothing selected var mailingListCnt = 0; var cardCnt = 0; for (var i = 0; i < count; i++) { if (cards[i].isMailList) mailingListCnt++; else cardCnt++; } if (mailingListCnt && cardCnt) return kListsAndCards; // lists and cards selected else if (mailingListCnt && !cardCnt) { if (mailingListCnt > 1) return kMultipleListsOnly; // only multiple mailing lists selected else return kSingleListOnly; // only single mailing list } else if (!mailingListCnt && cardCnt) return kCardsOnly; // only card(s) selected}function AbDelete(){ var types = GetSelectedCardTypes(); if (types == kNothingSelected) return; var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); // If at least one mailing list is selected then prompt users for deletion. if (types != kCardsOnly) { var confirmDeleteMessage; if (types == kListsAndCards) confirmDeleteMessage = gAddressBookBundle.getString("confirmDeleteListsAndCards"); else if (types == kMultipleListsOnly) confirmDeleteMessage = gAddressBookBundle.getString("confirmDeleteMailingLists"); else confirmDeleteMessage = gAddressBookBundle.getString("confirmDeleteMailingList"); if (!promptService.confirm(window, null, confirmDeleteMessage)) return; } gAbView.deleteSelectedCards();}function AbNewCard(abListItem){ goNewCardDialog(GetSelectedDirectory());}// NOTE, will return -1 if more than one card selected, or no cards selected.function GetSelectedCardIndex(){ if (!gAbView) return -1; var treeSelection = gAbView.selection; if (treeSelection.getRangeCount() == 1) { var start = new Object; var end = new Object; treeSelection.getRangeAt(0,start,end); if (start.value == end.value) return start.value; } return -1;}// NOTE, returns the card if exactly one card is selected, null otherwisefunction GetSelectedCard(){ var index = GetSelectedCardIndex(); if (index == -1) return null; else return gAbView.getCardFromRow(index);}function AbEditSelectedCard(){ AbEditCard(GetSelectedCard());}function AbEditCard(card){ if (!card) return; // Not allowing AOL special groups to be edited. if (card.isASpecialGroup) return; if (card.isMailList) { goEditListDialog(GetSelectedDirectory(), card, card.mailListURI, UpdateCardView); } else { goEditCardDialog(GetSelectedDirectory(), card, UpdateCardView); }}function AbNewMessage(){ var msgComposeType = Components.interfaces.nsIMsgCompType; var msgComposFormat = Components.interfaces.nsIMsgCompFormat; var msgComposeService = Components.classes["@mozilla.org/messengercompose;1"].getService(); msgComposeService = msgComposeService.QueryInterface(Components.interfaces.nsIMsgComposeService); var params = Components.classes["@mozilla.org/messengercompose/composeparams;1"].createInstance(Components.interfaces.nsIMsgComposeParams); if (params) { params.type = msgComposeType.New; params.format = msgComposFormat.Default; var composeFields = Components.classes["@mozilla.org/messengercompose/composefields;1"].createInstance(Components.interfaces.nsIMsgCompFields); if (composeFields) { if (DirPaneHasFocus()) composeFields.to = GetSelectedAddressesFromDirTree();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?