Re-add save-session setting.
This commit is contained in:
parent
56b0ae2b6e
commit
5b33f6c5fe
@ -20,6 +20,7 @@
|
|||||||
|<<general-default-encoding,default-encoding>>|Default encoding to use for websites.
|
|<<general-default-encoding,default-encoding>>|Default encoding to use for websites.
|
||||||
|<<general-new-instance-open-target,new-instance-open-target>>|How to open links in an existing instance if a new one is launched.
|
|<<general-new-instance-open-target,new-instance-open-target>>|How to open links in an existing instance if a new one is launched.
|
||||||
|<<general-log-javascript-console,log-javascript-console>>|Whether to log javascript console messages.
|
|<<general-log-javascript-console,log-javascript-console>>|Whether to log javascript console messages.
|
||||||
|
|<<general-save-session,save-session>>|Whether to always save the open pages.
|
||||||
|==============
|
|==============
|
||||||
|
|
||||||
.Quick reference for section ``ui''
|
.Quick reference for section ``ui''
|
||||||
@ -386,6 +387,17 @@ Valid values:
|
|||||||
|
|
||||||
Default: +pass:[false]+
|
Default: +pass:[false]+
|
||||||
|
|
||||||
|
[[general-save-session]]
|
||||||
|
=== save-session
|
||||||
|
Whether to always save the open pages.
|
||||||
|
|
||||||
|
Valid values:
|
||||||
|
|
||||||
|
* +true+
|
||||||
|
* +false+
|
||||||
|
|
||||||
|
Default: +pass:[false]+
|
||||||
|
|
||||||
== ui
|
== ui
|
||||||
General options related to the user interface.
|
General options related to the user interface.
|
||||||
|
|
||||||
|
@ -430,7 +430,7 @@ class Application(QApplication):
|
|||||||
def _connect_signals(self):
|
def _connect_signals(self):
|
||||||
"""Connect all signals to their slots."""
|
"""Connect all signals to their slots."""
|
||||||
config_obj = objreg.get('config')
|
config_obj = objreg.get('config')
|
||||||
self.lastWindowClosed.connect(self.shutdown)
|
self.lastWindowClosed.connect(self.on_last_window_closed)
|
||||||
config_obj.style_changed.connect(style.get_stylesheet.cache_clear)
|
config_obj.style_changed.connect(style.get_stylesheet.cache_clear)
|
||||||
self.focusChanged.connect(self.on_focus_changed)
|
self.focusChanged.connect(self.on_focus_changed)
|
||||||
|
|
||||||
@ -589,7 +589,7 @@ class Application(QApplication):
|
|||||||
log.destroy.exception("Error while ignoring ipc")
|
log.destroy.exception("Error while ignoring ipc")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.lastWindowClosed.disconnect(self.shutdown)
|
self.lastWindowClosed.disconnect(self.on_last_window_closed)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
log.destroy.exception("Error while preventing shutdown")
|
log.destroy.exception("Error while preventing shutdown")
|
||||||
QApplication.closeAllWindows()
|
QApplication.closeAllWindows()
|
||||||
@ -605,11 +605,6 @@ class Application(QApplication):
|
|||||||
self._destroy_crashlogfile()
|
self._destroy_crashlogfile()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@cmdutils.register(instance='app', name=['quit', 'q'])
|
|
||||||
def quit(self):
|
|
||||||
"""Quit qutebrowser."""
|
|
||||||
QApplication.closeAllWindows()
|
|
||||||
|
|
||||||
def _get_restart_args(self, pages):
|
def _get_restart_args(self, pages):
|
||||||
"""Get the current working directory and args to relaunch qutebrowser.
|
"""Get the current working directory and args to relaunch qutebrowser.
|
||||||
|
|
||||||
@ -742,20 +737,41 @@ class Application(QApplication):
|
|||||||
log.destroy.info("WHY ARE YOU DOING THIS TO ME? :(")
|
log.destroy.info("WHY ARE YOU DOING THIS TO ME? :(")
|
||||||
sys.exit(128 + signum)
|
sys.exit(128 + signum)
|
||||||
|
|
||||||
@pyqtSlot()
|
@cmdutils.register(instance='app', name='wq',
|
||||||
def shutdown(self, status=0):
|
completion=[usertypes.Completion.sessions])
|
||||||
"""Try to shutdown everything cleanly.
|
def save_and_quit(self, name='default'):
|
||||||
|
"""Save open pages and quit.
|
||||||
|
|
||||||
For some reason lastWindowClosing sometimes seem to get emitted twice,
|
Args:
|
||||||
so we make sure we only run once here.
|
name: The name of the session.
|
||||||
|
"""
|
||||||
|
self.shutdown(session=name)
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def on_last_window_closed(self):
|
||||||
|
"""Slot which gets invoked when the last window was closed."""
|
||||||
|
self.shutdown(last_window=True)
|
||||||
|
|
||||||
|
@cmdutils.register(instance='app', name=['quit', 'q'], ignore_args=True)
|
||||||
|
def shutdown(self, status=0, session=None, last_window=False):
|
||||||
|
"""Quit qutebrowser.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
status: The status code to exit with.
|
status: The status code to exit with.
|
||||||
|
session: A session name if saving should be forced.
|
||||||
|
last_window: If the shutdown was triggered due to the last window
|
||||||
|
closing.
|
||||||
"""
|
"""
|
||||||
if self._shutting_down:
|
if self._shutting_down:
|
||||||
return
|
return
|
||||||
self._shutting_down = True
|
self._shutting_down = True
|
||||||
log.destroy.debug("Shutting down with status {}...".format(status))
|
log.destroy.debug("Shutting down with status {}, session {}..."
|
||||||
|
.format(status, session))
|
||||||
|
session_manager = objreg.get('session-manager')
|
||||||
|
if session is not None:
|
||||||
|
session_manager.save(session, last_window=last_window)
|
||||||
|
elif config.get('general', 'save-session'):
|
||||||
|
session_manager.save('default', last_window=last_window)
|
||||||
deferrer = False
|
deferrer = False
|
||||||
for win_id in objreg.window_registry:
|
for win_id in objreg.window_registry:
|
||||||
prompter = objreg.get('prompter', None, scope='window',
|
prompter = objreg.get('prompter', None, scope='window',
|
||||||
|
@ -193,6 +193,10 @@ DATA = collections.OrderedDict([
|
|||||||
('log-javascript-console',
|
('log-javascript-console',
|
||||||
SettingValue(typ.Bool(), 'false'),
|
SettingValue(typ.Bool(), 'false'),
|
||||||
"Whether to log javascript console messages."),
|
"Whether to log javascript console messages."),
|
||||||
|
|
||||||
|
('save-session',
|
||||||
|
SettingValue(typ.Bool(), 'false'),
|
||||||
|
"Whether to always save the open pages."),
|
||||||
)),
|
)),
|
||||||
|
|
||||||
('ui', sect.KeyValue(
|
('ui', sect.KeyValue(
|
||||||
|
@ -364,6 +364,8 @@ class MainWindow(QWidget):
|
|||||||
e.ignore()
|
e.ignore()
|
||||||
return
|
return
|
||||||
e.accept()
|
e.accept()
|
||||||
|
if len(objreg.window_registry) == 1:
|
||||||
|
objreg.get('session-manager').save_last_window_session()
|
||||||
objreg.get('app').geometry = bytes(self.saveGeometry())
|
objreg.get('app').geometry = bytes(self.saveGeometry())
|
||||||
log.destroy.debug("Closing window {}".format(self.win_id))
|
log.destroy.debug("Closing window {}".format(self.win_id))
|
||||||
self._tabbed_browser.shutdown()
|
self._tabbed_browser.shutdown()
|
||||||
|
@ -53,6 +53,8 @@ class SessionManager(QObject):
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
_base_path: The path to store sessions under.
|
_base_path: The path to store sessions under.
|
||||||
|
_last_window_session: The session data of the last window which was
|
||||||
|
closed.
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
update_completion: Emitted when the session completion should get
|
update_completion: Emitted when the session completion should get
|
||||||
@ -65,6 +67,7 @@ class SessionManager(QObject):
|
|||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._base_path = os.path.join(
|
self._base_path = os.path.join(
|
||||||
standarddir.get(QStandardPaths.DataLocation), 'sessions')
|
standarddir.get(QStandardPaths.DataLocation), 'sessions')
|
||||||
|
self._last_window_session = None
|
||||||
if not os.path.exists(self._base_path):
|
if not os.path.exists(self._base_path):
|
||||||
os.mkdir(self._base_path)
|
os.mkdir(self._base_path)
|
||||||
|
|
||||||
@ -153,12 +156,21 @@ class SessionManager(QObject):
|
|||||||
data['windows'].append(win_data)
|
data['windows'].append(win_data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def save(self, name):
|
def save(self, name, last_window=False):
|
||||||
"""Save a named session."""
|
"""Save a named session.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
last_window: If set, saves the saved self._last_window_session
|
||||||
|
instead of the currently open state.
|
||||||
|
"""
|
||||||
path = self._get_session_path(name)
|
path = self._get_session_path(name)
|
||||||
|
|
||||||
log.misc.debug("Saving session {} to {}...".format(name, path))
|
log.misc.debug("Saving session {} to {}...".format(name, path))
|
||||||
data = self._save_all()
|
if last_window:
|
||||||
|
data = self._last_window_session
|
||||||
|
assert data is not None
|
||||||
|
else:
|
||||||
|
data = self._save_all()
|
||||||
log.misc.vdebug("Saving data: {}".format(data))
|
log.misc.vdebug("Saving data: {}".format(data))
|
||||||
try:
|
try:
|
||||||
with qtutils.savefile_open(path) as f:
|
with qtutils.savefile_open(path) as f:
|
||||||
@ -169,6 +181,10 @@ class SessionManager(QObject):
|
|||||||
else:
|
else:
|
||||||
self.update_completion.emit()
|
self.update_completion.emit()
|
||||||
|
|
||||||
|
def save_last_window_session(self):
|
||||||
|
"""Temporarily save the session for the last closed window."""
|
||||||
|
self._last_window_session = self._save_all()
|
||||||
|
|
||||||
def _load_tab(self, new_tab, data):
|
def _load_tab(self, new_tab, data):
|
||||||
"""Load yaml data into a newly opened tab."""
|
"""Load yaml data into a newly opened tab."""
|
||||||
entries = []
|
entries = []
|
||||||
@ -268,17 +284,6 @@ class SessionManager(QObject):
|
|||||||
raise cmdexc.CommandError("Error while saving session: {}"
|
raise cmdexc.CommandError("Error while saving session: {}"
|
||||||
.format(e))
|
.format(e))
|
||||||
|
|
||||||
@cmdutils.register(name='wq', completion=[usertypes.Completion.sessions],
|
|
||||||
instance='session-manager')
|
|
||||||
def save_and_quit(self, name='default'):
|
|
||||||
"""Save open pages and quit.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
name: The name of the session.
|
|
||||||
"""
|
|
||||||
self.session_save(name)
|
|
||||||
QApplication.closeAllWindows()
|
|
||||||
|
|
||||||
@cmdutils.register(completion=[usertypes.Completion.sessions],
|
@cmdutils.register(completion=[usertypes.Completion.sessions],
|
||||||
instance='session-manager')
|
instance='session-manager')
|
||||||
def session_delete(self, name):
|
def session_delete(self, name):
|
||||||
|
Loading…
Reference in New Issue
Block a user