[Pkg-mozext-commits] [tabmixplus] 28/44: Add new function to bookmark sessions, with and without groups, fix changeset 7b62fb27f914

David Prévot taffit at moszumanska.debian.org
Fri Mar 18 20:57:16 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository tabmixplus.

commit 1415a4952b6937c2f6843cfd7b302e7e866c866f
Author: onemen <tabmix.onemen at gmail.com>
Date:   Tue Mar 1 19:11:17 2016 +0200

    Add new function to bookmark sessions, with and without groups, fix changeset 7b62fb27f914
---
 chrome/content/session/session.js              | 46 ++++++++++++++++------
 chrome/content/tabmix.xul                      |  6 +--
 chrome/locale/en-US/session-manager.properties |  5 +++
 chrome/locale/en-US/tabmix.dtd                 |  4 +-
 modules/TabGroupsMigrator.jsm                  | 54 ++++++++++++++++++++++----
 5 files changed, 91 insertions(+), 24 deletions(-)

diff --git a/chrome/content/session/session.js b/chrome/content/session/session.js
index 4e95965..ea9b126 100644
--- a/chrome/content/session/session.js
+++ b/chrome/content/session/session.js
@@ -342,6 +342,10 @@ TabmixSessionManager = {
       document.getElementById("tmp_disableSave").setAttribute("disabled", true);
     }
 
+    if (!Tabmix.isVersion(450)) {
+      document.getElementById("tm-sm-bookmark").hidden = true;
+    }
+
     // check if last session was crashed
     let crashed, sm_status;
     if (this.enableBackup) {
@@ -1632,13 +1636,6 @@ TabmixSessionManager = {
     else
       document.getElementById("tm-sm-Rename").removeAttribute("disabled");
 
-    if (Tabmix.isVersion(450)) {
-      let bookmark = document.getElementById("tm-sm-bookmark");
-      triggerNode.state = TabmixConvertSession.getSessionState(triggerNode.session, true);
-      triggerNode.groupData = this.TabmixGroupsMigrator.gatherGroupData(triggerNode.state);
-      bookmark.hidden = !triggerNode.groupData.exist;
-    }
-
     var node = triggerNode.parentNode.parentNode;
     var mItem = document.getElementById("tm-sm-SetAsStartup");
     if (node.hasAttribute("sessionmanager-menu")) {
@@ -1732,12 +1729,35 @@ TabmixSessionManager = {
     }
   },
 
-  bookmarkAllGroups: function(node) {
-    let {groupData, session} = node;
-    let name = this.getDecodedLiteralValue(session, "name");
-    if (groupData && groupData.exist) {
+  bookmarkSession: function(node) {
+    if (!Tabmix.isVersion(450)) {
+      return;
+    }
+    let {command, session, history} = node;
+    let state, name;
+    let data = () => {
+      let nameExt = this.getLiteralValue(session, "nameExt");
+      let re = /\((\d+\sW)*[,\s]*(\d+\sT)\)\s\((\d{4}\/\d{2}\/\d{2})\s(\d{2}:\d{2}:\d{2})/;
+      let matches = nameExt.match(re);
+      let timestamp = matches ? Date.parse(new Date(matches[3] + " " + matches[4])) : Date.now();
+      return (new Date(timestamp)).toLocaleFormat("%Y/%m/%d %H:%M:%S");
+    };
+    if (command == "openclosedwindow") {
+      let winData = TabmixConvertSession.getWindowState(session, true);
+      state = {windows: [winData]};
+      name = TabmixSvc.getSMString("sm.bookmarks.closedWindow") + ", " + data();
+    } else {
+      state = TabmixConvertSession.getSessionState(session, true);
+      if (history) {
+        name = TabmixSvc.getSMString("sm.bookmarks.historySession") + ", " + data();
+      } else {
+        name = this.getDecodedLiteralValue(session, "name");
+      }
+    }
+    let groupData = this.TabmixGroupsMigrator.gatherGroupData(state);
+    if (groupData) {
       let oldGuid = this.getLiteralValue("rdf:backupSessionWithGroups", "guid");
-      let promise = this.TabmixGroupsMigrator.bookmarkAllGroupsFromState(groupData.data, oldGuid, name);
+      let promise = this.TabmixGroupsMigrator.bookmarkAllGroupsFromState(groupData, oldGuid, name);
       this.saveGuid(promise, oldGuid);
     }
   },
@@ -1989,6 +2009,7 @@ TabmixSessionManager = {
       mi.setAttribute("session", mi.session);
       if (backups.indexOf(name) > -1) {
         mi.style.setProperty("color", "blue", "important");
+        mi.history = true;
       }
       if (contents == 1 && loadsession > -1 && mi.session && mi.session == sessionpath) continue;
       mi.setAttribute("value", i);
@@ -2031,6 +2052,7 @@ TabmixSessionManager = {
           menu = document.createElement("menuitem");
           var [sLabel, sessionIndex] = sessionLabel[i].split(" ");
           menu.session = this.gSessionPath[sessionIndex];
+          menu.history = true;
           menu.command = menuCommand;
           if (this.containerEmpty(menu.session) && contents != 1)
             menu.setAttribute("disabled", "true");
diff --git a/chrome/content/tabmix.xul b/chrome/content/tabmix.xul
index 8226f9b..ccd992e 100644
--- a/chrome/content/tabmix.xul
+++ b/chrome/content/tabmix.xul
@@ -347,9 +347,9 @@
                   oncommand="TabmixSessionManager.saveClosedSession(this.parentNode.triggerNode);"/>
         <menuitem id="tm-sm-Rename" label="&sm.context.rename;" accesskey="&sm.context.rename.key;"
                   oncommand="TabmixSessionManager.renameSession(this.parentNode.triggerNode.session);"/>
-        <menuitem id="tm-sm-bookmark" label="&sm.context.bookmarkgroups;"
-                  accesskey="&sm.context.bookmarkgroups.key;" hidden="true"
-                  oncommand="TabmixSessionManager.bookmarkAllGroups(this.parentNode.triggerNode);"/>
+        <menuitem id="tm-sm-bookmark" label="&sm.context.bookmarkSession;"
+                  accesskey="&sm.context.bookmarkSession.key;"
+                  oncommand="TabmixSessionManager.bookmarkSession(this.parentNode.triggerNode);"/>
         <menuseparator/>
         <menuitem id="tm-sm-Delete" label="&sm.context.delete;" accesskey="&sm.context.delete.key;"
                   oncommand="TabmixSessionManager.removeSavedSession(this.parentNode.triggerNode);"/>
diff --git a/chrome/locale/en-US/session-manager.properties b/chrome/locale/en-US/session-manager.properties
index 7d76ff8..94905e5 100644
--- a/chrome/locale/en-US/session-manager.properties
+++ b/chrome/locale/en-US/session-manager.properties
@@ -114,4 +114,9 @@ sm.tabview.install.accesskey=I
 sm.tabview.backup.session=History Session, backup with groups data
 sm.tabview.backup.crashed=Crashed Session, backup with groups data
 sm.tabview.backup.msg=Tab mix plus Session Manager has saved a backup of your session.
+sm.bookmarks.historySession = History Session
+sm.bookmarks.closedWindow = Closed Window
 sm.bookmarks.sessionFolder=Tab Mix Plus Sessions
+# LOCALIZATION NOTE (sm.bookmarks.migration.windowID):
+# %S is the window number in the session
+sm.bookmarks.migration.windowID = Window %S
diff --git a/chrome/locale/en-US/tabmix.dtd b/chrome/locale/en-US/tabmix.dtd
index c93b481..9626138 100644
--- a/chrome/locale/en-US/tabmix.dtd
+++ b/chrome/locale/en-US/tabmix.dtd
@@ -102,8 +102,8 @@
 <!ENTITY sm.context.save.key "S">
 <!ENTITY sm.context.rename "Rename">
 <!ENTITY sm.context.rename.key "R">
-<!ENTITY sm.context.bookmarkgroups "Bookmark Groups">
-<!ENTITY sm.context.bookmarkgroups.key "B">
+<!ENTITY sm.context.bookmarkSession "Bookmark Session">
+<!ENTITY sm.context.bookmarkSession.key "B">
 <!ENTITY sm.context.delete "Delete">
 <!ENTITY sm.context.delete.key "D">
 <!ENTITY sm.context.deleteall "Delete All">
diff --git a/modules/TabGroupsMigrator.jsm b/modules/TabGroupsMigrator.jsm
index 6d1869d..95ceb41 100644
--- a/modules/TabGroupsMigrator.jsm
+++ b/modules/TabGroupsMigrator.jsm
@@ -1,4 +1,4 @@
-/* globals AsyncShutdown */
+/* globals AsyncShutdown, gBrowserBundle */
 "use strict";
 
 this.EXPORTED_SYMBOLS = ["TabmixGroupsMigrator"];
@@ -41,6 +41,10 @@ XPCOMUtils.defineLazyModuleGetter(this, "TabmixSvc",
 XPCOMUtils.defineLazyModuleGetter(this, "TabmixPlacesUtils",
                                   "resource://tabmixplus/Places.jsm");
 
+XPCOMUtils.defineLazyGetter(this, "gBrowserBundle", function() {
+  return Services.strings.createBundle('chrome://browser/locale/browser.properties');
+});
+
 this.TabmixGroupsMigrator = {
   /**
    * If previous or last session contains tab groups, save a back
@@ -199,15 +203,51 @@ this.TabmixGroupsMigrator = {
     return [...groupData.keys()].length > 0;
   },
 
+  // add windows without groups to the data as single group
+  // add window count to each folder title
   gatherGroupData: function(state) {
-    let data;
-    if (TabGroupsMigrator) {
-      data = TabGroupsMigrator._gatherGroupData(state);
+    if (!TabGroupsMigrator) {
+      return null;
     }
-    return {
-      exist: this.isGroupExist(data || new Map()),
-      data: data
+
+    let allGroupData = TabGroupsMigrator._gatherGroupData(state);
+    // add window count for each group title
+    let getWinTitle = id => {
+      const name = "sm.bookmarks.migration.windowID";
+      return TabmixSvc.SMstrings.formatStringFromName(name, [id], 1);
+    };
+    let getTitle = id => {
+      const name = "tabgroups.migration.anonGroup";
+      return gBrowserBundle.formatStringFromName(name, [id], 1);
     };
+    let winID = 0;
+    for (let win of state.windows) {
+      let winTitle = getWinTitle(++winID);
+      let windowGroupMap = allGroupData.get(win);
+      if (windowGroupMap) {
+        let anonGroupCount = 0;
+        let windowGroups = [... windowGroupMap.values()].sort(TabGroupsMigrator._groupSorter);
+        let singleanonGroup = windowGroups[0].anonGroupID && windowGroups.length == 1;
+        if (singleanonGroup) {
+          windowGroups[0].tabGroupsMigrationTitle = winTitle;
+          continue;
+        }
+        for (let group of windowGroups) {
+          let title = group.anonGroupID ?
+              getTitle(++anonGroupCount) : group.tabGroupsMigrationTitle;
+          group.tabGroupsMigrationTitle = winTitle + " " + title;
+        }
+      } else {
+        let windowGroupMap = new Map();
+        windowGroupMap.set("active group", {
+          tabs: win.tabs,
+          anonGroupID: 1,
+          tabGroupsMigrationTitle: winTitle
+        });
+        allGroupData.set(win, windowGroupMap);
+      }
+    }
+    return allGroupData;
   },
 
   setTabTitle: function(groupData) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/tabmixplus.git



More information about the Pkg-mozext-commits mailing list