Bug 421834 - Fix sorting and labels for the bookmark library restore menu, r=adw, mak77 a=beltzner
authorMichael Kohler <michaelkohler@live.com>
Mon, 23 Mar 2009 18:43:06 +0100
changeset 23875 611067897bf2
parent 23874 96a69edf5317
child 23876 6333e294056a
push id969
push usermak77@bonardo.net
push dateMon, 23 Mar 2009 17:43:45 +0000
reviewersadw, mak77, beltzner
bugs421834
milestone1.9.1b4pre
Bug 421834 - Fix sorting and labels for the bookmark library restore menu, r=adw, mak77 a=beltzner
browser/components/places/content/places.js
--- a/browser/components/places/content/places.js
+++ b/browser/components/places/content/places.js
@@ -402,51 +402,59 @@ var PlacesOrganizer = {
   },
 
   /**
    * Populates the restore menu with the dates of the backups available.
    */
   populateRestoreMenu: function PO_populateRestoreMenu() {
     var restorePopup = document.getElementById("fileRestorePopup");
 
+    var dateSvc = Cc["@mozilla.org/intl/scriptabledateformat;1"].
+                  getService(Ci.nsIScriptableDateFormat);
+
     // remove existing menu items
     // last item is the restoreFromFile item
     while (restorePopup.childNodes.length > 1)
       restorePopup.removeChild(restorePopup.firstChild);
 
     // get list of files
     var localizedFilename = PlacesUtils.getString("bookmarksArchiveFilename");
     var localizedFilenamePrefix = localizedFilename.substr(0, localizedFilename.indexOf("-"));
     var fileList = [];
     var files = this.bookmarksBackupDir.directoryEntries;
     while (files.hasMoreElements()) {
       var f = files.getNext().QueryInterface(Ci.nsIFile);
-      var rx = new RegExp("^(bookmarks|" + localizedFilenamePrefix + ")-.+\.json");
-      if (!f.isHidden() && f.leafName.match(rx))
-        fileList.push(f);
+      var rx = new RegExp("^(bookmarks|" + localizedFilenamePrefix +
+                          ")-([0-9]{4}-[0-9]{2}-[0-9]{2})\.json$");
+      if (!f.isHidden() && f.leafName.match(rx)) {
+        var date = f.leafName.match(rx)[2].replace(/-/g, "/");
+        var dateObj = new Date(date);
+        fileList.push({date: dateObj, filename: f.leafName});
+      }
     }
 
     fileList.sort(function PO_fileList_compare(a, b) {
-      return b.lastModifiedTime - a.lastModifiedTime;
+      return b.date - a.date;
     });
 
     if (fileList.length == 0)
       return;
 
     // populate menu
     for (var i = 0; i < fileList.length; i++) {
       var m = restorePopup.insertBefore
         (document.createElement("menuitem"),
          document.getElementById("restoreFromFile"));
-      var rx = new RegExp("^(bookmarks|" + localizedFilenamePrefix + ")-");
-      var dateStr = fileList[i].leafName.replace(rx, "").replace(/\.json$/, "");
-      if (!dateStr.length)
-        dateStr = fileList[i].leafName;
-      m.setAttribute("label", dateStr);
-      m.setAttribute("value", fileList[i].leafName);
+      m.setAttribute("label",
+                     dateSvc.FormatDate("",
+                                        Ci.nsIScriptableDateFormat.dateFormatLong,
+                                        fileList[i].date.getFullYear(),
+                                        fileList[i].date.getMonth() + 1,
+                                        fileList[i].date.getDate()));
+      m.setAttribute("value", fileList[i].filename);
       m.setAttribute("oncommand",
                      "PlacesOrganizer.onRestoreMenuItemClick(this);");
     }
     restorePopup.insertBefore(document.createElement("menuseparator"),
                               document.getElementById("restoreFromFile"));
   },
 
   /**