save: Add possibility to mark things dirty on add.
KeyConfig needs this feature, because it can fix some deprecated commands during __init__ and emit its dirty-signal, but that happens before the saveable is added.
This commit is contained in:
parent
630a827afc
commit
ac63fc073f
@ -22,7 +22,7 @@
|
|||||||
import os.path
|
import os.path
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot, QObject
|
from PyQt5.QtCore import pyqtSlot, QObject, QTimer
|
||||||
|
|
||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
from qutebrowser.commands import cmdutils
|
from qutebrowser.commands import cmdutils
|
||||||
@ -139,7 +139,7 @@ class SaveManager(QObject):
|
|||||||
self._save_timer.start()
|
self._save_timer.start()
|
||||||
|
|
||||||
def add_saveable(self, name, save, changed=None, config_opt=None,
|
def add_saveable(self, name, save, changed=None, config_opt=None,
|
||||||
filename=None):
|
filename=None, dirty=False):
|
||||||
"""Add a new saveable.
|
"""Add a new saveable.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -150,11 +150,15 @@ class SaveManager(QObject):
|
|||||||
or not.
|
or not.
|
||||||
filename: The filename of the underlying file, so we can force
|
filename: The filename of the underlying file, so we can force
|
||||||
saving if it doesn't exist.
|
saving if it doesn't exist.
|
||||||
|
dirty: Whether the saveable is already dirty.
|
||||||
"""
|
"""
|
||||||
if name in self.saveables:
|
if name in self.saveables:
|
||||||
raise ValueError("Saveable {} already registered!".format(name))
|
raise ValueError("Saveable {} already registered!".format(name))
|
||||||
self.saveables[name] = Saveable(name, save, changed, config_opt,
|
saveable = Saveable(name, save, changed, config_opt, filename)
|
||||||
filename)
|
self.saveables[name] = saveable
|
||||||
|
if dirty:
|
||||||
|
saveable.mark_dirty()
|
||||||
|
QTimer.singleShot(0, saveable.save)
|
||||||
|
|
||||||
def save(self, name, is_exit=False, explicit=False, silent=False,
|
def save(self, name, is_exit=False, explicit=False, silent=False,
|
||||||
force=False):
|
force=False):
|
||||||
|
Loading…
Reference in New Issue
Block a user