From deb16c1da3b0301a04487e2bfb753536176264c8 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Sun, 24 Jan 2016 23:12:42 +0100 Subject: Move some :delete logic to fm.delete, further refactoring --- ranger/config/commands.py | 13 ++----------- ranger/core/actions.py | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 98cf0cdf..eb4ee4c3 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -548,23 +548,14 @@ class delete(Command): partial(self._question_callback, files), ('n', 'N', 'y', 'Y')) else: # no need for a confirmation, just delete - self._delete_with_tags(files) + self.fm.delete(files) def tab(self, tabnum): return self._tab_directory_content() - def _delete_with_tags(self, files): - # Delete the selected files and untag them. - absolute_files = [os.path.abspath(f) for f in files] - for f in absolute_files: - for tag in self.fm.tags.tags: - if str(tag).startswith(os.path.abspath(f)): - self.fm.tags.remove(tag) - self.fm.delete(absolute_files) - def _question_callback(self, files, answer): if answer == 'y' or answer == 'Y': - self._delete_with_tags(files) + self.fm.delete(files) class mark_tag(Command): diff --git a/ranger/core/actions.py b/ranger/core/actions.py index e45326f3..a9618746 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -1309,19 +1309,24 @@ class Actions(FileManagerAware, SettingsAware): def delete(self, files): # XXX: warn when deleting mount points/unseen marked files? self.notify("Deleting!") + files = [os.path.abspath(f) for f in files] + for f in files: + # Untag the deleted files. + for tag in self.fm.tags.tags: + if str(tag).startswith(f): + self.fm.tags.remove(tag) self.copy_buffer = set(filter(lambda f: f.path not in files, self.copy_buffer)) - if files: - for f in files: - if isdir(f) and not os.path.islink(f): - try: - shutil.rmtree(f) - except OSError as err: - self.notify(err) - else: - try: - os.remove(f) - except OSError as err: - self.notify(err) + for f in files: + if isdir(f) and not os.path.islink(f): + try: + shutil.rmtree(f) + except OSError as err: + self.notify(err) + else: + try: + os.remove(f) + except OSError as err: + self.notify(err) self.thistab.ensure_correct_pointer() def mkdir(self, name): -- cgit 1.4.1-2-gfad0