From 8329de6c2e2b2550d6f9afbd7d2967a6078598b5 Mon Sep 17 00:00:00 2001 From: "technutz%netscape.net" Date: Tue, 11 Nov 2003 02:56:36 +0000 Subject: [PATCH] Bug 73801. Disable the delete menu item, context menu item and button when either a Collected or Personal address book is selected. r=neil, sr=bienvenu --- .../addrbook/resources/content/abCommon.js | 2 + .../addrbook/resources/content/addressbook.js | 109 ++++++++---------- .../resources/content/addressbook.xul | 2 +- .../locale/en-US/addressBook.properties | 1 - 4 files changed, 48 insertions(+), 66 deletions(-) diff --git a/mailnews/addrbook/resources/content/abCommon.js b/mailnews/addrbook/resources/content/abCommon.js index 6d591328333..e7e64e3f08e 100644 --- a/mailnews/addrbook/resources/content/abCommon.js +++ b/mailnews/addrbook/resources/content/abCommon.js @@ -168,6 +168,8 @@ var DirPaneController = 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 diff --git a/mailnews/addrbook/resources/content/addressbook.js b/mailnews/addrbook/resources/content/addressbook.js index 3b2e70574ff..90be30601ff 100644 --- a/mailnews/addrbook/resources/content/addressbook.js +++ b/mailnews/addrbook/resources/content/addressbook.js @@ -239,7 +239,8 @@ function SetNameColumn(cmd) function CommandUpdate_AddressBook() { - goUpdateCommand('button_delete'); + goUpdateCommand('cmd_delete'); + goUpdateCommand('button_delete'); } function ResultsPaneSelectionChanged() @@ -401,35 +402,36 @@ function AbPrintCardInternal(doPrintPreview, msgType) if (!uri) return; - var statusFeedback; - statusFeedback = Components.classes["@mozilla.org/messenger/statusfeedback;1"].createInstance(); - statusFeedback = statusFeedback.QueryInterface(Components.interfaces.nsIMsgStatusFeedback); + var statusFeedback; + statusFeedback = Components.classes["@mozilla.org/messenger/statusfeedback;1"].createInstance(); + statusFeedback = statusFeedback.QueryInterface(Components.interfaces.nsIMsgStatusFeedback); - var selectionArray = new Array(numSelected); + var selectionArray = new Array(numSelected); - var totalCard = 0; + var totalCard = 0; - for(var i = 0; i < numSelected; i++) - { - var card = selectedItems[i]; - var printCardUrl = CreatePrintCardUrl(card); - if (printCardUrl) - { - selectionArray[totalCard++] = printCardUrl; - } - } + for (var i = 0; i < numSelected; i++) + { + var card = selectedItems[i]; + var printCardUrl = CreatePrintCardUrl(card); + if (printCardUrl) + { + selectionArray[totalCard++] = printCardUrl; + } + } - if (!gPrintSettings) { + if (!gPrintSettings) + { gPrintSettings = GetPrintSettings(); } - printEngineWindow = window.openDialog("chrome://messenger/content/msgPrintEngine.xul", - "", - "chrome,dialog=no,all", - totalCard, selectionArray, statusFeedback, - gPrintSettings, doPrintPreview, msgType); + printEngineWindow = window.openDialog("chrome://messenger/content/msgPrintEngine.xul", + "", + "chrome,dialog=no,all", + totalCard, selectionArray, statusFeedback, + gPrintSettings, doPrintPreview, msgType); - return; + return; } function AbPrintCard() @@ -524,55 +526,34 @@ function AbExport() function AbDeleteDirectory() { - var selectedABURI = GetSelectedDirectory(); - if (!selectedABURI) return; + var selectedABURI = GetSelectedDirectory(); + if (!selectedABURI) + return; - var isPersonalOrCollectedAbsSelectedForDeletion = false; - var parentArray = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray); - if (!parentArray) - return; + var parentArray = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray); + if (!parentArray) + return; - var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); - - // check to see if personal or collected address books is selected for deletion. - // if yes, prompt the user an appropriate message saying these cannot be deleted - if ((selectedABURI != kCollectedAddressbookURI) && - (selectedABURI != kPersonalAddressbookURI)) { - var parentRow = GetParentRow(dirTree, dirTree.currentIndex); - var parentId; - if (parentRow == -1) - parentId = "moz-abdirectory://"; - else - parentId = dirTree.builderView.getResourceAtIndex(parentRow).Value; - - var parentDir = GetDirectoryFromURI(parentId); - parentArray.AppendElement(parentDir); - } - else { - promptService.alert(window, - gAddressBookBundle.getString("cannotDeleteTitle"), - gAddressBookBundle.getString("cannotDeleteMessage")); - return; - } - - var confirmDeleteMessage; + var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); + + var parentRow = GetParentRow(dirTree, dirTree.currentIndex); + var parentId = (parentRow == -1) ? "moz-abdirectory://" : dirTree.builderView.getResourceAtIndex(parentRow).Value; + var parentDir = GetDirectoryFromURI(parentId); + parentArray.AppendElement(parentDir); - var directory = GetDirectoryFromURI(selectedABURI); - if (directory.isMailList) - confirmDeleteMessage = gAddressBookBundle.getString("confirmDeleteMailingList"); - else - confirmDeleteMessage = gAddressBookBundle.getString("confirmDeleteAddressbook"); + var directory = GetDirectoryFromURI(selectedABURI); + var confirmDeleteMessage = gAddressBookBundle.getString(directory.isMailList ? "confirmDeleteMailingList" : "confirmDeleteAddressbook"); - if (!promptService.confirm(window, null, confirmDeleteMessage)) - return; + if (!promptService.confirm(window, null, confirmDeleteMessage)) + return; - var resourceArray = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray); - var selectedABResource = GetDirectoryFromURI(selectedABURI).QueryInterface(Components.interfaces.nsIRDFResource); + var resourceArray = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray); + var selectedABResource = GetDirectoryFromURI(selectedABURI).QueryInterface(Components.interfaces.nsIRDFResource); - resourceArray.AppendElement(selectedABResource); + resourceArray.AppendElement(selectedABResource); - top.addressbook.deleteAddressBooks(dirTree.database, parentArray, resourceArray); - SelectFirstAddressBook(); + top.addressbook.deleteAddressBooks(dirTree.database, parentArray, resourceArray); + SelectFirstAddressBook(); } function SetStatusText(total) diff --git a/mailnews/addrbook/resources/content/addressbook.xul b/mailnews/addrbook/resources/content/addressbook.xul index 1ea916b94e1..691903980c9 100644 --- a/mailnews/addrbook/resources/content/addressbook.xul +++ b/mailnews/addrbook/resources/content/addressbook.xul @@ -215,7 +215,7 @@ Contributor(s): - + diff --git a/mailnews/addrbook/resources/locale/en-US/addressBook.properties b/mailnews/addrbook/resources/locale/en-US/addressBook.properties index 8d77dc941be..96de088169c 100644 --- a/mailnews/addrbook/resources/locale/en-US/addressBook.properties +++ b/mailnews/addrbook/resources/locale/en-US/addressBook.properties @@ -46,7 +46,6 @@ mailListNameExistsMessage=A Mailing List with that name already exists. Please c # used in the addressbook cannotDeleteTitle=Delete Failed -cannotDeleteMessage=You are not allowed to delete the Personal or Collected Addresses address books. confirmDeleteAddressbook=Are you sure you want to delete the selected address book? confirmDeleteMailingList=Are you sure you want to delete the selected mailing list? confirmDeleteListsAndCards=Are you sure you want to delete the selected cards and mailing lists?