diff options
author | hut <hut@lavabit.com> | 2013-03-16 19:13:46 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2013-03-16 19:18:25 +0100 |
commit | 1f5a29d42745f0ae7c37a96339e8df0185d5f3dd (patch) | |
tree | e0b1e7e79959ed0c7d45ed32b53cd6c96931bf5e /ranger | |
parent | 8a5944e1bd52dd749c34a5b4eda401902531175a (diff) | |
download | ranger-1f5a29d42745f0ae7c37a96339e8df0185d5f3dd.tar.gz |
settings: sanitize in separate signal with higher priority
Some signals may require the sanitized value BEFORE it is actually set with settings._raw_set. We need to separate sanitizing and _raw_set into separate signals so other signals can be bound in between those two.
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/container/settings.py | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/ranger/container/settings.py b/ranger/container/settings.py index 2ca77d07..85480d1b 100644 --- a/ranger/container/settings.py +++ b/ranger/container/settings.py @@ -72,29 +72,32 @@ class Settings(SignalDispatcher, FileManagerAware): self.__dict__['_settings'] = dict() for name in ALLOWED_SETTINGS: self.signal_bind('setopt.'+name, + self._sanitize, priority=1.0) + self.signal_bind('setopt.'+name, self._raw_set_with_signal, priority=0.2) - def _sanitize(self, name, value): + def _sanitize(self, signal): + name, value = signal.setting, signal.value if name == 'column_ratios': # TODO: cover more cases here if isinstance(value, tuple): - return list(value) + signal.value = list(value) if not isinstance(value, list) or len(value) < 2: - return [1, 1] + signal.value = [1, 1] else: - return [int(i) if str(i).isdigit() else 1 for i in value] + signal.value = [int(i) if str(i).isdigit() else 1 \ + for i in value] elif name == 'colorscheme': - signal = Signal(value=value, previous="Penis", fm=self.fm) _colorscheme_name_to_class(signal) - return signal.value elif name == 'preview_script': if isinstance(value, str): result = os.path.expanduser(value) if os.path.exists(result): - return result - return None + signal.value = result + else: + signal.value = None elif name == 'use_preview_script': if self._settings['preview_script'] is None and value \ @@ -102,9 +105,6 @@ class Settings(SignalDispatcher, FileManagerAware): self.fm.notify("Preview script undefined or not found!", bad=True) - # fallback: - return value - def set(self, name, value, path=None): assert name in ALLOWED_SETTINGS, "No such setting: {0}!".format(name) if name not in self._settings: @@ -183,7 +183,6 @@ class Settings(SignalDispatcher, FileManagerAware): __setitem__ = __setattr__ def _raw_set(self, name, value, path): - value = self._sanitize(name, value) if path: if not path in self._localsettings: try: |