Bug 740617 - Show the default account name in bold in the Account manager tree of accounts. r=IanN, ui-r=bwinton, r=mconley
authoraceman <acelists@atlas.sk>
Mon, 23 Apr 2012 19:04:29 -0400
changeset 11713 da0cbfbfbeb7e2df9b9d1a1a464c032c4e4b9e49
parent 11712 75dc16fb563807e5fb76be26d18b9513190c17be
child 11714 9aace1fa76ffa6a2b96e01e10681da2f7c70b95a
push idunknown
push userunknown
push dateunknown
reviewersIanN, bwinton, mconley
bugs740617
Bug 740617 - Show the default account name in bold in the Account manager tree of accounts. r=IanN, ui-r=bwinton, r=mconley
mail/themes/pinstripe/mail/accountManage.css
mailnews/base/prefs/content/AccountManager.js
--- a/mail/themes/pinstripe/mail/accountManage.css
+++ b/mail/themes/pinstripe/mail/accountManage.css
@@ -68,16 +68,20 @@
 #accounttree {
   -moz-margin-end: 8px;
 }
 
 #accountActionsDropdown {
   min-width: 30ch;
 }
 
+treechildren::-moz-tree-cell-text(isDefaultServer-true) {
+  font-weight: bold;
+}
+
 button:not(.spinbuttons-button):not(.dialog-button) {
   min-height: 19px; /* aqua size for small buttons */
 }
 
 page > description {
      margin: 4px 4px 8px;
 }
 
--- a/mailnews/base/prefs/content/AccountManager.js
+++ b/mailnews/base/prefs/content/AccountManager.js
@@ -421,75 +421,100 @@ function AddMailAccount()
 }
 
 function AddIMAccount()
 {
   window.openDialog("chrome://messenger/content/chat/imAccountWizard.xul",
                     "", "chrome,modal,titlebar,centerscreen");
 }
 
-function onSetDefault(event) {
-  if (event.target.getAttribute("disabled") == "true") return;
+/**
+ * Highlight the default server in the account tree,
+ * optionally un-highlight the previous one.
+ */
+function markDefaultServer(newDefault, oldDefault) {
+  let accountTree = document.getElementById("account-tree-children");
+  for each (let accountNode in accountTree.childNodes) {
+    if (newDefault == accountNode._account) {
+      accountNode.firstChild
+                 .firstChild
+                 .setAttribute("properties", "isDefaultServer-true");
+    }
+    if (oldDefault && oldDefault == accountNode._account) {
+      accountNode.firstChild
+                 .firstChild
+                 .removeAttribute("properties");
+    }
+  }
+}
 
-  Components.classes["@mozilla.org/messenger/account-manager;1"]
-            .getService(Components.interfaces.nsIMsgAccountManager)
-            .defaultAccount = currentAccount;
+/**
+ * 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 = MailServices.accounts.defaultAccount;
+  MailServices.accounts.defaultAccount = currentAccount;
+  markDefaultServer(currentAccount, previousDefault);
+
+  // This is only needed on Seamonkey which has this button.
   setEnabled(document.getElementById("setDefaultButton"), false);
 }
 
 function onRemoveAccount(event) {
-  if (event.target.getAttribute("disabled") == "true") return;
-
-  var account = currentAccount;
-
-  var server = account.incomingServer;
-  var type = server.type;
-  var prettyName = server.prettyName;
-
-  var protocolinfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + type].getService(Components.interfaces.nsIMsgProtocolInfo);
-  var canDelete = protocolinfo.canDelete;
-  if (!canDelete) {
-    canDelete = server.canDelete;
-  }
-  if (!canDelete) 
+  if (event.target.getAttribute("disabled") == "true" || !currentAccount)
     return;
 
-  var bundle = document.getElementById("bundle_prefs");
-  var confirmRemoveAccount =
-    bundle.getFormattedString("confirmRemoveAccount", [prettyName]);
+  let server = currentAccount.incomingServer;
+  let type = server.type;
+  let prettyName = server.prettyName;
+
+  let canDelete = false;
+  if (Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + type]
+                .getService(Components.interfaces.nsIMsgProtocolInfo).canDelete)
+    canDelete = true;
+  else
+    canDelete = server.canDelete;
 
-  var confirmTitle = bundle.getString("confirmRemoveAccountTitle");
+  if (!canDelete)
+    return;
 
-  var promptService =
-    Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
-              .getService(Components.interfaces.nsIPromptService);
-  if (!promptService.confirm(window, confirmTitle, confirmRemoveAccount))
+  let bundle = document.getElementById("bundle_prefs");
+  let confirmRemoveAccount = bundle.getFormattedString("confirmRemoveAccount",
+                                                       [prettyName]);
+
+  let confirmTitle = bundle.getString("confirmRemoveAccountTitle");
+
+  if (!Services.prompt.confirm(window, confirmTitle, confirmRemoveAccount))
     return;
 
   try {
-    // clear cached data out of the account array
-    currentAccount = currentPageId = null;
+    let serverId = server.serverURI;
+    MailServices.accounts.removeAccount(currentAccount);
 
-    var serverId = server.serverURI;
-    Components.classes["@mozilla.org/messenger/account-manager;1"]
-              .getService(Components.interfaces.nsIMsgAccountManager)
-              .removeAccount(account);
-
+    currentAccount = currentPageId = null;
+    // clear cached data out of the account array
     if (serverId in accountArray) {
       delete accountArray[serverId];
     }
     selectServer(null, null);
   }
   catch (ex) {
     dump("failure to remove account: " + ex + "\n");
-    var alertText = bundle.getString("failedRemoveAccount");
-    Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
-              .getService(Components.interfaces.nsIPromptService)
-              .alert(window, null, alertText);;
+    let alertText = bundle.getString("failedRemoveAccount");
+    Services.prompt.alert(window, null, alertText);;
   }
+
+  // Either the default account was deleted so there is a new one
+  // or the default account was not changed. Either way, there is
+  // no need to unmark the old one.
+  markDefaultServer(MailServices.accounts.defaultAccount, null);
 }
 
 function saveAccount(accountValues, account)
 {
   var identity = null;
   var server = null;
 
   if (account) {
@@ -1088,24 +1113,20 @@ function getValueArrayFor(account) {
 
   return accountArray[serverId];
 }
 
 var gAccountTree = {
   load: function at_load() {
     this._build();
 
-    var mgr = Components.classes["@mozilla.org/messenger/account-manager;1"]
-                        .getService(Components.interfaces.nsIMsgAccountManager);
-    mgr.addIncomingServerListener(this);
+    MailServices.accounts.addIncomingServerListener(this);
   },
   unload: function at_unload() {
-    var mgr = Components.classes["@mozilla.org/messenger/account-manager;1"]
-                        .getService(Components.interfaces.nsIMsgAccountManager);
-    mgr.removeIncomingServerListener(this);
+    MailServices.accounts.removeIncomingServerListener(this);
   },
   onServerLoaded: function at_onServerLoaded(aServer) {
     this._build();
   },
   onServerUnloaded: function at_onServerUnloaded(aServer) {
     this._build();
   },
   onServerChanged: function at_onServerChanged(aServer) {},
@@ -1117,18 +1138,17 @@ var gAccountTree = {
     var panels = [{string: get("prefPanel-server"), src: "am-server.xul"},
                   {string: get("prefPanel-copies"), src: "am-copies.xul"},
                   {string: get("prefPanel-synchronization"), src: "am-offline.xul"},
                   {string: get("prefPanel-diskspace"), src: "am-offline.xul"},
                   {string: get("prefPanel-addressing"), src: "am-addressing.xul"},
                   {string: get("prefPanel-junk"), src: "am-junk.xul"}];
 
     // Get our account list, and add the proper items
-    var mgr = Components.classes["@mozilla.org/messenger/account-manager;1"]
-                        .getService(Components.interfaces.nsIMsgAccountManager);
+    var mgr = MailServices.accounts;
 
     var accounts = [a for each (a in fixIterator(mgr.accounts, Ci.nsIMsgAccount))];
     // Stupid bug 41133 hack. Grr...
     accounts = accounts.filter(function fix(a) { return a.incomingServer; });
 
     function sortAccounts(a, b) {
       if (a.key == mgr.defaultAccount.key)
         return -1;
@@ -1151,22 +1171,20 @@ var gAccountTree = {
     }
     accounts.sort(sortAccounts);
 
     var mainTree = document.getElementById("account-tree-children");
     // Clear off all children...
     while (mainTree.firstChild)
       mainTree.removeChild(mainTree.firstChild);
 
-    var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
-                               .getService(Components.interfaces.nsIPrefBranch);
-    for each (var account in accounts) {
+    for each (let account in accounts) {
       let server = account.incomingServer;
 
-      if (server.type == "im" && !prefBranch.getBoolPref("mail.chat.enabled"))
+      if (server.type == "im" && !Services.prefs.getBoolPref("mail.chat.enabled"))
         continue;
 
       // Create the top level tree-item
       var treeitem = document.createElement("treeitem");
       mainTree.appendChild(treeitem);
       var treerow = document.createElement("treerow");
       treeitem.appendChild(treerow);
       var treecell = document.createElement("treecell");
@@ -1201,31 +1219,28 @@ var gAccountTree = {
       const CATEGORY = "mailnews-accountmanager-extensions";
       var catEnum = catMan.enumerateCategory(CATEGORY);
       while (catEnum.hasMoreElements()) {
         var string = Components.interfaces.nsISupportsCString;
         var entryName = catEnum.getNext().QueryInterface(string).data;
         var svc = Components.classes[catMan.getCategoryEntry(CATEGORY, entryName)]
                             .getService(Ci.nsIMsgAccountManagerExtension);
         if (svc.showPanel(server)) {
-          var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"]
-                              .getService(Ci.nsIStringBundleService);
-
           let bundleName = "chrome://" + svc.chromePackageName +
                            "/locale/am-" + svc.name + ".properties";
-          let bundle = sbs.createBundle(bundleName);
+          let bundle = Services.strings.createBundle(bundleName);
           let title = bundle.GetStringFromName("prefPanel-" + svc.name);
           panelsToKeep.push({string: title, src: "am-" + svc.name + ".xul"});
         }
       }
 
       if (panelsToKeep.length > 0) {
         var treekids = document.createElement("treechildren");
         treeitem.appendChild(treekids);
-        for each (panel in panelsToKeep) {
+        for each (let panel in 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);
           kidtreeitem.setAttribute("PageTag", panel.src);
@@ -1234,16 +1249,18 @@ var gAccountTree = {
         treeitem.setAttribute("container", "true");
         treeitem.setAttribute("open", "true");
       }
       treeitem.setAttribute("PageTag", server ? server.accountManagerChrome
                                               : "am-main.xul");
       treeitem._account = account;
     }
 
+    markDefaultServer(mgr.defaultAccount, null);
+
     // Now add the outgoing server node
     var treeitem = document.createElement("treeitem");
     mainTree.appendChild(treeitem);
     var treerow = document.createElement("treerow");
     treeitem.appendChild(treerow);
     var treecell = document.createElement("treecell");
     treerow.appendChild(treecell);
     treecell.setAttribute("label", bundle.getString("prefPanel-smtp"));