summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2017-02-25 17:55:42 +0100
committerFlorian Bruhin <git@the-compiler.org>2017-02-25 17:55:42 +0100
commitfc2250b3b2740bbf5ce216655ad21b9d965c5fc4 (patch)
treeead4731660785667863e2f9e5f5fcc38cba79da4
parent1bd9b4cd409428763f7b2b1c2a5bb4b6f5f24ef4 (diff)
parent81a24bdbef832dd40f8e0c5d0bc2b485f9ac0bc2 (diff)
downloadqutebrowser-fc2250b3b2740bbf5ce216655ad21b9d965c5fc4.tar.gz
qutebrowser-fc2250b3b2740bbf5ce216655ad21b9d965c5fc4.zip
Merge branch 'session-save-only-active-window' of https://github.com/danfis/qutebrowser into danfis-session-save-only-active-window
-rw-r--r--README.asciidoc1
-rw-r--r--doc/help/commands.asciidoc4
-rw-r--r--qutebrowser/misc/sessions.py24
-rw-r--r--tests/end2end/features/sessions.feature25
4 files changed, 47 insertions, 7 deletions
diff --git a/README.asciidoc b/README.asciidoc
index 67444c9fb..a33855afc 100644
--- a/README.asciidoc
+++ b/README.asciidoc
@@ -243,6 +243,7 @@ Contributors, sorted by the number of commits in descending order:
* Jean-Louis Fuchs
* Franz Fellner
* Eric Drechsel
+* Daniel Fiser
* zwarag
* xd1le
* rmortens
diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc
index 77d7026c8..3f4eb4404 100644
--- a/doc/help/commands.asciidoc
+++ b/doc/help/commands.asciidoc
@@ -741,7 +741,8 @@ Load a session.
[[session-save]]
=== session-save
-Syntax: +:session-save [*--current*] [*--quiet*] [*--force*] ['name']+
+Syntax: +:session-save [*--current*] [*--quiet*] [*--force*] [*--only-active-window*]
+ ['name']+
Save a session.
@@ -753,6 +754,7 @@ Save a session.
* +*-c*+, +*--current*+: Save the current session instead of the default.
* +*-q*+, +*--quiet*+: Don't show confirmation message.
* +*-f*+, +*--force*+: Force saving internal sessions (starting with an underline).
+* +*-o*+, +*--only-active-window*+: Saves only tabs of the currently active window.
[[set]]
=== set
diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py
index e559475e3..6ad8358a6 100644
--- a/qutebrowser/misc/sessions.py
+++ b/qutebrowser/misc/sessions.py
@@ -213,10 +213,15 @@ class SessionManager(QObject):
data['history'].append(item_data)
return data
- def _save_all(self):
+ def _save_all(self, *, only_window=None):
"""Get a dict with data for all windows/tabs."""
data = {'windows': []}
- for win_id in objreg.window_registry:
+ if only_window is not None:
+ winlist = [only_window]
+ else:
+ winlist = objreg.window_registry
+
+ for win_id in winlist:
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
main_window = objreg.get('main-window', scope='window',
@@ -254,7 +259,8 @@ class SessionManager(QObject):
name = 'default'
return name
- def save(self, name, last_window=False, load_next_time=False):
+ def save(self, name, last_window=False, load_next_time=False,
+ only_window=None):
"""Save a named session.
Args:
@@ -263,6 +269,7 @@ class SessionManager(QObject):
last_window: If set, saves the saved self._last_window_session
instead of the currently open state.
load_next_time: If set, prepares this session to be load next time.
+ only_window: If set, only tabs in the specified window is saved.
Return:
The name of the saved session.
@@ -277,7 +284,7 @@ class SessionManager(QObject):
log.sessions.error("last_window_session is None while saving!")
return
else:
- data = self._save_all()
+ data = self._save_all(only_window=only_window)
log.sessions.vdebug("Saving data: {}".format(data))
try:
with qtutils.savefile_open(path) as f:
@@ -435,8 +442,9 @@ class SessionManager(QObject):
@cmdutils.register(name=['session-save', 'w'], instance='session-manager')
@cmdutils.argument('name', completion=usertypes.Completion.sessions)
+ @cmdutils.argument('win_id', win_id=True)
def session_save(self, name: str=default, current=False, quiet=False,
- force=False):
+ force=False, only_active_window=False, win_id=None):
"""Save a session.
Args:
@@ -445,6 +453,7 @@ class SessionManager(QObject):
current: Save the current session instead of the default.
quiet: Don't show confirmation message.
force: Force saving internal sessions (starting with an underline).
+ only_active_window: Saves only tabs of the currently active window.
"""
if (name is not default and
name.startswith('_') and # pylint: disable=no-member
@@ -457,7 +466,10 @@ class SessionManager(QObject):
name = self._current
assert not name.startswith('_')
try:
- name = self.save(name)
+ if only_active_window:
+ name = self.save(name, only_window=win_id)
+ else:
+ name = self.save(name)
except SessionError as e:
raise cmdexc.CommandError("Error while saving session: {}"
.format(e))
diff --git a/tests/end2end/features/sessions.feature b/tests/end2end/features/sessions.feature
index abb399453..bba8023c9 100644
--- a/tests/end2end/features/sessions.feature
+++ b/tests/end2end/features/sessions.feature
@@ -278,6 +278,31 @@ Feature: Saving and loading sessions
Then "Saved session quiet_session." should not be logged
And the session quiet_session should exist
+ Scenario: Saving session with --only-active-window
+ When I open data/numbers/1.txt
+ And I open data/numbers/2.txt in a new tab
+ And I open data/numbers/3.txt in a new window
+ And I open data/numbers/4.txt in a new tab
+ And I open data/numbers/5.txt in a new tab
+ And I run :session-save --only-active-window window_session_name
+ And I run :window-only
+ And I run :tab-only
+ And I run :session-load window_session_name
+ Then the session should look like:
+ windows:
+ - tabs:
+ - history:
+ - active: true
+ url: http://localhost:*/data/numbers/5.txt
+ - tabs:
+ - history:
+ - url: http://localhost:*/data/numbers/3.txt
+ - history:
+ - url: http://localhost:*/data/numbers/4.txt
+ - history:
+ - active: true
+ url: http://localhost:*/data/numbers/5.txt
+
# :session-delete
Scenario: Deleting a directory