Merge branch 'session-save-only-active-window' of https://github.com/danfis/qutebrowser into danfis-session-save-only-active-window

This commit is contained in:
Florian Bruhin 2017-02-25 17:55:42 +01:00
commit fc2250b3b2
4 changed files with 47 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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,6 +466,9 @@ class SessionManager(QObject):
name = self._current
assert not name.startswith('_')
try:
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: {}"

View File

@ -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