diff options
author | hut <hut@lavabit.com> | 2010-04-14 20:01:26 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-04-14 20:01:26 +0200 |
commit | 5a8c735198079d928a7611b1f9c5aa7bf6d62a1e (patch) | |
tree | 49a7ec085adf776a3d51bde9b4814cc9a8fa96f6 /ranger | |
parent | 951aedd4a63ed53c4fe523f57e6f4cfe6d519d89 (diff) | |
parent | 3dd1793a9f60b318c73e1a0d5eade6349ad322fa (diff) | |
download | ranger-5a8c735198079d928a7611b1f9c5aa7bf6d62a1e.tar.gz |
Merge branch 'dirarg' into newkey
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/api/keys.py | 22 | ||||
-rw-r--r-- | ranger/core/actions.py | 25 | ||||
-rw-r--r-- | ranger/ext/direction.py | 9 |
3 files changed, 40 insertions, 16 deletions
diff --git a/ranger/api/keys.py b/ranger/api/keys.py index d7a688b9..92a0269c 100644 --- a/ranger/api/keys.py +++ b/ranger/api/keys.py @@ -34,10 +34,11 @@ class Wrapper(object): def function(command_argument): args, kws = real_args, real_keywords number = command_argument.n + direction = command_argument.direction obj = getattr(command_argument, self.__firstattr__) fnc = getattr(obj, attr) - if number is not None: - args, kws = replace_narg(number, fnc, args, kws) + if number is not None or direction is not None: + args, kws = replace_narg(number, direction, fnc, args, kws) return fnc(*args, **kws) return function return wrapper @@ -63,6 +64,7 @@ fm = Wrapper('fm') wdg = Wrapper('wdg') +DIRARG_KEYWORD = 'dirarg' NARG_KEYWORD = 'narg' def narg(number_, function_, *args_, **keywords_): @@ -78,7 +80,7 @@ def narg(number_, function_, *args_, **keywords_): args, keywords = replace_narg(number_, function_, args_, keywords_) return function_(*args, **keywords) -def replace_narg(number, function, args, keywords): +def replace_narg(number, direction, function, args, keywords): """ This function returns (args, keywords) with one little change: if <function> has a named argument called "narg", args and keywords @@ -93,10 +95,10 @@ def replace_narg(number, function, args, keywords): => (1, 666), {} """ argspec = getargspec(function).args - if NARG_KEYWORD in argspec: + args = list(args) + if number is not None and NARG_KEYWORD in argspec: try: # is narg in args? - args = list(args) index = argspec.index(NARG_KEYWORD) if ismethod(function): index -= 1 # because of 'self' @@ -105,4 +107,14 @@ def replace_narg(number, function, args, keywords): # is narg in keywords? keywords = dict(keywords) keywords[NARG_KEYWORD] = number + if direction is not None and DIRARG_KEYWORD in argspec: + try: + index = argspec.index(DIRARG_KEYWORD) + if ismethod(function): + index -= 1 # because of 'self' + args[index] = direction + except (ValueError, IndexError): + # is narg in keywords? + keywords = dict(keywords) + keywords[DIRARG_KEYWORD] = direction return args, keywords diff --git a/ranger/core/actions.py b/ranger/core/actions.py index ac6cfc95..b320396a 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -542,16 +542,29 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): self.env.cut = False self.ui.browser.main_column.request_redraw() - def copy(self): + def copy(self, narg=None, dirarg=None): """Copy the selected items""" - - selected = self.env.get_selection() - self.env.copy = set(f for f in selected if f in self.env.cwd.files) + cwd = self.env.cwd + if not narg and not dirarg: + selected = (f for f in self.env.get_selection() if f in cwd.files) + else: + if not dirarg and narg: + direction = Direction(down=1) + offset = 0 + else: + direction = Direction(dirarg) + offset = 1 + pos, selected = direction.select( + override=narg, lst=cwd.files, current=cwd.pointer, + pagesize=self.env.termsize[0], offset=offset) + self.env.cwd.pointer = pos + self.env.cwd.correct_pointer() + self.env.copy = set(selected) self.env.cut = False self.ui.browser.main_column.request_redraw() - def cut(self): - self.copy() + def cut(self, narg=None, dirarg=None): + self.copy(narg=narg, dirarg=dirarg) self.env.cut = True self.ui.browser.main_column.request_redraw() diff --git a/ranger/ext/direction.py b/ranger/ext/direction.py index f96ee90f..b9fbcac9 100644 --- a/ranger/ext/direction.py +++ b/ranger/ext/direction.py @@ -134,9 +134,8 @@ class Direction(dict): pos += current return int(max(min(pos, maximum + offset - 1), minimum)) - def select(self, lst, override, current, pagesize): - destination = self.move(direction=self.down(), override=override, + def select(self, lst, override, current, pagesize, offset=1): + dest = self.move(direction=self.down(), override=override, current=current, pagesize=pagesize, minimum=0, maximum=len(lst)) - if destination > current: - return destination, lst[current:destination] - return destination, lst[destination:current] + selection = lst[min(current, dest):max(current, dest) + offset] + return dest + offset - 1, selection |