Bug 706826 - update account name in the account tree when a new name is entered into the account name field and update the folder pane if the name change is saved. r=jorgk
authoraceman <acelists@atlas.sk>
Tue, 25 Sep 2018 12:29:00 +0200
changeset 33227 bff3cba93b7ce29a2a0747c540e4ec59461b54b1
parent 33226 1b38cacc09e510c2e418a9af31bd3bcaf55404f2
child 33228 49bf37634232a6237ccc84219a365000affc9739
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs706826
Bug 706826 - update account name in the account tree when a new name is entered into the account name field and update the folder pane if the name change is saved. r=jorgk
mail/base/content/folderPane.js
mailnews/base/prefs/content/AccountManager.js
mailnews/base/prefs/content/am-main.js
mailnews/base/prefs/content/am-main.xul
mailnews/base/prefs/content/am-serverwithnoidentities.js
mailnews/base/prefs/content/am-serverwithnoidentities.xul
mailnews/extensions/newsblog/content/am-newsblog.js
mailnews/extensions/newsblog/content/am-newsblog.xul
--- a/mail/base/content/folderPane.js
+++ b/mail/base/content/folderPane.js
@@ -2242,17 +2242,23 @@ var gFolderTreeView = {
     }
   },
 
   OnItemBoolPropertyChanged: function(aItem, aProperty, aOld, aNew) {
     let index = this.getIndexOfFolder(aItem);
     if (index != null)
       this._tree.invalidateRow(index);
   },
-  OnItemUnicharPropertyChanged: function(aItem, aProperty, aOld, aNew) {},
+
+  OnItemUnicharPropertyChanged: function(aItem, aProperty, aOld, aNew) {
+    let index = this.getIndexOfFolder(aItem);
+    if (index != null)
+      this._tree.invalidateRow(index);
+  },
+
   OnItemPropertyFlagChanged: function(aItem, aProperty, aOld, aNew) {},
   OnItemEvent: function(aFolder, aEvent) {
     let index = this.getIndexOfFolder(aFolder);
     if (index != null)
       this._tree.invalidateRow(index);
   }
 };
 
--- a/mailnews/base/prefs/content/AccountManager.js
+++ b/mailnews/base/prefs/content/AccountManager.js
@@ -703,34 +703,56 @@ function AddIMAccount()
  *                    Can be given as null if there is none.
  * @param oldDefault  The account that has stopped being the default.
  *                    Can be given as null if there was none.
  */
 function markDefaultServer(newDefault, oldDefault) {
   if (oldDefault == newDefault)
     return;
 
-  let accountTreeNodes = document.getElementById("account-tree-children")
-                                 .childNodes;
-  for (let i = 0; i < accountTreeNodes.length; i++) {
-    let accountNode = accountTreeNodes[i];
+  let accountTree = document.getElementById("account-tree-children");
+  for (let accountNode of accountTree.childNodes) {
     if (newDefault && newDefault == accountNode._account) {
       let props = accountNode.firstChild.firstChild.getAttribute("properties");
       accountNode.firstChild.firstChild
                             .setAttribute("properties", props + " isDefaultServer-true");
     }
     if (oldDefault && oldDefault == accountNode._account) {
       let props = accountNode.firstChild.firstChild.getAttribute("properties");
       props = props.replace(/isDefaultServer-true/, "");
       accountNode.firstChild.firstChild.setAttribute("properties", props);
     }
   }
 }
 
 /**
+ * Sets the name of the account rowitem in the tree pane.
+ *
+ * @param aAccountKey   the key of the account to change
+ * @param aAccountNode  the node on which to change the label
+ * @param aLabel        the value of the label to set
+ */
+function setAccountLabel(aAccountKey, aAccountNode, aLabel) {
+  if (!aAccountNode) {
+    // We can't use the current tree selection to determine the current account,
+    // because this function may be called when the selection
+    // is already on another tree item (account) than the one we want to change.
+    // So find the proper node using the account key.
+    let accountTree = document.getElementById("account-tree-children");
+    for (let accountNode of accountTree.childNodes) {
+      if (("_account" in accountNode) && (accountNode._account.key == aAccountKey)) {
+        aAccountNode = accountNode.firstChild.firstChild;
+        break;
+      }
+    }
+  }
+  aAccountNode.setAttribute("label", aLabel);
+}
+
+/**
  * Make currentAccount (currently selected in the account tree) the default one.
  */
 function onSetDefault(event) {
   // Make sure this function was not called while the control item is disabled
   if (event.target.getAttribute("disabled") == "true")
     return;
 
   let previousDefault = getDefaultAccount();
@@ -1616,17 +1638,17 @@ var gAccountTree = {
         treeitem.appendChild(treekids);
         for (let panel of panelsToKeep) {
           var kidtreeitem = document.createElement("treeitem");
           treekids.appendChild(kidtreeitem);
           var kidtreerow = document.createElement("treerow");
           kidtreeitem.appendChild(kidtreerow);
           var kidtreecell = document.createElement("treecell");
           kidtreerow.appendChild(kidtreecell);
-          kidtreecell.setAttribute("label", panel.string);
+          setAccountLabel(null, kidtreecell, panel.string);
           kidtreeitem.setAttribute("PageTag", panel.src);
           kidtreeitem._account = account;
         }
         treeitem.setAttribute("container", "true");
         treeitem.id = accountKey;
         // Load the 'open' state of the account from XULStore.json.
         treeitem.setAttribute("open", this._getAccountOpenState(accountKey));
         // Let the XULStore.json automatically save the 'open' state of the
--- a/mailnews/base/prefs/content/am-main.js
+++ b/mailnews/base/prefs/content/am-main.js
@@ -1,13 +1,15 @@
 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+var gAccount;
+
 function onInit(aPageId, aServerId)
 {
   var accountName = document.getElementById("server.prettyName");
   var title = document.getElementById("am-main-title");
   var defaultTitle = title.getAttribute("defaultTitle");
   var titleValue;
 
   if(accountName.value)
@@ -18,42 +20,42 @@ function onInit(aPageId, aServerId)
   title.setAttribute("title",titleValue);
   document.title = titleValue;
 
   setupSignatureItems();
 }
 
 function onPreInit(account, accountValues)
 {
+  gAccount = account;
   loadSMTPServerList();
 }
 
 function manageIdentities()
 {
   // We want to save the current identity information before bringing up the multiple identities
   // UI. This ensures that the changes are reflected in the identity list dialog
   // onSave();
 
-  var account = parent.getCurrentAccount();
-  if (!account)
+  if (!gAccount)
     return;
 
   var accountName = document.getElementById("server.prettyName").value;
 
-  var args = { account: account, accountName: accountName, result: false };
+  var args = { account: gAccount, accountName: accountName, result: false };
 
   // save the current identity settings so they show up correctly
   // if the user just changed them in the manage identities dialog
-  var identity = account.defaultIdentity;
+  var identity = gAccount.defaultIdentity;
   saveIdentitySettings(identity);
 
   window.openDialog("am-identities-list.xul", "", "chrome,modal,resizable=no,centerscreen", args);
 
   if (args.result) {
     // now re-initialize the default identity settings in case they changed
-    identity = account.defaultIdentity; // refetch the default identity in case it changed
+    identity = gAccount.defaultIdentity; // Refetch the default identity in case it changed.
     initIdentityValues(identity);
   }
 
   // Refresh the SMTP list in case the user changed server properties
   // from the identity dialog.
   loadSMTPServerList();
 }
--- a/mailnews/base/prefs/content/am-main.xul
+++ b/mailnews/base/prefs/content/am-main.xul
@@ -24,16 +24,17 @@
     <broadcaster id="broadcaster_attachSignature"/>
 
     <dialogheader id="am-main-title" defaultTitle="&accountTitle.label;"/>
 
     <hbox align="center">
       <label value="&accountName.label;" control="server.prettyName"
              accesskey="&accountName.accesskey;"/>
       <textbox wsm_persist="true" size="30" id="server.prettyName"
+               onblur="parent.setAccountLabel(gAccount.key, null, this.value);"
                prefstring="mail.server.%serverkey%.name"/>
     </hbox>
 
     <separator class="thin"/>
 
     <groupbox style="width: 20em !important;" flex="1">
       <caption label="&identityTitle.label;"/>
       <description>&identityDesc.label;</description>
--- a/mailnews/base/prefs/content/am-serverwithnoidentities.js
+++ b/mailnews/base/prefs/content/am-serverwithnoidentities.js
@@ -1,16 +1,16 @@
 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 ChromeUtils.import("resource://gre/modules/BrowserUtils.jsm");
 
-var gServer;
+var gAccount;
 var gOriginalStoreType;
 
 /**
  * Called when the store type menu is clicked.
  * @param {Object} aStoreTypeElement - store type menu list element.
  */
 function clickStoreTypeMenu(aStoreTypeElement) {
   if (aStoreTypeElement.value == gOriginalStoreType) {
@@ -18,17 +18,18 @@ function clickStoreTypeMenu(aStoreTypeEl
   }
 
   // Response from migration dialog modal. If the conversion is complete
   // 'response.newRootFolder' will hold the path to the new account root folder,
   // otherwise 'response.newRootFolder' will be null.
   let response = { newRootFolder: null };
   // Send 'response' as an argument to converterDialog.xhtml.
   window.openDialog("converterDialog.xhtml","mailnews:mailstoreconverter",
-                    "modal,centerscreen,width=800,height=180", gServer,
+                    "modal,centerscreen,width=800,height=180",
+                    gAccount.incomingServer,
                     aStoreTypeElement.value, response);
   changeStoreType(response);
 }
 
 /**
  * Revert store type to the original store type if converter modal closes
  * before migration is complete, otherwise change original store type to
  * currently selected store type.
@@ -60,17 +61,17 @@ function onInit(aPageId, aServerId) {
                                .getAttribute("value");
   let targetItem = storeTypeElement.getElementsByAttribute("value", currentStoreID);
   storeTypeElement.selectedItem = targetItem[0];
   // Initialise 'gOriginalStoreType' to the item that was originally selected.
   gOriginalStoreType = storeTypeElement.value;
 }
 
 function onPreInit(account, accountValues) {
-  gServer = account.incomingServer;
+  gAccount = account;
 }
 
 function onSave()
 {
   let storeContractID = document.getElementById("server.storeTypeMenulist")
                                 .selectedItem
                                 .value;
   document.getElementById("server.storeContractID")
--- a/mailnews/base/prefs/content/am-serverwithnoidentities.xul
+++ b/mailnews/base/prefs/content/am-serverwithnoidentities.xul
@@ -28,16 +28,17 @@
          genericattr="true"
          id="server.storeContractID"/>
 
   <description class="secDesc">&accountSettingsDesc.label;</description>
   <hbox align="center">
     <label value="&accountName.label;" control="server.prettyName"
            accesskey="&accountName.accesskey;"/>
     <textbox wsm_persist="true" size="30" id="server.prettyName"
+             onblur="parent.setAccountLabel(gAccount.key, null, this.value);"
              prefstring="mail.server.%serverkey%.name"/>
   </hbox>
 
   <separator class="thin"/>
 
   <groupbox>
     <caption label="&messageStorage.label;"/>
 
--- a/mailnews/extensions/newsblog/content/am-newsblog.js
+++ b/mailnews/extensions/newsblog/content/am-newsblog.js
@@ -1,16 +1,16 @@
 /* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 ChromeUtils.import("resource:///modules/FeedUtils.jsm");
 
-var gServer, gUpdateEnabled, gUpdateValue, gBiffUnits,
+var gAccount, gUpdateEnabled, gUpdateValue, gBiffUnits,
     gAutotagEnable, gAutotagUsePrefix, gAutotagPrefix;
 
 function onInit(aPageId, aServerId) {
   var accountName = document.getElementById("server.prettyName");
   var title = document.getElementById("am-newsblog-title");
   var defaultTitle = title.getAttribute("defaultTitle");
 
   var titleValue;
@@ -18,17 +18,17 @@ function onInit(aPageId, aServerId) {
     titleValue = defaultTitle + " - <" + accountName.value + ">";
   } else {
     titleValue = defaultTitle;
   }
 
   title.setAttribute("title", titleValue);
   document.title = titleValue;
 
-  let optionsAcct = FeedUtils.getOptionsAcct(gServer);
+  let optionsAcct = FeedUtils.getOptionsAcct(gAccount.incomingServer);
   document.getElementById("doBiff").checked = optionsAcct.doBiff;
 
   gUpdateEnabled = document.getElementById("updateEnabled");
   gUpdateValue = document.getElementById("updateValue");
   gBiffUnits = document.getElementById("biffUnits");
   gAutotagEnable = document.getElementById("autotagEnable");
   gAutotagUsePrefix = document.getElementById("autotagUsePrefix");
   gAutotagPrefix = document.getElementById("autotagPrefix");
@@ -44,24 +44,24 @@ function onInit(aPageId, aServerId) {
   gAutotagEnable.checked = optionsAcct.category.enabled;
   gAutotagUsePrefix.disabled = !gAutotagEnable.checked;
   gAutotagUsePrefix.checked = optionsAcct.category.prefixEnabled;
   gAutotagPrefix.disabled = gAutotagUsePrefix.disabled || !gAutotagUsePrefix.checked;
   gAutotagPrefix.value = optionsAcct.category.prefix;
 }
 
 function onPreInit(account, accountValues) {
-  gServer = account.incomingServer;
+  gAccount = account;
 }
 
 function setPrefs(aNode) {
-  let optionsAcct =  FeedUtils.getOptionsAcct(gServer);
+  let optionsAcct =  FeedUtils.getOptionsAcct(gAccount.incomingServer);
   switch (aNode.id) {
     case "doBiff":
-      FeedUtils.pauseFeedFolderUpdates(gServer.rootFolder, !aNode.checked, true);
+      FeedUtils.pauseFeedFolderUpdates(gAccount.incomingServer.rootFolder, !aNode.checked, true);
       break;
     case "updateEnabled":
     case "updateValue":
     case "biffUnits":
       optionsAcct.updates.enabled = gUpdateEnabled.checked;
       onCheckItem("updateValue", ["updateEnabled"]);
       let minutes = gBiffUnits.value == FeedUtils.kBiffUnitsMinutes ?
                       gUpdateValue.valueNumber :
@@ -78,10 +78,10 @@ function setPrefs(aNode) {
       optionsAcct.category.prefixEnabled = aNode.checked;
       gAutotagPrefix.disabled = aNode.disabled || !aNode.checked;
       break;
     case "autotagPrefix":
       optionsAcct.category.prefix = aNode.value;
       break;
   }
 
-  FeedUtils.setOptionsAcct(gServer, optionsAcct);
+  FeedUtils.setOptionsAcct(gAccount.incomingServer, optionsAcct);
 }
--- a/mailnews/extensions/newsblog/content/am-newsblog.xul
+++ b/mailnews/extensions/newsblog/content/am-newsblog.xul
@@ -41,16 +41,17 @@
 
     <hbox align="center">
       <label value="&accountName.label;"
              accesskey="&accountName.accesskey;"
              control="server.prettyName"/>
       <textbox id="server.prettyName"
                wsm_persist="true"
                size="30"
+               onblur="parent.setAccountLabel(gAccount.key, null, this.value);"
                prefstring="mail.server.%serverkey%.name"/>
     </hbox>
 
     <separator class="thin"/>
 
     <groupbox>
       <caption label="&serverSettings.label;"/>
       <checkbox id="doBiff"
@@ -116,17 +117,17 @@
       </hbox>
     </groupbox>
 
     <separator class="thin"/>
 
     <hbox align="center">
       <button label="&manageSubscriptions.label;"
               accesskey="&manageSubscriptions.accesskey;"
-              oncommand="openSubscriptionsDialog(gServer.rootFolder);"/>
+              oncommand="openSubscriptionsDialog(gAccount.incomingServer.rootFolder);"/>
       <spacer flex="1"/>
     </hbox>
 
     <separator class="thin"/>
 
     <groupbox>
       <caption label="&messageStorage.label;"/>