From cd14cbbfb89db81113c642ed76f0e67e7cffa51b Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 12 Sep 2014 17:20:47 +0200 Subject: [PATCH] Handle changed config correctly for interpolated values. --- qutebrowser/config/config.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 986afd62f..33b26787f 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -229,6 +229,29 @@ class ConfigManager(QObject): e.option = k raise + def _emit_changed(self, sectname, optname): + """Emit the appropriate signals for a changed config option.""" + log.misc.debug("Config option changed: {} -> {}".format( + sectname, optname)) + if sectname in ('colors', 'fonts'): + self.style_changed.emit(sectname, optname) + self.changed.emit(sectname, optname) + + def _after_set(self, changed_sect, changed_opt): + """Clean up caches and emit signals after an option has been set.""" + self.get.cache_clear() + self._emit_changed(changed_sect, changed_opt) + # Options in the same section and ${optname} interpolation. + for optname, option in self.sections[changed_sect].items(): + if '${' + changed_opt + '}' in option.value(): + self._emit_changed(changed_sect, optname) + # Options in any section and ${sectname:optname} interpolation. + for sectname, section in self.sections.items(): + for optname, option in section.items(): + if ('${' + changed_sect + ':' + changed_opt + '}' in + option.value()): + self._emit_changed(sectname, optname) + def items(self, sectname, raw=True): """Get a list of (optname, value) tuples for a section. @@ -411,10 +434,7 @@ class ConfigManager(QObject): except KeyError: raise NoOptionError(optname, sectname) else: - self.get.cache_clear() - if sectname in ('colors', 'fonts'): - self.style_changed.emit(sectname, optname) - self.changed.emit(sectname, optname) + self._after_set(sectname, optname) @cmdutils.register(instance='config') def save(self):