Bug 1665430 - Respect default start-up address book preferences in contacts sidebar. r=ThomasD
authorGeoff Lankow <geoff@darktrojan.net>
Mon, 23 Nov 2020 07:30:09 +0000
changeset 40527 a4c52e5d29fcac8968ed07102d4b889ae78750a1
parent 40526 4c8d82dc0948dd9aaedbc9e21f63ef5f8d96736c
child 40528 552965dee1f6f1a1eb4d96dcea58c5a7398221c5
push id2885
push userthunderbird@calypsoblue.org
push dateMon, 14 Dec 2020 19:37:55 +0000
treeherdercomm-beta@49a97c7fccb0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersThomasD
bugs1665430
Bug 1665430 - Respect default start-up address book preferences in contacts sidebar. r=ThomasD Stop using the XUL store to persist the last used value, and store it (if applicable) in the same way as the address book window does. Differential Revision: https://phabricator.services.mozilla.com/D94274
mail/components/addrbook/content/abContactsPanel.js
mail/components/addrbook/content/abContactsPanel.xhtml
--- a/mail/components/addrbook/content/abContactsPanel.js
+++ b/mail/components/addrbook/content/abContactsPanel.js
@@ -142,23 +142,26 @@ function AbPanelLoad() {
   if (location.search == "?focus") {
     document.getElementById("peopleSearchInput").focus();
   }
 
   InitCommonJS();
 
   document.title = parent.document.getElementById("sidebar-title").value;
 
-  var abPopup = document.getElementById("addressbookList");
+  // Get the URI of the directory to display.
+  let startupURI = Services.prefs.getCharPref("mail.addr_book.view.startupURI");
+  // If the URI is a mailing list, use the parent directory instead, since
+  // mailing lists are not displayed here.
+  startupURI = startupURI.replace(/^(jsaddrbook:\/\/[\w\.-]*)\/.*$/, "$1");
 
-  // Reselect the persisted address book if possible, if not just select the
-  // first in the list.
-  var temp = abPopup.value;
-  abPopup.selectedItem = null;
-  abPopup.value = temp;
+  let abPopup = document.getElementById("addressbookList");
+  abPopup.value = startupURI;
+
+  // If provided directory is not on abPopup, fall back to All Address Books.
   if (!abPopup.selectedItem) {
     abPopup.selectedIndex = 0;
   }
 
   // Postpone the slow contacts load so that the sidebar document
   // gets a chance to display quickly.
   setTimeout(ChangeDirectoryByURI, 0, abPopup.value);
 
@@ -181,16 +184,24 @@ function AbPanelLoad() {
     attributes: true,
     childList: true,
   });
 }
 
 function AbPanelUnload() {
   mutationObs.disconnect();
 
+  // If there's no default startupURI, save the last used URI as new startupURI.
+  if (!Services.prefs.getBoolPref("mail.addr_book.view.startupURIisDefault")) {
+    Services.prefs.setCharPref(
+      "mail.addr_book.view.startupURI",
+      getSelectedDirectoryURI()
+    );
+  }
+
   CloseAbView();
 }
 
 function AbPanelNewCard() {
   goNewCardDialog(abList.value);
 }
 
 function AbPanelNewList() {
--- a/mail/components/addrbook/content/abContactsPanel.xhtml
+++ b/mail/components/addrbook/content/abContactsPanel.xhtml
@@ -108,18 +108,17 @@
       <button id="abContextMenuButton"
               tooltiptext="&abContextMenuButton.tooltip;"
               oncommand="abContextMenuButtonOnCommand(event);"/>
     </hbox>
     <hbox id="panel-bar" class="themeable-full" align="center">
       <menulist is="menulist-addrbooks" id="addressbookList"
                 alladdressbooks="true"
                 oncommand="AddressBookMenuListChange(this.value);"
-                flex="1"
-                persist="value"/>
+                flex="1"/>
     </hbox>
 
     <separator class="thin"/>
 
     <vbox>
       <label value="&searchContacts.label;"
              accesskey="&searchContacts.accesskey;"
              control="peopleSearchInput"/>