diff options
author | hut <hut@lavabit.com> | 2010-11-22 04:03:07 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-11-22 04:03:07 +0100 |
commit | cb41ff7ba0c1a60044bb4329812ceb9920965f03 (patch) | |
tree | b94407c5a92890c0eb31517f399bab5f7b8fd799 | |
parent | e3f6f484f0bb516a802f60f6dae89580d47a2217 (diff) | |
download | ranger-cb41ff7ba0c1a60044bb4329812ceb9920965f03.tar.gz |
core.actions: simplified tag functions
-rw-r--r-- | ranger/core/actions.py | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py index b52ae0ed..51a70844 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -17,7 +17,7 @@ import os import re import shutil import string -from os.path import join, isdir +from os.path import join, isdir, realpath from os import symlink, getcwd from inspect import cleandoc @@ -430,39 +430,33 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): # Tags are saved in ~/.config/ranger/tagged and simply mark if a # file is important to you in any context. - def tag_toggle(self, movedown=None): - try: - toggle = self.tags.toggle - except AttributeError: + def tag_toggle(self, paths=None, value=None, movedown=None): + if not self.tags: return - - sel = self.env.get_selection() - toggle(*tuple(map(lambda x: x.realpath, sel))) + if paths is None: + tags = tuple(x.realpath for x in self.env.get_selection()) + else: + tags = [realpath(path) for path in paths] + if value is True: + self.tags.add(*tags) + elif value is False: + self.tags.remove(*tags) + else: + self.tags.toggle(*tags) if movedown is None: - movedown = len(sel) == 1 + movedown = len(tags) == 1 and paths is None if movedown: self.move(down=1) if hasattr(self.ui, 'redraw_main_column'): self.ui.redraw_main_column() - def tag_remove(self, movedown=None): - try: - remove = self.tags.remove - except AttributeError: - return - - sel = self.env.get_selection() - remove(*tuple(map(lambda x: x.realpath, sel))) + def tag_remove(self, paths=None, movedown=None): + self.tag_toggle(paths=paths, value=False, movedown=movedown) - if movedown is None: - movedown = len(sel) == 1 - if movedown: - self.move(down=1) - - if hasattr(self.ui, 'redraw_main_column'): - self.ui.redraw_main_column() + def tag_add(self, paths=None, movedown=None): + self.tag_toggle(paths=paths, value=True, movedown=movedown) # -------------------------- # -- Bookmarks |