:session-load: Add a -c/--clear argument.

See #523.
This commit is contained in:
Florian Bruhin 2015-03-30 07:09:16 +02:00
parent dff8f73a11
commit 33dff70357
2 changed files with 11 additions and 2 deletions

View File

@ -414,13 +414,16 @@ Delete a session.
[[session-load]]
=== session-load
Syntax: +:session-load 'name'+
Syntax: +:session-load [*--clear*] 'name'+
Load a session.
==== positional arguments
* +'name'+: The name of the session.
==== optional arguments
* +*-c*+, +*--clear*+: Close all existing windows.
[[session-save]]
=== session-save
Syntax: +:session-save [*--quiet*] ['name']+

View File

@ -266,12 +266,14 @@ class SessionManager(QObject):
@cmdutils.register(completion=[usertypes.Completion.sessions],
instance='session-manager')
def session_load(self, name):
def session_load(self, name, clear=False):
"""Load a session.
Args:
name: The name of the session.
clear: Close all existing windows.
"""
old_windows = list(objreg.window_registry.values())
try:
self.load(name)
except SessionNotFoundError:
@ -279,6 +281,10 @@ class SessionManager(QObject):
except SessionError as e:
raise cmdexc.CommandError("Error while loading session: {}"
.format(e))
else:
if clear:
for win in old_windows:
win.close()
@cmdutils.register(name=['session-save', 'w'],
completion=[usertypes.Completion.sessions],