summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2017-02-25 17:56:27 +0100
committerFlorian Bruhin <git@the-compiler.org>2017-02-25 17:56:27 +0100
commitf1ecb21d3dcecdcccde82bdbc8b27df998fb6e15 (patch)
tree105b0c7c9b93b68233cc2bd510759b60238df1ab
parent1bd9b4cd409428763f7b2b1c2a5bb4b6f5f24ef4 (diff)
parentd771f1f89ecee10b415503044794fe85560efc43 (diff)
downloadqutebrowser-f1ecb21d3dcecdcccde82bdbc8b27df998fb6e15.tar.gz
qutebrowser-f1ecb21d3dcecdcccde82bdbc8b27df998fb6e15.zip
Merge branch 'danfis-session-save-only-active-window'
-rw-r--r--CHANGELOG.asciidoc1
-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
5 files changed, 48 insertions, 7 deletions
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index fc24cc4b5..4a2152e38 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -34,6 +34,7 @@ Added
- New `qute:history` URL and `:history` command to show the browsing history.
- Open tabs are now auto-saved on each successful load and restored in case of a crash.
- `:jseval` now has a `--file` flag so you can pass a javascript file
+- `:session-save` now has a `--only-active-window` flag to only save the active window.
Changed
~~~~~~~
diff --git a/README.asciidoc b/README.asciidoc
index 67444c9fb..3b2db5e3f 100644
--- a/README.asciidoc
+++ b/README.asciidoc
@@ -195,6 +195,7 @@ Contributors, sorted by the number of commits in descending order:
* error800
* Michael Hoang
* Liam BEGUIN
+* Daniel Fiser
* skinnay
* Zach-Button
* Samuel Walladge
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