diff options
author | hut <hut@lavabit.com> | 2009-12-27 16:43:12 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-12-27 16:43:12 +0100 |
commit | 0b8a9d79273a91787eb4f373989d85e7a93e673b (patch) | |
tree | 17c9d982cd089d45fc6cfae8a0686241067d6b5b | |
parent | d309f218d7d00405d5bca2f8c77344ce0c33a0bb (diff) | |
download | ranger-0b8a9d79273a91787eb4f373989d85e7a93e673b.tar.gz |
implemented customized cycling through the directory
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | ranger/actions.py | 19 | ||||
-rw-r--r-- | ranger/defaults/keys.py | 12 | ||||
-rw-r--r-- | ranger/fsobject/directory.py | 15 |
4 files changed, 43 insertions, 5 deletions
diff --git a/TODO b/TODO index 206f0445..bfd80a4d 100644 --- a/TODO +++ b/TODO @@ -17,4 +17,4 @@ General (X) #9 09/12/24 add a widget for managing running operations (X) #10 09/12/24 sorting (X) #11 09/12/27 filter - ( ) #12 09/12/27 jump through the list in a specific order + (X) #12 09/12/27 jump through the list in a specific order diff --git a/ranger/actions.py b/ranger/actions.py index 9ccbc93f..968aae4f 100644 --- a/ranger/actions.py +++ b/ranger/actions.py @@ -5,7 +5,7 @@ from ranger.shared import EnvironmentAware, SettingsAware from ranger import fsobject class Actions(EnvironmentAware, SettingsAware): - search_method = None + search_method = 'ctime' search_forward = False def search(self, order=None, forward=True): @@ -33,8 +33,23 @@ class Actions(EnvironmentAware, SettingsAware): return self.env.pwd.search_fnc(fnc=fnc, forward=forward) + elif order in ('size', 'mimetype', 'ctime'): + pwd = self.env.pwd + if not pwd.cycle_list: + lst = list(pwd.files) + if order == 'size': + fnc = lambda item: item.size + elif order == 'mimetype': + fnc = lambda item: item.mimetype + elif order == 'ctime': + fnc = lambda item: -int(item.stat and item.stat.st_ctime) + lst.sort(key=fnc) + pwd.set_cycle_list(lst) + + return pwd.cycle(forward=forward) + def set_search_method(self, order, forward=True): - if order in ('search', 'tag', 'size', 'type', 'time'): + if order in ('search', 'tag', 'size', 'mimetype', 'ctime'): self.search_method = order self.search_forward = forward diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py index 2f4106c3..c3490c4a 100644 --- a/ranger/defaults/keys.py +++ b/ranger/defaults/keys.py @@ -39,8 +39,8 @@ def initialize_commands(command_list): bind('v', do('mark', all=True, toggle=True)) bind('V', do('mark', all=True, val=False)) - bind('yy', 'cp', do('copy')) - bind('cut', do('cut')) + bind('yy', do('copy')) + bind('dd', do('cut')) bind('p', do('paste')) bind('s', do('spawn', 'bash')) @@ -85,6 +85,8 @@ def initialize_commands(command_list): bind('term', do('spawn', 'x-terminal-emulator')) bind('du', do('runcmd', 'du --max-depth=1 -h | less')) bind('tf', do('open_console', cmode.COMMAND, 'filter ')) + d_hint = 'd//u// (disk usage) d//d// (cut)' + command_list.hint(d_hint, 'd') # key combinations which change the current directory def cd(path): @@ -103,6 +105,12 @@ def initialize_commands(command_list): bind('n', do('search', forward=True)) bind('N', do('search', forward=False)) + bind('cc', do('search', forward=True, order='ctime')) + bind('cm', do('search', forward=True, order='mimetype')) + bind('cs', do('search', forward=True, order='size')) + c_hint = '//c//time //m//imetype //s//ize' + command_list.hint(c_hint, 'c') + # bookmarks for key in ALLOWED_BOOKMARK_KEYS: bind("`" + key, "'" + key, do('enter_bookmark', key)) diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py index 4f35dd9e..6c9ab7b1 100644 --- a/ranger/fsobject/directory.py +++ b/ranger/fsobject/directory.py @@ -1,6 +1,7 @@ from ranger.fsobject import BAD_INFO, File, FileSystemObject from ranger.shared import SettingsAware from ranger.ext.accumulator import Accumulator +from collections import deque from ranger import log import ranger.fsobject @@ -18,6 +19,7 @@ class NoDirectoryGiven(Exception): class Directory(FileSystemObject, Accumulator, SettingsAware): enterable = False load_generator = None + cycle_list = None loading = False filenames = None @@ -171,6 +173,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): self.files = None self.infostring = BAD_INFO + self.cycle_list = None self.content_loaded = True self.loading = False @@ -273,6 +276,18 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): return True return False + def set_cycle_list(self, lst): + self.cycle_list = deque(lst) + + def cycle(self, forward=True): + if self.cycle_list: + if forward: + self.cycle_list.rotate(-1) + else: + self.cycle_list.rotate(1) + + self.move_to_obj(self.cycle_list[0]) + def correct_pointer(self): """Make sure the pointer is in the valid range""" Accumulator.correct_pointer(self) |