[Pkg-mozext-commits] [tabmixplus] 81/123: Add new options "Restore my pinned tabs from last time" when user preference is not to restore when Firefox starts
David Prévot
taffit at moszumanska.debian.org
Wed Sep 17 21:16:29 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository tabmixplus.
commit d829c20f2c1931cd939525752b25101cb4a83d8a
Author: onemen <tabmix.onemen at gmail.com>
Date: Fri Sep 5 23:20:22 2014 +0300
Add new options "Restore my pinned tabs from last time" when user preference is not to restore when Firefox starts
---
chrome/content/links/setup.js | 13 ++---
chrome/content/preferences/session.xul | 4 ++
chrome/content/session/session.js | 95 ++++++++++++++++++++++++++--------
defaults/preferences/tabmix.js | 1 +
4 files changed, 86 insertions(+), 27 deletions(-)
diff --git a/chrome/content/links/setup.js b/chrome/content/links/setup.js
index 70a5918..b475844 100644
--- a/chrome/content/links/setup.js
+++ b/chrome/content/links/setup.js
@@ -111,11 +111,13 @@ Tabmix.beforeBrowserInitOnLoad = function() {
this.prefs.getBoolPref("sessions.crashRecovery") &&
this.prefs.prefHasUserValue("sessions.crashed"));
var notRestore = firstWindow && !disabled && sessionManager &&
- this.prefs.getIntPref("sessions.onStart") > 1;
+ this.prefs.getIntPref("sessions.onStart") > 1 &&
+ (!this.prefs.getBoolPref("sessions.onStart.restorePinned") ||
+ this.prefs.getBoolPref("sessions.restore.concatenate"));
// Set SessionStore._loadState to running on first window in the session
- // to prevent it from restoring pinned tabs.
- let setStateRunning = Tabmix.isVersion(250) && (willRestore || notRestore) &&
+ // to prevent it from restoring last session or pinned tabs.
+ let setStateRunning = (willRestore || notRestore) &&
this.firstWindowInSession && !this.isWindowAfterSessionRestore;
if (setStateRunning) {
let STATE_STOPPED = 0;
@@ -126,8 +128,7 @@ Tabmix.beforeBrowserInitOnLoad = function() {
}
}
- var afterSessionRestore = !this.isVersion(250) && this.isWindowAfterSessionRestore;
- SM.doRestore = willRestore && !(SM.isPrivateWindow || afterSessionRestore);
+ var prepareLoadOnStartup = willRestore && !(SM.isPrivateWindow || this.isWindowAfterSessionRestore);
var willOverrideHomepage = willRestore && !SM.isPrivateWindow;
if (willOverrideHomepage) {
// Prevent the default homepage from loading if we're going to restore a session
@@ -142,7 +143,7 @@ Tabmix.beforeBrowserInitOnLoad = function() {
}
}
- if (SM.doRestore) {
+ if (prepareLoadOnStartup) {
// move this code from gBrowserInit.onLoad to gBrowserInit._delayedStartup after bug 756313
loadOnStartup =
' if (uriToLoad && uriToLoad != "about:blank") {' +
diff --git a/chrome/content/preferences/session.xul b/chrome/content/preferences/session.xul
index e592cbd..1e573a4 100644
--- a/chrome/content/preferences/session.xul
+++ b/chrome/content/preferences/session.xul
@@ -54,6 +54,8 @@
name="extensions.tabmix.sessions.onStart.sessionpath" type="string"/>
<preference id="pref_onStart.empty"
name="extensions.tabmix.sessions.onStart.askifempty" type="bool"/>
+ <preference id="pref_onStart.restorePinned"
+ name="extensions.tabmix.sessions.onStart.restorePinned" type="bool"/>
<preference id="pref_onRestore.overwritewindows"
name="extensions.tabmix.sessions.restore.overwritewindows" type="bool"/>
<preference id="pref_onRestore.overwritetabs"
@@ -191,6 +193,8 @@
</menupopup>
</menulist>
</hbox>
+ <checkbox_tmp id="onStart.restorePinned" class="indent" label="Restore my pinned tabs from last time"
+ preference="pref_onStart.restorePinned"/>
</groupbox>
</tabpanel>
<!-- Tabmix Session manager - restore -->
diff --git a/chrome/content/session/session.js b/chrome/content/session/session.js
index 3a70c90..975a9b7 100644
--- a/chrome/content/session/session.js
+++ b/chrome/content/session/session.js
@@ -260,29 +260,20 @@ var TabmixSessionManager = {
return;
this._inited = true;
- if (Tabmix.isVersion(250) && !TabmixSvc.sm.promiseInitialized) {
- let initializeSM = function() {
- TabmixSvc.sm.promiseInitialized = true;
- this._init();
+ let initializeSM = function() {
+ TabmixSvc.sm.promiseInitialized = true;
+ this._init();
+ if (this.notifyObservers)
this._sendRestoreCompletedNotifications(false);
- }.bind(this);
+ }.bind(this);
+
+ if (Tabmix.isVersion(250) && !TabmixSvc.sm.promiseInitialized) {
Tabmix.ssPromise = aPromise || TabmixSvc.ss.promiseInitialized;
Tabmix.ssPromise.then(initializeSM)
.then(null, Cu.reportError);
}
- else {
- let forceInit = !Tabmix.isVersion(250) && this.doRestore;
- // make sure sessionstore initialize without restoring pinned tabs
- // for Firefox 25+ we set SessionStore._loadState = STATE_RUNNING
- if (forceInit)
- TabmixSvc.ss.init(null);
- this._init();
- // restart-less extensions observers for this notification on startup
- // notify observers things are complete when we call SessionStore.init
- // with null.
- if (Tabmix.isVersion(250) && this.firstNonPrivateWindow || forceInit)
- this._sendRestoreCompletedNotifications(false);
- }
+ else
+ initializeSM();
},
_init: function SM__init() {
@@ -770,7 +761,7 @@ var TabmixSessionManager = {
this.overrideHomepage = null;
},
- loadHomePage: function SM_loadHomePage() {
+ loadHomePage: function SM_loadHomePage(addTab) {
function afterLoad(aBrowser) {
if (!gBrowser.isBlankBrowser(aBrowser))
aBrowser.focus();
@@ -785,7 +776,7 @@ var TabmixSessionManager = {
// This function throws for certain malformed URIs, so use exception handling
// so that we don't disrupt startup
try {
- gBrowser.loadTabs(URIs, false, true);
+ gBrowser.loadTabs(URIs, false, !addTab);
} catch (e) { afterLoad(gBrowser.selectedBrowser); }
}
else
@@ -2142,7 +2133,7 @@ if (container == "error") { Tabmix.log("wrapContainer error path " + path + "\n"
default:
}
} else
- this.loadHomePage();
+ this.deferredRestore(true);
this.saveStateDelayed();
delete this.callBackData;
@@ -2200,6 +2191,10 @@ if (container == "error") { Tabmix.log("wrapContainer error path " + path + "\n"
// else if loadsession < 0 the session path is saved in this.gSessionPath
var restoreFlag = this.prefBranch.getIntPref("onStart");
if (restoreFlag > 1) {
+ // merege pinned tabs from all windows into one, other cases
+ // handled by SessionStore
+ if (this.prefBranch.getBoolPref("restore.concatenate"))
+ this.deferredRestore();
return; // Don't Restore
}
var loadSession = this.prefBranch.getIntPref("onStart.loadsession");
@@ -2310,7 +2305,10 @@ try{
this.enableCrashRecovery(aResult);
if (aResult.button == Tabmix.BUTTON_OK)
this.loadSession(aResult.label, "firstwindowopen", !this.firstNonPrivateWindow);
+ else if (this.waitForCallBack)
+ this.deferredRestore();
else
+ // we are here not after a callback only when the stratup file is empty
this.loadHomePage();
this.saveStateDelayed();
@@ -2322,6 +2320,61 @@ try{
this._sendRestoreCompletedNotifications(true);
},
+ /**
+ * user wants to restore only pinned tabs
+ * use SessionStore functions to prepare and restore
+ */
+ deferredRestore: function(afterCrash) {
+ if (!this.prefBranch.getBoolPref("onStart.restorePinned"))
+ return;
+
+ let state = TabmixConvertSession.getSessionState(this.gSessionPath[1]);
+ let [iniState, remainingState] = this.SessionStore._prepDataForDeferredRestore(state);
+ let pinnedExist = iniState.windows.length > 0;
+ if (pinnedExist) {
+ // move all tabs and closed tabs into one window
+ if (!afterCrash && (Tabmix.prefs.getBoolPref("singleWindow") ||
+ this.prefBranch.getBoolPref("restore.concatenate"))) {
+ this.mergeWindows(iniState);
+ }
+ let overwrite = this.SessionStore._isCmdLineEmpty(window, iniState);
+ if (Tabmix.isVersion(260)) {
+ let options = {firstWindow: true, overwriteTabs: overwrite};
+ this.SessionStore.restoreWindow(window, iniState, options);
+ }
+ else {
+ iniState._firstTabs = true;
+ this.SessionStore.restoreWindow(window, iniState, overwrite);
+ }
+ }
+ this.loadHomePage(pinnedExist);
+ },
+
+ /**
+ * move all tabs & closed tabs into one window
+ * (original code by Session Manager extension)
+ */
+ mergeWindows: function(state){
+ if (state.windows.length < 2)
+ return;
+ // take off first window
+ let win = state.windows.shift();
+ // make sure toolbars are not hidden on the window
+ delete win.hidden;
+ delete win.isPopup;
+ if (!win._closedTabs)
+ win._closedTabs = [];
+ // Move tabs to first window
+ state.windows.forEach(function(aWindow) {
+ win.tabs = win.tabs.concat(aWindow.tabs);
+ if (aWindow._closedTabs)
+ win._closedTabs = win._closedTabs.concat(aWindow._closedTabs);
+ });
+ win._closedTabs.splice(Services.prefs.getIntPref("browser.sessionstore.max_tabs_undo"));
+ // Remove all but first window
+ state.windows = [win];
+ },
+
_sendRestoreCompletedNotifications: function(waitForCallBack) {
// notify observers things are complete.
// we send sessionstore-windows-restored notification as soon as _init
diff --git a/defaults/preferences/tabmix.js b/defaults/preferences/tabmix.js
index 0c828f8..0bc54da 100644
--- a/defaults/preferences/tabmix.js
+++ b/defaults/preferences/tabmix.js
@@ -248,6 +248,7 @@ pref("extensions.tabmix.sessions.onStart", 2);
pref("extensions.tabmix.sessions.onStart.askifempty", true);
pref("extensions.tabmix.sessions.onStart.loadsession", -1);
pref("extensions.tabmix.sessions.onStart.sessionpath", "");
+pref("extensions.tabmix.sessions.onStart.restorePinned", true);
//pref("extensions.tabmix.sessions.version", ""); removed on 2013-02-05 - not in use
pref("extensions.tabmix.autoReloadContent", 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