summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2013-04-20 15:04:17 +0200
committerhut <hut@lavabit.com>2013-04-20 15:04:17 +0200
commit56278294cf6e50f70918bd47e6c1a58e1d050e7f (patch)
treeda00a4cc11c94653052f66e2343170cc9cb547d5 /ranger
parent63b6a8281b9e3e601d4a34819ed1622a7b40c243 (diff)
downloadranger-56278294cf6e50f70918bd47e6c1a58e1d050e7f.tar.gz
config/commands: implemented :setintag <tags> <option>=<value>
Diffstat (limited to 'ranger')
-rw-r--r--ranger/config/commands.py12
-rw-r--r--ranger/container/settings.py23
-rw-r--r--ranger/core/actions.py4
3 files changed, 32 insertions, 7 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 2d830a0f..4d290e7e 100644
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -368,6 +368,18 @@ class setlocal(set_):
             self.fm.set_option_from_string(name, value, localpath=path)
 
 
+class setintag(setlocal):
+    """:setintag <tag or tags> <option name>=<option value>
+
+    Sets an option for directories that are tagged with a specific tag.
+    """
+    def execute(self):
+        tags = self.arg(1)
+        self.shift()
+        name, value, _ = self.parse_setting_line()
+        self.fm.set_option_from_string(name, value, tags=tags)
+
+
 class quit(Command):
     """:quit
 
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index 85480d1b..71f3e601 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -69,6 +69,7 @@ class Settings(SignalDispatcher, FileManagerAware):
         SignalDispatcher.__init__(self)
         self.__dict__['_localsettings'] = dict()
         self.__dict__['_localregexes'] = dict()
+        self.__dict__['_tagsettings'] = dict()
         self.__dict__['_settings'] = dict()
         for name in ALLOWED_SETTINGS:
             self.signal_bind('setopt.'+name,
@@ -105,15 +106,17 @@ class Settings(SignalDispatcher, FileManagerAware):
                 self.fm.notify("Preview script undefined or not found!",
                         bad=True)
 
-    def set(self, name, value, path=None):
+    def set(self, name, value, path=None, tags=None):
         assert name in ALLOWED_SETTINGS, "No such setting: {0}!".format(name)
         if name not in self._settings:
             previous = None
         else:
             previous=self._settings[name]
         assert self._check_type(name, value)
+        assert not (tags and path), "Can't set a setting for path and tag " \
+            "at the same time!"
         kws = dict(setting=name, value=value, previous=previous,
-                path=path, fm=self.fm)
+                path=path, tags=tags, fm=self.fm)
         self.signal_emit('setopt', **kws)
         self.signal_emit('setopt.'+name, **kws)
 
@@ -129,12 +132,17 @@ class Settings(SignalDispatcher, FileManagerAware):
                 if name in self._localsettings[pattern] and\
                         regex.search(path):
                     return self._localsettings[pattern][name]
+        if self._tagsettings and path:
+            if self.fm.thisdir.realpath in self.fm.tags:
+                tag = self.fm.tags.marker(self.fm.thisdir.realpath)
+                if tag in self._tagsettings and name in self._tagsettings[tag]:
+                    return self._tagsettings[tag][name]
         if name in self._settings:
             return self._settings[name]
         else:
             type_ = self.types_of(name)[0]
             value = DEFAULT_VALUES[type_]
-            self._raw_set(name, value, None)
+            self._raw_set(name, value)
             self.__setattr__(name, value)
             return self._settings[name]
 
@@ -182,7 +190,7 @@ class Settings(SignalDispatcher, FileManagerAware):
     __getitem__ = __getattr__
     __setitem__ = __setattr__
 
-    def _raw_set(self, name, value, path):
+    def _raw_set(self, name, value, path=None, tags=None):
         if path:
             if not path in self._localsettings:
                 try:
@@ -200,11 +208,16 @@ class Settings(SignalDispatcher, FileManagerAware):
                 type_ = self.types_of(name)[0]
                 value = DEFAULT_VALUES[type_]
                 self._settings[name] = value
+        elif tags:
+            for tag in tags:
+                if tag not in self._tagsettings:
+                    self._tagsettings[tag] = dict()
+                self._tagsettings[tag][name] = value
         else:
             self._settings[name] = value
 
     def _raw_set_with_signal(self, signal):
-        self._raw_set(signal.setting, signal.value, signal.path)
+        self._raw_set(signal.setting, signal.value, signal.path, signal.tags)
 
 
 class LocalSettings():
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index cbf97054..8bd6dd0f 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -67,14 +67,14 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
         self.mode = mode
         self.ui.status.request_redraw()
 
-    def set_option_from_string(self, option_name, value, localpath=None):
+    def set_option_from_string(self, option_name, value, localpath=None, tags=None):
         if option_name not in ALLOWED_SETTINGS:
             raise ValueError("The option named `%s' does not exist" %
                     option_name)
         if not isinstance(value, str):
             raise ValueError("The value for an option needs to be a string.")
 
-        self.settings.set(option_name, self._parse_option_value(option_name, value), localpath)
+        self.settings.set(option_name, self._parse_option_value(option_name, value), localpath, tags)
 
 
     def _parse_option_value(self, name, value):