diff options
author | hut <hut@lavabit.com> | 2009-12-27 16:09:33 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-12-27 16:09:33 +0100 |
commit | d309f218d7d00405d5bca2f8c77344ce0c33a0bb (patch) | |
tree | f6f1b9e8bb9a0d98eedd3f29bfc8a89336a9acff /ranger | |
parent | ef0ee84300be230ab5ef417f4a303d07e5b5f0b9 (diff) | |
download | ranger-d309f218d7d00405d5bca2f8c77344ce0c33a0bb.tar.gz |
changed search implementation
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/actions.py | 41 | ||||
-rw-r--r-- | ranger/defaults/keys.py | 6 | ||||
-rw-r--r-- | ranger/fsobject/directory.py | 17 | ||||
-rw-r--r-- | ranger/gui/widgets/console.py | 2 |
4 files changed, 44 insertions, 22 deletions
diff --git a/ranger/actions.py b/ranger/actions.py index e1005201..9ccbc93f 100644 --- a/ranger/actions.py +++ b/ranger/actions.py @@ -5,15 +5,38 @@ from ranger.shared import EnvironmentAware, SettingsAware from ranger import fsobject class Actions(EnvironmentAware, SettingsAware): - def search_forward(self): - """Search forward for the regexp in self.env.last_search""" - if self.env.pwd: - self.env.pwd.search(self.env.last_search) - - def search_backward(self): - """Search backward for the regexp in self.env.last_search""" - if self.env.pwd: - self.env.pwd.search(self.env.last_search, -1) + search_method = None + search_forward = False + + def search(self, order=None, forward=True): + if self.search_forward: + direction = bool(forward) + else: + direction = not bool(forward) + + if order is None: + order = self.search_method + else: + self.set_search_method(order=order) + + if order in ('search', 'tag'): + if order == 'search': + arg = self.env.last_search + if arg is None: + return False + if hasattr(arg, 'search'): + fnc = lambda x: arg.search(x.basename) + else: + fnc = lambda x: arg in x.basename + elif order == 'tag': + fnc = lambda x: x.realpath in self.tags + + return self.env.pwd.search_fnc(fnc=fnc, forward=forward) + + def set_search_method(self, order, forward=True): + if order in ('search', 'tag', 'size', 'type', 'time'): + self.search_method = order + self.search_forward = forward def interrupt(self): """ diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py index 75956b7a..2f4106c3 100644 --- a/ranger/defaults/keys.py +++ b/ranger/defaults/keys.py @@ -45,6 +45,8 @@ def initialize_commands(command_list): bind('s', do('spawn', 'bash')) + bind(TAB, do('search', order='tag')) + t_hint = "show_//h//idden //p//review_files //d//irectories_first //a//uto_load_preview //c//ollapse_preview" command_list.hint(t_hint, 't') bind('th', do('toggle_boolean_option', 'show_hidden')) @@ -98,8 +100,8 @@ def initialize_commands(command_list): bind('gs', do('cd', '/srv')) bind('gR', do('cd', RANGERDIR)) - bind('n', do('search_forward')) - bind('N', do('search_backward')) + bind('n', do('search', forward=True)) + bind('N', do('search', forward=False)) # bookmarks for key in ALLOWED_BOOKMARK_KEYS: diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py index f263aa74..4f35dd9e 100644 --- a/ranger/fsobject/directory.py +++ b/ranger/fsobject/directory.py @@ -251,21 +251,18 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): Accumulator.move_to_obj(self, arg, attr='path') - def search(self, arg, direction = 1): - """Search for a regular expression""" - if self.empty() or arg is None: + def search_fnc(self, fnc, forward=True): + if not hasattr(fnc, '__call__'): return False - elif hasattr(arg, 'search'): - fnc = lambda x: arg.search(x.basename) - else: - fnc = lambda x: arg in x.basename length = len(self) - if direction > 0: - generator = ((self.pointer + (x + 1)) % length for x in range(length-1)) + if forward: + generator = ((self.pointer + (x + 1)) % length \ + for x in range(length-1)) else: - generator = ((self.pointer - (x + 1)) % length for x in range(length-1)) + generator = ((self.pointer - (x + 1)) % length \ + for x in range(length-1)) for i in generator: _file = self.files[i] diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 2d6df2a7..92c57a46 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -296,7 +296,7 @@ class SearchConsole(Console): if self.fm.env.pwd: regexp = re.compile(self.line, re.L | re.U | re.I) self.fm.env.last_search = regexp - if self.fm.env.pwd.search(regexp): + if self.fm.search(order='search'): self.fm.env.cf = self.fm.env.pwd.pointed_obj Console.execute(self) |