diff options
author | hut <hut@lavabit.com> | 2009-12-18 01:20:43 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-12-18 01:20:43 +0100 |
commit | 6a5d09b8731414c6fd76213bd31f7b29b847a235 (patch) | |
tree | 692d14a44f8582f275c82e9e8139d484df31ce34 /ranger | |
parent | b4b0eb249fbc2fa76e36eca898123509dd20d818 (diff) | |
download | ranger-6a5d09b8731414c6fd76213bd31f7b29b847a235.tar.gz |
added provisional filesystem operations (cp/cut/paste/delete/mkdir)
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/actions.py | 59 | ||||
-rw-r--r-- | ranger/commands.py | 14 | ||||
-rw-r--r-- | ranger/container/environment.py | 25 | ||||
-rw-r--r-- | ranger/defaults/keys.py | 4 |
4 files changed, 95 insertions, 7 deletions
diff --git a/ranger/actions.py b/ranger/actions.py index 41c7a6eb..d571b2aa 100644 --- a/ranger/actions.py +++ b/ranger/actions.py @@ -1,3 +1,6 @@ +import os +import shutil + from ranger.shared import EnvironmentAware, SettingsAware class Actions(EnvironmentAware, SettingsAware): @@ -133,6 +136,62 @@ class Actions(EnvironmentAware, SettingsAware): if isinstance(self.env.settings[string], bool): self.env.settings[string] ^= True +# ------------------------------------ filesystem operations + + def copy(self): + """Copy the selected items""" + + selected = set([self.env.cf]) + self.env.copy = set(f for f in selected if f in self.env.pwd.files) + self.env.cut = False + + def cut(self): + self.copy() + self.env.cut = True + + def paste(self): + """Paste the selected items into the current directory""" + from os.path import join, isdir + copied_files = self.env.copy + + if self.env.cut: + for f in self.env.copy: + try: + shutil.move(f.path, self.env.pwd.path) + except shutil.Error: + pass + self.env.copy.clear() + self.env.cut = False + else: + for f in self.env.copy: + if isdir(f.path): + try: + shutil.copytree(f.path, join(self.env.pwd.path, f.basename)) + except shutil.Error: + pass + else: + try: + shutil.copy(f.path, self.env.pwd.path) + except shutil.Error: + pass + + self.env.pwd.load_content() + + def delete(self): + selected = set([self.env.cf]) + self.env.copy -= selected + if selected: + for f in selected: + if os.path.isdir(f.path): + shutil.rmtree(f.path) + else: + try: + os.remove(f.path) + except OSError: + pass + + def mkdir(self, name): + os.mkdir(os.path.join(self.env.pwd.path, name)) # aliases: cd = enter_dir diff --git a/ranger/commands.py b/ranger/commands.py index 5b1060b6..06a4321b 100644 --- a/ranger/commands.py +++ b/ranger/commands.py @@ -169,6 +169,20 @@ class quit(Command): raise SystemExit +class delete(Command): + def execute(self): + self.fm.delete() + + +class mkdir(Command): + def execute(self): + line = parse(self.line) + try: + self.fm.mkdir(line.chunks[1]) + except IndexError: + pass + + # -------------------------------- rest by_name = {} diff --git a/ranger/container/environment.py b/ranger/container/environment.py index 40378221..7da8a608 100644 --- a/ranger/container/environment.py +++ b/ranger/container/environment.py @@ -4,18 +4,29 @@ from ranger.container import KeyBuffer, History from ranger.shared import SettingsAware class Environment(SettingsAware): - # A collection of data which is relevant for more than - # one class. + """A collection of data which is relevant for more than + one class. + """ + + pwd = None # current directory + cf = None # current file + copy = None + selection = None + termsize = None + history = None + directories = None + last_search = None + pathway = None + path = None + keybuffer = None + def __init__(self, path): self.path = abspath(expanduser(path)) self.pathway = () - self.last_search = None self.directories = {} - self.pwd = None # current directory - self.cf = None # current file self.keybuffer = KeyBuffer() - self.copy = None - self.termsize = None + self.selection = set() + self.copy = set() self.history = History(self.settings.max_history_size) from ranger.shared import EnvironmentAware diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py index 706e36e8..b300c4ad 100644 --- a/ranger/defaults/keys.py +++ b/ranger/defaults/keys.py @@ -36,6 +36,10 @@ def initialize_commands(command_list): bind('G', do('move_pointer', absolute = -1)) bind('E', do('edit_file')) + bind('yy', 'cp', do('copy')) + bind('cut', do('cut')) + bind('p', do('paste')) + bind('th', do('toggle_boolean_option', 'show_hidden')) bind('tp', do('toggle_boolean_option', 'preview_files')) bind('td', do('toggle_boolean_option', 'directories_first')) |