Bug 649989 - display account names in favorite folders pane view only when there are duplicated folder names and location info in the tooltip; r=bienvenu ui-r=bwinton
authorStefan Plewako <splewako@aviary.pl>
Mon, 04 Jul 2011 10:55:17 +0100
changeset 8258 1281fc89bac53103e40f3da71b2e6ab2346af885
parent 8257 1f367f35734935abcfbf6507e516822cd1fa6d30
child 8259 f6adf57025405e094d7e12a426427b6eb319a94d
push id84
push userbugzilla@standard8.plus.com
push dateTue, 16 Aug 2011 21:25:04 +0000
treeherdercomm-beta@6970c86be3cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbienvenu, bwinton
bugs649989
Bug 649989 - display account names in favorite folders pane view only when there are duplicated folder names and location info in the tooltip; r=bienvenu ui-r=bwinton
mail/base/content/folderPane.js
mail/base/content/mailWidgets.xml
mail/base/content/messenger.css
mail/test/mozmill/folder-display/test-display-message-with-folder-modes.js
mail/test/mozmill/folder-display/test-folder-names-in-favorite-mode.js
mail/test/mozmill/shared-modules/test-folder-display-helpers.js
--- a/mail/base/content/folderPane.js
+++ b/mail/base/content/folderPane.js
@@ -1323,21 +1323,26 @@ let gFolderTreeView = {
         let faves = [];
         for each (let folder in ftv._enumerateFolders) {
           if (folder.flags & nsMsgFolderFlags.Favorite)
             faves.push(new ftvItem(folder));
         }
 
         // There are no children in this view!
         // And we want to display the account name to distinguish folders w/
-        // the same name.
-        for each (let folder in faves) {
-          folder.__defineGetter__("children", function() []);
-          folder.addServerName = true;
+        // the same name. (only for folders with duplicated names)
+        let uniqueNames = new Object();
+        for each (let item in faves) {
+          item.__defineGetter__("children", function() []);
+          if (!uniqueNames[item._folder.abbreviatedName])
+            uniqueNames[item._folder.abbreviatedName] = 0;
+          uniqueNames[item._folder.abbreviatedName]++;
         }
+        for each (let item in faves)
+          item.addServerName = (uniqueNames[item._folder.abbreviatedName] > 1) ? true : false;
         sortFolderItems(faves);
         return faves;
       },
 
       getParentOfFolder: function ftv_unread_getParentOfFolder(aFolder) {
         // This is a flat view, so no folders have parents.
         return null;
       }
--- a/mail/base/content/mailWidgets.xml
+++ b/mail/base/content/mailWidgets.xml
@@ -2093,18 +2093,22 @@
     </content>
     <handlers>
       <handler event="popupshowing">
         <![CDATA[
           var msgFolder = gFolderTreeView.getFolderAtCoords(event.clientX,
                                                             event.clientY);
           if (!msgFolder || msgFolder.isServer)
             return false;
+
           var asyncResults = {};
-          return document.getAnonymousNodes(this)[0].parseFolder(msgFolder, null, asyncResults);
+          let newMessages = document.getAnonymousNodes(this)[0].parseFolder(msgFolder, null, asyncResults);
+          let addLocation = document.getAnonymousNodes(this)[0].addLocationInfo(msgFolder);
+
+          return newMessages || addLocation;
         ]]>
       </handler>
 
       <handler event="popuphiding">
         document.getAnonymousNodes(this)[0].clear();
       </handler>
     </handlers>
   </binding>
@@ -2118,31 +2122,21 @@
       <field name="mMaxMsgHdrsInPopup">8</field>
       <property name="hasMessages" readonly="true" onget="return document.getAnonymousNodes(this)[0].hasChildNodes();"/>
       <method name="parseFolder">
         <parameter name="aFolder"/>
         <parameter name="aUrlListener"/>
         <parameter name="aOutAsync"/>
         <body>
           <![CDATA[
-            // Use the full newsgroup name as tooltip for abbreviated newsgroups.
-            if ((aFolder.server instanceof Components.interfaces.nsINntpIncomingServer) &&
-                !(aFolder.flags & Components.interfaces.nsMsgFolderFlags.Virtual) &&
-                aFolder.server.abbreviate) {
-
-              var msgPopup = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "label");
-              msgPopup.setAttribute("value", aFolder.name);
-              document.getAnonymousNodes(this)[0].appendChild(msgPopup);
-              return true;
-            }
-
-            // skip servers, Trash and Junk folders
+            // skip servers, Trash, Junk folders and newsgroups
             if (!aFolder || aFolder.isServer ||
                 aFolder.getFlag(Components.interfaces.nsMsgFolderFlags.Junk) ||
-                aFolder.getFlag(Components.interfaces.nsMsgFolderFlags.Trash))
+                aFolder.getFlag(Components.interfaces.nsMsgFolderFlags.Trash) ||
+                (aFolder.server instanceof Components.interfaces.nsINntpIncomingServer))
               return false;
             var pref = Components.classes["@mozilla.org/preferences-service;1"]
                                  .getService(Components.interfaces.nsIPrefBranch);
             var showPreviewText = pref.getBoolPref("mail.biff.alert.show_preview");
             var folderArray = new Array;
             if (aFolder.flags & Components.interfaces.nsMsgFolderFlags.Virtual)
             {
               var dbFolderInfo = aFolder.msgDatabase.dBFolderInfo;
@@ -2240,28 +2234,70 @@
               if (document.getAnonymousNodes(this)[0].childNodes.length >= this.mMaxMsgHdrsInPopup)
                 return true;
             }
             return foundNewMsg;
           ]]>
         </body>
       </method>
 
+      <method name="addLocationInfo">
+        <parameter name="aFolder"/>
+        <body>
+          <![CDATA[
+            // Use the full newsgroup name as tooltip for abbreviated newsgroups.
+            if ((aFolder.server instanceof Components.interfaces.nsINntpIncomingServer) &&
+                !(aFolder.flags & Components.interfaces.nsMsgFolderFlags.Virtual) &&
+                aFolder.server.abbreviate) {
+
+              let loc = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "folderSummaryLocation");
+              loc.setAttribute("location", aFolder.name);
+              document.getAnonymousNodes(this)[0].appendChild(loc);
+              return true;
+            }
+
+            // Display location info for items in favorite folder pane mode.
+            if (gFolderTreeView.mode == "favorite") {
+              let loc = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "folderSummaryLocation");
+              let midPath = "";
+              let midFolder = aFolder.parent;
+              while (aFolder.server.rootFolder != midFolder) {
+                midPath = midFolder.name + " - " + midPath;
+                midFolder = midFolder.parent;
+              }
+              loc.setAttribute("location", aFolder.server.prettyName + " - " + midPath + aFolder.name);
+              document.getAnonymousNodes(this)[0].appendChild(loc);
+              return true;
+            }
+
+            return false;
+          ]]>
+        </body>
+      </method>
+
       <method name="clear">
         <body>
           <![CDATA[
             var containingBox = document.getAnonymousNodes(this)[0];
             while (containingBox.hasChildNodes())
               containingBox.removeChild(containingBox.lastChild);
           ]]>
         </body>
       </method>
     </implementation>
   </binding>
 
+  <binding id="folderSummary-location">
+    <content>
+      <xul:hbox>
+        <xul:label anonid="location" xbl:inherits="value=location"/>
+      </xul:hbox>
+    </content>
+  </binding>
+
   <binding id="folderSummary-message">
     <content>
       <xul:vbox class="folderSummaryMessage">
         <xul:hbox class="folderSummary-message-row">
           <xul:label anonid="subject" flex="1" class="folderSummary-subject" xbl:inherits="value=subject" crop="right"/>
           <xul:label anonid="sender"  class="folderSummary-sender" xbl:inherits="value=sender" crop="right"/>
           <xul:spring anonid="spring" flex="100%"/>
         </xul:hbox>
--- a/mail/base/content/messenger.css
+++ b/mail/base/content/messenger.css
@@ -207,16 +207,21 @@ folderSummary
   -moz-binding: url("chrome://messenger/content/mailWidgets.xml#folderSummary");
 }
 
 folderSummaryMessage
 {
   -moz-binding: url("chrome://messenger/content/mailWidgets.xml#folderSummary-message");
 }
 
+folderSummaryLocation
+{
+  -moz-binding: url("chrome://messenger/content/mailWidgets.xml#folderSummary-location");
+}
+
 .foldersTree
 {
   margin: 0px;
   border: none;
   -moz-user-focus: ignore;
 }
 
 .foldersTreeChildren
--- a/mail/test/mozmill/folder-display/test-display-message-with-folder-modes.js
+++ b/mail/test/mozmill/folder-display/test-display-message-with-folder-modes.js
@@ -122,16 +122,20 @@ function test_display_message_with_folde
   assert_folder_visible(dummyFolder);
 
   // Try displaying a message
   display_message_in_folder_tab(msgHdr);
 
   assert_folder_mode("favorite");
   assert_folder_selected_and_displayed(folder);
   assert_selected_and_displayed(msgHdr);
+
+  // Now unset the flags so that we don't affect later tests.
+  folder.flags &= ~Ci.nsMsgFolderFlags.Favorite;
+  dummyFolder.flags &= ~Ci.nsMsgFolderFlags.Favorite;
 }
 
 /**
  * Test that displaying a message in smart folders mode causes the parent in the
  * view to expand.
  */
 function test_display_message_in_smart_folder_mode_works() {
   // Clear the message selection, otherwise msgHdr will still be displayed and
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/folder-display/test-folder-names-in-favorite-mode.js
@@ -0,0 +1,46 @@
+var MODULE_NAME = "test-folder-names-in-favorite-mode";
+var RELATIVE_ROOT = "../shared-modules";
+var MODULE_REQUIRES = ["folder-display-helpers"];
+
+function setupModule(module) {
+  let fdh = collector.getModule("folder-display-helpers");
+  fdh.installInto(module);
+};
+
+function test_folder_names_in_favorite_pane_view_mode() {
+  let acc1 = MailServices.accounts.accounts.QueryElementAt(0, Ci.nsIMsgAccount);
+  let acc2 = MailServices.accounts.accounts.QueryElementAt(1, Ci.nsIMsgAccount);
+  let rootFolder1 = acc1.incomingServer.rootFolder;
+  let rootFolder2 = acc2.incomingServer.rootFolder;
+
+  rootFolder1.createSubfolder("uniqueName", null);
+  rootFolder1.createSubfolder("duplicatedName", null);
+  rootFolder2.createSubfolder("duplicatedName", null);
+  rootFolder2.getFolderWithFlags(Ci.nsMsgFolderFlags.Inbox).createSubfolder("duplicatedName", null);
+
+  let fUnique = rootFolder1.getChildNamed("uniqueName");
+  let fDup1 = rootFolder1.getChildNamed("duplicatedName");
+  let fDup2 = rootFolder2.getChildNamed("duplicatedName");
+  let fDup3 = rootFolder2.getFolderWithFlags(Ci.nsMsgFolderFlags.Inbox).getChildNamed("duplicatedName");
+  let inbox = rootFolder2.getFolderWithFlags(Ci.nsMsgFolderFlags.Inbox);
+
+  fUnique.flags |= Ci.nsMsgFolderFlags.Favorite;
+  fDup1.flags |= Ci.nsMsgFolderFlags.Favorite;
+  fDup2.flags |= Ci.nsMsgFolderFlags.Favorite;
+  fDup3.flags |= Ci.nsMsgFolderFlags.Favorite;
+  inbox.flags &= ~Ci.nsMsgFolderFlags.Favorite;
+
+  mc.window.gFolderTreeView.mode = "favorite";
+
+  assert_folder_at_index_as(0, "duplicatedName - Local Folders");
+  assert_folder_at_index_as(1, "duplicatedName - tinderbox@invalid.com");
+  assert_folder_at_index_as(2, "duplicatedName - tinderbox@invalid.com");
+  assert_folder_at_index_as(3, "uniqueName");
+
+  // Reset the flags to the state they were previously.
+  fUnique.flags &= ~Ci.nsMsgFolderFlags.Favorite;
+  fDup1.flags &= ~Ci.nsMsgFolderFlags.Favorite;
+  fDup2.flags &= ~Ci.nsMsgFolderFlags.Favorite;
+  fDup3.flags &= ~Ci.nsMsgFolderFlags.Favorite;
+  inbox.flags |= Ci.nsMsgFolderFlags.Favorite;
+};
--- a/mail/test/mozmill/shared-modules/test-folder-display-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-folder-display-helpers.js
@@ -2467,16 +2467,24 @@ let assert_folder_selected_and_displayed
  */
 function assert_folder_tree_view_row_count(aCount) {
   if (mc.folderTreeView.rowCount != aCount)
     throw new Error("The folder tree view's row count should be " + aCount +
                     ", but is actually " + mc.folderTreeView.rowCount);
 }
 
 /**
+ * Assert that the displayed text of the folder at index n equals to str.
+ */
+function assert_folder_at_index_as(n, str) {
+  let folderN = mc.window.gFolderTreeView.getFTVItemForIndex(n);
+  assert_equals(folderN.text, str)
+}
+
+/**
  * Since indexOf does strict equality checking, we need this.
  */
 function _non_strict_index_of(aArray, aSearchElement) {
   for ([i, item] in Iterator(aArray)) {
     if (item == aSearchElement)
       return i;
   }
   return -1;