Bug 455240 Address book card preview pane doesn't update for card changes via external interfaces (where notifications exist, e.g. OS X) and some internal updates too. r=Neil,sr=bienvenu
authorMark Banner <bugzilla@standard8.plus.com>
Wed, 17 Sep 2008 17:41:54 +0100
changeset 360 6fb2a576f786f77f14bdecaee18d10039493ff15
parent 359 2554af42cc1d0ec9accfbd1b1b7c892fd28c8d07
child 361 d6628cc24bc509a592d94070b4cc22befac0a02f
push idunknown
push userunknown
push dateunknown
reviewersNeil, bienvenu
bugs455240
Bug 455240 Address book card preview pane doesn't update for card changes via external interfaces (where notifications exist, e.g. OS X) and some internal updates too. r=Neil,sr=bienvenu
mail/components/addrbook/content/abCardOverlay.js
mail/components/addrbook/content/abCommon.js
mailnews/addrbook/resources/content/abCardOverlay.js
mailnews/addrbook/resources/content/abCommon.js
mailnews/addrbook/resources/content/abMailListDialog.js
mailnews/addrbook/src/nsAbView.cpp
--- a/mail/components/addrbook/content/abCardOverlay.js
+++ b/mail/components/addrbook/content/abCardOverlay.js
@@ -86,17 +86,16 @@ const kVcardFields =
          ["Custom3", "Custom3"],
          ["Custom4", "Custom4"],
           // Other > Notes
          ["Notes", "Notes"]];
 
 const kDefaultYear = 2000;
 var gEditCard;
 var gOnSaveListeners = new Array();
-var gOkCallback = null;
 var gHideABPicker = false;
 
 function OnLoadNewCard()
 {
   InitEditCard();
 
   gEditCard.card =
     (("arguments" in window) && (window.arguments.length > 0) &&
@@ -139,19 +138,16 @@ function OnLoadNewCard()
     }
     if ("aimScreenName" in window.arguments[0])
       gEditCard.card.setProperty("_AimScreenName",
                                  window.arguments[0].aimScreenName);
     if ("allowRemoteContent" in window.arguments[0])
       gEditCard.card.setProperty("AllowRemoteContent",
                                  window.arguments[0].allowRemoteContent);
 
-    if ("okCallback" in window.arguments[0])
-      gOkCallback = window.arguments[0].okCallback;
-
     if ("escapedVCardStr" in window.arguments[0]) {
       // hide non vcard values
       HideNonVcardFields();
       gEditCard.card =
         Components.classes["@mozilla.org/abmanager;1"]
                   .getService(Components.interfaces.nsIAbManager)
                   .escapedVCardToAbCard(window.arguments[0].escapedVCardStr);
     }
@@ -226,35 +222,29 @@ function EditCardOKButton()
   for (i=0; i < foundDirectoriesCount; i++) {
     // Update the addressLists item for this card
     foundDirectories[i].directory.addressLists
                        .replaceElementAt(gEditCard.card, foundDirectories[i].index, false);
   }
                                         
   NotifySaveListeners(directory);
 
-  // callback to allow caller to update
-  if (gOkCallback)
-    gOkCallback();
-
   return true;  // close the window
 }
 
 function OnLoadEditCard()
 {
   InitEditCard();
 
   gEditCard.titleProperty = "editCardTitle";
 
   if (window.arguments && window.arguments[0])
   {
     if ( window.arguments[0].card )
       gEditCard.card = window.arguments[0].card;
-    if ( window.arguments[0].okCallback )
-      gOkCallback = window.arguments[0].okCallback;
     if ( window.arguments[0].abURI )
       gEditCard.abURI = window.arguments[0].abURI;
   }
 
   // set global state variables
   // if first or last name entered, disable generateDisplayName
   if (gEditCard.generateDisplayName &&
       (gEditCard.card.firstName.length +
@@ -365,25 +355,16 @@ function InitEditCard()
   }
   catch (ex) {
     dump("ex: failed to get pref" + ex + "\n");
   }
 }
 
 function NewCardOKButton()
 {
-  if (gOkCallback)
-  {
-    if (!CheckAndSetCardValues(gEditCard.card, document, true))
-      return false;  // don't close window
-
-    gOkCallback(gEditCard.card.translateTo("vcard"));
-    return true;  // close the window
-  }
-
   var popup = document.getElementById('abPopup');
   if ( popup )
   {
     var uri = popup.value;
 
     // FIX ME - hack to avoid crashing if no ab selected because of blank option bug from template
     // should be able to just remove this if we are not seeing blank lines in the ab popup
     if ( !uri )
--- a/mail/components/addrbook/content/abCommon.js
+++ b/mail/components/addrbook/content/abCommon.js
@@ -199,17 +199,17 @@ function AbNewAddressBook()
 
 function AbEditSelectedDirectory()
 {
   if (dirTree.view.selection.count == 1) {
     var selecteduri = GetSelectedDirectory();
     var directory = GetDirectoryFromURI(selecteduri);
     if (directory.isMailList) {
       var dirUri = GetParentDirectoryFromMailingListURI(selecteduri);
-      goEditListDialog(null, selecteduri, UpdateCardView);
+      goEditListDialog(null, selecteduri);
     }
     else {
       window.openDialog(directory.propertiesChromeURI,
                         "editDirectory", "chrome,modal=yes,resizable=no",
                         {selectedDirectory: directory});
     }
   }
 }
@@ -322,20 +322,20 @@ function AbNewCard()
 function AbEditCard(card)
 {
   // Need a card,
   // but not allowing AOL special groups to be edited.
   if (!card)
     return;
 
   if (card.isMailList) {
-    goEditListDialog(card, card.mailListURI, UpdateCardView);
+    goEditListDialog(card, card.mailListURI);
   }
   else {
-    goEditCardDialog(GetSelectedDirectory(), card, UpdateCardView);
+    goEditCardDialog(GetSelectedDirectory(), card);
   }
 }
 
 function AbNewMessage()
 {
   var msgComposeType = Components.interfaces.nsIMsgCompType;
   var msgComposFormat = Components.interfaces.nsIMsgCompFormat;
   var msgComposeService = Components.classes["@mozilla.org/messengercompose;1"].getService();
@@ -501,38 +501,38 @@ function AbNewList()
 function goNewListDialog(selectedAB)
 {
   window.openDialog("chrome://messenger/content/addressbook/abMailListDialog.xul",
                     "",
                     "chrome,resizable=no,titlebar,modal,centerscreen",
                     {selectedAB:selectedAB});
 }
 
-function goEditListDialog(abCard, listURI, okCallback)
+function goEditListDialog(abCard, listURI)
 {
   window.openDialog("chrome://messenger/content/addressbook/abEditListDialog.xul",
                     "",
                     "chrome,resizable=no,titlebar,modal,centerscreen",
-                    {abCard:abCard, listURI:listURI, okCallback:okCallback});
+                    {abCard:abCard, listURI:listURI});
 }
 
 function goNewCardDialog(selectedAB)
 {
   window.openDialog("chrome://messenger/content/addressbook/abNewCardDialog.xul",
                     "",
                     "chrome,resizable=no,titlebar,modal,centerscreen",
                     {selectedAB:selectedAB});
 }
 
-function goEditCardDialog(abURI, card, okCallback)
+function goEditCardDialog(abURI, card)
 {
   window.openDialog("chrome://messenger/content/addressbook/abEditCardDialog.xul",
             "",
             "chrome,resizable=no,modal,titlebar,centerscreen",
-            {abURI:abURI, card:card, okCallback:okCallback});
+            {abURI:abURI, card:card});
 }
 
 
 function setSortByMenuItemCheckState(id, value)
 {
     var menuitem = document.getElementById(id);
     if (menuitem) {
       menuitem.setAttribute("checked", value);
--- a/mailnews/addrbook/resources/content/abCardOverlay.js
+++ b/mailnews/addrbook/resources/content/abCardOverlay.js
@@ -86,17 +86,16 @@ const kVcardFields =
          ["Custom3", "Custom3"],
          ["Custom4", "Custom4"],
           // Other > Notes
          ["Notes", "Notes"]];
 
 const kDefaultYear = 2000;
 var gEditCard;
 var gOnSaveListeners = new Array();
-var gOkCallback = null;
 var gHideABPicker = false;
 
 function OnLoadNewCard()
 {
   InitEditCard();
 
   gEditCard.card =
     (("arguments" in window) && (window.arguments.length > 0) &&
@@ -140,19 +139,16 @@ function OnLoadNewCard()
     if ("aimScreenName" in window.arguments[0])
       gEditCard.card.setProperty("_AimScreenName",
                                  window.arguments[0].aimScreenName);
     
     if ("allowRemoteContent" in window.arguments[0])
       gEditCard.card.setProperty("AllowRemoteContent",
                                  window.arguments[0].allowRemoteContent);
 
-    if ("okCallback" in window.arguments[0])
-      gOkCallback = window.arguments[0].okCallback;
-
     if ("escapedVCardStr" in window.arguments[0]) {
       // hide non vcard values
       HideNonVcardFields();
       gEditCard.card =
         Components.classes["@mozilla.org/abmanager;1"]
                   .getService(Components.interfaces.nsIAbManager)
                   .escapedVCardToAbCard(window.arguments[0].escapedVCardStr);
     }
@@ -226,35 +222,29 @@ function EditCardOKButton()
   
   for (i=0; i<foundDirectoriesCount; i++) {
       // Update the addressLists item for this card
       foundDirectories[i].directory.addressLists
                          .replaceElementAt(gEditCard.card, foundDirectories[i].index, false);
   }
   NotifySaveListeners(directory);
 
-  // callback to allow caller to update
-  if (gOkCallback)
-    gOkCallback();
-
   return true;  // close the window
 }
 
 function OnLoadEditCard()
 {
   InitEditCard();
 
   gEditCard.titleProperty = "editCardTitle";
 
   if (window.arguments && window.arguments[0])
   {
     if ( window.arguments[0].card )
       gEditCard.card = window.arguments[0].card;
-    if ( window.arguments[0].okCallback )
-      gOkCallback = window.arguments[0].okCallback;
     if ( window.arguments[0].abURI )
       gEditCard.abURI = window.arguments[0].abURI;
   }
 
   // set global state variables
   // if first or last name entered, disable generateDisplayName
   if (gEditCard.generateDisplayName &&
       (gEditCard.card.firstName.length +
@@ -364,25 +354,16 @@ function InitEditCard()
   }
   catch (ex) {
     dump("ex: failed to get pref" + ex + "\n");
   }
 }
 
 function NewCardOKButton()
 {
-  if (gOkCallback)
-  {
-    if (!CheckAndSetCardValues(gEditCard.card, document, true))
-      return false;  // don't close window
-
-    gOkCallback(gEditCard.card.translateTo("vcard"));
-    return true;  // close the window
-  }
-
   var popup = document.getElementById('abPopup');
   if ( popup )
   {
     var uri = popup.value;
 
     // FIX ME - hack to avoid crashing if no ab selected because of blank option bug from template
     // should be able to just remove this if we are not seeing blank lines in the ab popup
     if ( !uri )
--- a/mailnews/addrbook/resources/content/abCommon.js
+++ b/mailnews/addrbook/resources/content/abCommon.js
@@ -191,17 +191,17 @@ function AbNewAddressBook()
 }
 
 function AbEditSelectedDirectory()
 {
   if (dirTree.view.selection.count == 1) {
     var selecteduri = GetSelectedDirectory();
     var directory = GetDirectoryFromURI(selecteduri);
     if (directory.isMailList) {
-      goEditListDialog(null, selecteduri, UpdateCardView);
+      goEditListDialog(null, selecteduri);
     }
     else {
       window.openDialog(directory.propertiesChromeURI,
                         "editDirectory", "chrome,modal=yes,resizable=no",
                         { selectedDirectory: directory });
     }
   }
 }
@@ -310,20 +310,20 @@ function AbNewCard()
 
 function AbEditCard(card)
 {
   // Need a card,
   if (!card)
     return;
 
   if (card.isMailList) {
-    goEditListDialog(card, card.mailListURI, UpdateCardView);
+    goEditListDialog(card, card.mailListURI);
   }
   else {
-    goEditCardDialog(GetSelectedDirectory(), card, UpdateCardView);
+    goEditCardDialog(GetSelectedDirectory(), card);
   }
 }
 
 function AbNewMessage()
 {
   var params = Components.classes["@mozilla.org/messengercompose/composeparams;1"].createInstance(Components.interfaces.nsIMsgComposeParams);
   if (params)
   {
@@ -515,38 +515,38 @@ function AbNewList()
 function goNewListDialog(selectedAB)
 {
   window.openDialog("chrome://messenger/content/addressbook/abMailListDialog.xul",
                     "",
                     "chrome,resizable=no,titlebar,modal,centerscreen",
                     {selectedAB:selectedAB});
 }
 
-function goEditListDialog(abCard, listURI, okCallback)
+function goEditListDialog(abCard, listURI)
 {
   window.openDialog("chrome://messenger/content/addressbook/abEditListDialog.xul",
                     "",
                     "chrome,resizable=no,titlebar,modal,centerscreen",
-                    {abCard:abCard, listURI:listURI, okCallback:okCallback});
+                    {abCard:abCard, listURI:listURI});
 }
 
 function goNewCardDialog(selectedAB)
 {
   window.openDialog("chrome://messenger/content/addressbook/abNewCardDialog.xul",
                     "",
                     "chrome,resizable=no,titlebar,modal,centerscreen",
                     {selectedAB:selectedAB});
 }
 
-function goEditCardDialog(abURI, card, okCallback)
+function goEditCardDialog(abURI, card)
 {
   window.openDialog("chrome://messenger/content/addressbook/abEditCardDialog.xul",
 					  "",
 					  "chrome,resizable=no,modal,titlebar,centerscreen",
-					  {abURI:abURI, card:card, okCallback:okCallback});
+					  {abURI:abURI, card:card});
 }
 
 
 function setSortByMenuItemCheckState(id, value)
 {
     var menuitem = document.getElementById(id);
     if (menuitem) {
       menuitem.setAttribute("checked", value);
--- a/mailnews/addrbook/resources/content/abMailListDialog.js
+++ b/mailnews/addrbook/resources/content/abMailListDialog.js
@@ -35,17 +35,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 top.MAX_RECIPIENTS = 1;
 var inputElementType = "";
 
 var gListCard;
 var gEditList;
-var gOkCallback = null;
 var oldListName = "";
 var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
 var gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
 var gHeaderParser = Components.classes["@mozilla.org/messenger/headerparser;1"].getService(Components.interfaces.nsIMsgHeaderParser);
 
 try
 {
   var gDragService = Components.classes["@mozilla.org/widget/dragservice;1"]
@@ -261,31 +260,28 @@ function EditListOKButton()
       gListCard.displayName = gEditList.dirName;
       gListCard.lastName = gEditList.dirName;
       gListCard.setProperty("NickName", gEditList.listNickName);
       gListCard.setProperty("Notes", gEditList.description);
     }
 
     gEditList.editMailListToDatabase(gListCard);
 
-    if (gOkCallback)
-      gOkCallback();
     return true;  // close the window
   }
-  else
-    return false;
+
+  return false;
 }
 
 function OnLoadEditList()
 {
   InitCommonJS();
 
   gListCard = window.arguments[0].abCard;
   var listUri  = window.arguments[0].listURI;
-  gOkCallback = window.arguments[0].okCallback;
 
   gEditList = GetDirectoryFromURI(listUri);
 
   document.getElementById('ListName').value = gEditList.dirName;
   document.getElementById('ListNickName').value = gEditList.listNickName;
   document.getElementById('ListDescription').value = gEditList.description;
   oldListName = gEditList.dirName;
 
--- a/mailnews/addrbook/src/nsAbView.cpp
+++ b/mailnews/addrbook/src/nsAbView.cpp
@@ -962,16 +962,23 @@ NS_IMETHODIMP nsAbView::OnItemPropertyCh
     return NS_ERROR_OUT_OF_MEMORY;
 
   newCard->card = card;
   NS_IF_ADDREF(newCard->card);
     
   rv = GenerateCollationKeysForCard(mSortColumn.get(), newCard);
   NS_ENSURE_SUCCESS(rv,rv);
 
+  PRBool cardWasSelected = PR_FALSE;
+
+  if (mTreeSelection) {
+    rv = mTreeSelection->IsSelected(index, &cardWasSelected);
+    NS_ENSURE_SUCCESS(rv,rv);
+  }
+  
   if (!CompareCollationKeys(newCard->primaryCollationKey,newCard->primaryCollationKeyLen,oldCard->primaryCollationKey,oldCard->primaryCollationKeyLen)
     && CompareCollationKeys(newCard->secondaryCollationKey,newCard->secondaryCollationKeyLen,oldCard->secondaryCollationKey,oldCard->secondaryCollationKeyLen)) {
     // no need to remove and add, since the collation keys haven't change.
     // since they haven't chagned, the card will sort to the same place.
     // we just need to clean up what we allocated.
     NS_IF_RELEASE(newCard->card);
     if (newCard->primaryCollationKey)
       nsMemory::Free(newCard->primaryCollationKey);
@@ -979,23 +986,16 @@ NS_IMETHODIMP nsAbView::OnItemPropertyCh
       nsMemory::Free(newCard->secondaryCollationKey);
     PR_FREEIF(newCard);
 
     // still need to invalidate, as the other columns may have changed
     rv = InvalidateTree(index);
     NS_ENSURE_SUCCESS(rv,rv);
   }
   else {
-    PRBool cardWasSelected = PR_FALSE;
-
-    if (mTreeSelection) {
-      rv = mTreeSelection->IsSelected(index, &cardWasSelected);
-      NS_ENSURE_SUCCESS(rv,rv);
-    }
-    
     mSuppressSelectionChange = PR_TRUE;
     mSuppressCountChange = PR_TRUE;
 
     // remove the old card
     rv = RemoveCardAt(index);
     NS_ASSERTION(NS_SUCCEEDED(rv), "remove card failed\n");
 
     // add the card we created, and select it (to restore selection) if it was selected
@@ -1004,16 +1004,23 @@ NS_IMETHODIMP nsAbView::OnItemPropertyCh
 
     mSuppressSelectionChange = PR_FALSE;
     mSuppressCountChange = PR_FALSE;
 
     // ensure restored selection is visible
     if (cardWasSelected && mTree) 
       mTree->EnsureRowIsVisible(index);
   }
+
+  // Although the selection hasn't changed, the card that is selected may need
+  // to be displayed differently, therefore pretend that the selection has
+  // changed to force that update.
+  if (cardWasSelected)
+    SelectionChanged();
+
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAbView::SelectAll()
 {
   if (mTreeSelection && mTree) {
     mTreeSelection->SelectAll();
     mTree->Invalidate();