Make saving in autoconfig.yml work
This commit is contained in:
parent
4691753965
commit
6abb42a066
@ -415,8 +415,8 @@ class Config(QObject):
|
||||
file.
|
||||
"""
|
||||
for name, values in self._values.items():
|
||||
cleared = values.clear()
|
||||
if cleared:
|
||||
if values:
|
||||
values.clear()
|
||||
self.changed.emit(name)
|
||||
|
||||
if save_yaml:
|
||||
|
@ -115,10 +115,17 @@ class YamlConfig(QObject):
|
||||
if not self._dirty:
|
||||
return
|
||||
|
||||
data = {'config_version': self.VERSION, 'global': self._values}
|
||||
for pattern, values in sorted(self._values.items()):
|
||||
data[str(pattern)] = values
|
||||
settings = {}
|
||||
for name, values in sorted(self._values.items()):
|
||||
if not values:
|
||||
continue
|
||||
settings[name] = {}
|
||||
for scoped in values:
|
||||
key = ('global' if scoped.pattern is None
|
||||
else str(scoped.pattern))
|
||||
settings[name][key] = scoped.value
|
||||
|
||||
data = {'config_version': self.VERSION, 'settings': settings}
|
||||
with qtutils.savefile_open(self._filename) as f:
|
||||
f.write(textwrap.dedent("""
|
||||
# DO NOT edit this file by hand, qutebrowser will overwrite it.
|
||||
@ -231,6 +238,7 @@ class YamlConfig(QObject):
|
||||
def set_obj(self, name, value, *, pattern=None):
|
||||
"""Set the given setting to the given value."""
|
||||
self._values[name].add(value, pattern)
|
||||
self._mark_changed()
|
||||
|
||||
def unset(self, name, *, pattern=None):
|
||||
"""Remove the given option name if it's configured."""
|
||||
|
@ -73,6 +73,10 @@ class Values:
|
||||
"""
|
||||
yield from self._values
|
||||
|
||||
def __bool__(self):
|
||||
"""Check whether this value is customized."""
|
||||
return bool(self._values)
|
||||
|
||||
def add(self, value, pattern=None):
|
||||
"""Add a value with the given pattern to the list of values.
|
||||
|
||||
@ -92,9 +96,7 @@ class Values:
|
||||
|
||||
def clear(self):
|
||||
"""Clear all customization for this value."""
|
||||
had_values = bool(self._values)
|
||||
self._values = []
|
||||
return had_values
|
||||
|
||||
def _get_fallback(self):
|
||||
"""Get the fallback global/default value."""
|
||||
|
Loading…
Reference in New Issue
Block a user