[Pkg-mozext-commits] [tabmixplus] 14/44: Create TabGroupsMigrator.jsm and move to it new functions from changesets 6c166b2305b7 and 90deaeb2cc7a
David Prévot
taffit at moszumanska.debian.org
Fri Mar 18 20:57:15 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 f1c4df0d35c9e3b6f5299575331306e7fe8e2f94
Author: onemen <tabmix.onemen at gmail.com>
Date: Sun Feb 28 23:11:19 2016 +0200
Create TabGroupsMigrator.jsm and move to it new functions from changesets 6c166b2305b7 and 90deaeb2cc7a
---
chrome/content/session/session.js | 119 ++--------------------------------
modules/TabGroupsMigrator.jsm | 132 ++++++++++++++++++++++++++++++++++++++
2 files changed, 138 insertions(+), 113 deletions(-)
diff --git a/chrome/content/session/session.js b/chrome/content/session/session.js
index 7091d29..3f0f99e 100644
--- a/chrome/content/session/session.js
+++ b/chrome/content/session/session.js
@@ -275,66 +275,6 @@ TabmixSessionManager = {
.then(null, Tabmix.reportError);
},
- //XXX move this to a modules ????
- _maybeBackupTabGroups: function(isAfterCrash) {
- let notify;
-
- let isSessionWithGroups = path => {
- if (this.containerEmpty(path)) {
- return false;
- }
- let sessionContainer = this.initContainer(path);
- let sessionEnum = sessionContainer.GetElements();
- while (sessionEnum.hasMoreElements()) {
- let rdfNodeSession = sessionEnum.getNext();
- if (rdfNodeSession instanceof Ci.nsIRDFResource) {
- let windowPath = rdfNodeSession.QueryInterface(Ci.nsIRDFResource).Value;
- if (this.nodeHasArc(windowPath, "dontLoad")) {
- continue;
- }
- let data = this.getLiteralValue(windowPath, "tabview-groups", "{}");
- let parsedData = TabmixSvc.JSON.parse(data);
- if (parsedData.totalNumber > 1) {
- notify = true;
- return true;
- }
- }
- }
- return false;
- };
-
- let string = s => TabmixSvc.getSMString("sm.tabview.backup." + s);
- let saveSessions = (type, index) => {
- let session = this.gSessionPath[index];
- if (!isSessionWithGroups(session)) {
- return;
- }
- this.saveClosedSession({
- session: session,
- name: {name: string(type)},
- nameExt: this.getLiteralValue(session, "nameExt", ""),
- button: -1
- });
- };
-
- try {
- // we run this function before preparAfterCrash and prepareSavedSessions
- // we need to backup 2 last session, if last session was crashed backup
- // one more older session
- let index = isAfterCrash ? 1 : 0;
- saveSessions("session", index + 1);
- saveSessions("session", index);
- if (isAfterCrash) {
- saveSessions("crashed", 0);
- }
- if (notify) {
- this.missingTabViewNotification(string("msg"));
- }
- } catch (ex) {
- Tabmix.assert(ex);
- }
- },
-
_init: function SM__init() {
if (Tabmix.isVersion(320)) {
XPCOMUtils.defineLazyModuleGetter(this, "TabState",
@@ -342,6 +282,10 @@ TabmixSessionManager = {
XPCOMUtils.defineLazyModuleGetter(this, "TabStateCache",
"resource:///modules/sessionstore/TabStateCache.jsm");
}
+
+ XPCOMUtils.defineLazyModuleGetter(this, "TabmixGroupsMigrator",
+ "resource://tabmixplus/TabGroupsMigrator.jsm");
+
// just in case tablib isn't init yet
// when Webmail Notifier extension istalled and user have master password
// we can get here before the browser window is loaded
@@ -406,7 +350,7 @@ TabmixSessionManager = {
!TabmixSvc.isPaleMoon && Tabmix.firstWindowInSession && !sanitized &&
!this.nodeHasArc("rdf:backupSessionWithGroups", "status")) {
this.setLiteral("rdf:backupSessionWithGroups", "status", "saved");
- this._maybeBackupTabGroups(crashed);
+ this.TabmixGroupsMigrator.backupSessions(window, crashed);
}
// If sessionStore restore the session after restart we do not need to do anything
@@ -3895,59 +3839,8 @@ TabmixSessionManager = {
if (showNotification || !this.tabViewInstalled) {
let hiddenTabs = gBrowser.tabs.length > gBrowser.visibleTabs.length;
if (this._groupCount > 1 && hiddenTabs) {
- this.missingTabViewNotification();
- }
- }
- },
-
- missingTabViewNotification: function(backup = "") {
- let string = s => TabmixSvc.getSMString("sm.tabview." + s);
-
- // If there's already an existing notification bar, don't do anything.
- let notificationBox = document.getElementById("high-priority-global-notificationbox") ||
- document.getElementById("global-notificationbox");
- let notification = notificationBox.getNotificationWithValue("tabmix-missing-tabview");
- if (notification) {
- if (notification.tabmixSavedBackup) {
- notification.label += " " + string("hiddengroups");
- delete notification.tabmixSavedBackup;
+ this.TabmixGroupsMigrator.missingTabViewNotification(window);
}
- return;
- }
-
- let message = backup || string("hiddengroups");
- let buttons = [{
- label: string("install.label"),
- accessKey: string("install.accesskey"),
- callback: function() {
- let link = TabmixSvc.isPaleMoon ?
- "http://www.palemoon.org/tabgroups.shtml" :
- "https://addons.mozilla.org/en-US/firefox/addon/tab-groups-panorama/";
- openUILinkIn(link, "tab");
- }
- }];
-
- if (!TabmixSvc.isPaleMoon) {
- buttons.push({
- label: string("removed.learnMore.label"),
- accessKey: string("removed.learnMore.accesskey"),
- callback: function() {
- openUILinkIn("https://support.mozilla.org/kb/tab-groups-removal#w_tab-groups-replacement-add-ons", "tab");
- }
- });
-
- message = string("removed") + " " + message;
- }
-
- notification = notificationBox.appendNotification(
- message,
- "tabmix-missing-tabview",
- "chrome://tabmixplus/skin/tmpsmall.png",
- notificationBox.PRIORITY_WARNING_MEDIUM,
- buttons
- );
- if (backup) {
- notification.tabmixSavedBackup = true;
}
},
diff --git a/modules/TabGroupsMigrator.jsm b/modules/TabGroupsMigrator.jsm
new file mode 100644
index 0000000..1f9974d
--- /dev/null
+++ b/modules/TabGroupsMigrator.jsm
@@ -0,0 +1,132 @@
+"use strict";
+
+this.EXPORTED_SYMBOLS = ["TabmixGroupsMigrator"];
+
+const {interfaces: Ci, utils: Cu} = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "Services",
+ "resource://gre/modules/Services.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "TabGroupsMigrator",
+ "resource:///modules/TabGroupsMigrator.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "TabmixSvc",
+ "resource://tabmixplus/Services.jsm");
+
+this.TabmixGroupsMigrator = {
+ /**
+ * If previous or last session contains tab groups, save a back
+ */
+ backupSessions: function(window, isAfterCrash) {
+ let sm = window.TabmixSessionManager;
+ let notify;
+
+ let isSessionWithGroups = path => {
+ if (sm.containerEmpty(path)) {
+ return false;
+ }
+ let sessionContainer = sm.initContainer(path);
+ let sessionEnum = sessionContainer.GetElements();
+ while (sessionEnum.hasMoreElements()) {
+ let rdfNodeSession = sessionEnum.getNext();
+ if (rdfNodeSession instanceof Ci.nsIRDFResource) {
+ let windowPath = rdfNodeSession.QueryInterface(Ci.nsIRDFResource).Value;
+ if (sm.nodeHasArc(windowPath, "dontLoad")) {
+ continue;
+ }
+ let data = sm.getLiteralValue(windowPath, "tabview-groups", "{}");
+ let parsedData = TabmixSvc.JSON.parse(data);
+ if (parsedData.totalNumber > 1) {
+ notify = true;
+ return true;
+ }
+ }
+ }
+ return false;
+ };
+
+ let string = s => TabmixSvc.getSMString("sm.tabview.backup." + s);
+ let saveSessions = (type, index) => {
+ let session = sm.gSessionPath[index];
+ if (!isSessionWithGroups(session)) {
+ return;
+ }
+ sm.saveClosedSession({
+ session: session,
+ name: {name: string(type)},
+ nameExt: sm.getLiteralValue(session, "nameExt", ""),
+ button: -1
+ });
+ };
+
+ try {
+ // we run this function before preparAfterCrash and prepareSavedSessions
+ // we need to backup 2 last session, if last session was crashed backup
+ // one more older session
+ let index = isAfterCrash ? 1 : 0;
+ saveSessions("session", index + 1);
+ saveSessions("session", index);
+ if (isAfterCrash) {
+ saveSessions("crashed", 0);
+ }
+ if (notify) {
+ this.missingTabViewNotification(window, string("msg"));
+ }
+ } catch (ex) {
+ TabmixSvc.console.assert(ex);
+ }
+ },
+
+ missingTabViewNotification: function(win, backup = "") {
+ let string = s => TabmixSvc.getSMString("sm.tabview." + s);
+ let doc = win.document;
+
+ // If there's already an existing notification bar, don't do anything.
+ let notificationBox = doc.getElementById("high-priority-global-notificationbox") ||
+ doc.getElementById("global-notificationbox");
+ let notification = notificationBox.getNotificationWithValue("tabmix-missing-tabview");
+ if (notification) {
+ if (notification.tabmixSavedBackup) {
+ notification.label += " " + string("hiddengroups");
+ delete notification.tabmixSavedBackup;
+ }
+ return;
+ }
+
+ let message = backup || string("hiddengroups");
+ let buttons = [{
+ label: string("install.label"),
+ accessKey: string("install.accesskey"),
+ callback: function() {
+ let link = TabmixSvc.isPaleMoon ?
+ "http://www.palemoon.org/tabgroups.shtml" :
+ "https://addons.mozilla.org/en-US/firefox/addon/tab-groups-panorama/";
+ win.openUILinkIn(link, "tab");
+ }
+ }];
+
+ if (!TabmixSvc.isPaleMoon) {
+ buttons.push({
+ label: string("removed.learnMore.label"),
+ accessKey: string("removed.learnMore.accesskey"),
+ callback: function() {
+ win.openUILinkIn("http://tabmixplus.org/support/viewpage.php?t=2&p=tab-groups-removal", "tab");
+ }
+ });
+ message = string("removed") + " " + message;
+ }
+
+ notification = notificationBox.appendNotification(
+ message,
+ "tabmix-missing-tabview",
+ "chrome://tabmixplus/skin/tmpsmall.png",
+ notificationBox.PRIORITY_WARNING_MEDIUM,
+ buttons
+ );
+ if (backup) {
+ notification.tabmixSavedBackup = true;
+ }
+ },
+};
--
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