diff options
-rw-r--r-- | ranger/actions.py | 94 | ||||
-rw-r--r-- | ranger/gui/widgets/filelist.py | 30 |
2 files changed, 59 insertions, 65 deletions
diff --git a/ranger/actions.py b/ranger/actions.py index 9a9b3636..e0798344 100644 --- a/ranger/actions.py +++ b/ranger/actions.py @@ -291,8 +291,53 @@ class Actions(EnvironmentAware, SettingsAware): self.env.pwd.filter = fltr except: pass + + def notify(self, text, duration=4, bad=False): + try: + method = self.ui.display + except AttributeError: + pass + else: + return method(text, duration=duration, bad=bad) + + def mark(self, all=False, toggle=False, val=None, movedown=None): + """ + A wrapper for the directory.mark_xyz functions. + + Arguments: + all - change all files of the current directory at once? + toggle - toggle the marked-status? + val - mark or unmark? + """ + + if self.env.pwd is None: + return + + pwd = self.env.pwd + + if movedown is None: + movedown = not all + + if val is None and toggle is False: + return + + if all: + if toggle: + pwd.toggle_all_marks() + else: + pwd.mark_all(val) + else: + item = self.env.cf + if item is not None: + if toggle: + pwd.toggle_mark(item) + else: + pwd.mark_item(item, val) + + if movedown: + self.move_pointer(relative=1) -# ------------------------------------ filesystem operations + # ------------------------------------ filesystem operations def copy(self): """Copy the selected items""" @@ -385,51 +430,6 @@ class Actions(EnvironmentAware, SettingsAware): except OSError as err: self.notify(str(err), bad=True) - - def notify(self, text, duration=4, bad=False): - try: - method = self.ui.display - except AttributeError: - pass - else: - return method(text, duration=duration, bad=bad) - - def mark(self, all=False, toggle=False, val=None, movedown=None): - """ - A wrapper for the directory.mark_xyz functions. - - Arguments: - all - change all files of the current directory at once? - toggle - toggle the marked-status? - val - mark or unmark? - """ - - if self.env.pwd is None: - return - - pwd = self.env.pwd - - if movedown is None: - movedown = not all - - if val is None and toggle is False: - return - - if all: - if toggle: - pwd.toggle_all_marks() - else: - pwd.mark_all(val) - else: - item = self.env.cf - if item is not None: - if toggle: - pwd.toggle_mark(item) - else: - pwd.mark_item(item, val) - - if movedown: - self.move_pointer(relative=1) + # ------------------------------------ aliases - # aliases: cd = enter_dir diff --git a/ranger/gui/widgets/filelist.py b/ranger/gui/widgets/filelist.py index 71ee4717..8d37b92a 100644 --- a/ranger/gui/widgets/filelist.py +++ b/ranger/gui/widgets/filelist.py @@ -71,7 +71,7 @@ class FileList(Widget, DisplayableContainer): self.target = self.env.at_level(self.level) def draw(self): - """Call either draw_file() or draw_directory()""" + """Call either _draw_file() or _draw_directory()""" from ranger.fsobject.file import File from ranger.fsobject.directory import Directory @@ -79,22 +79,16 @@ class FileList(Widget, DisplayableContainer): if self.target is None: pass elif type(self.target) == File: - self.draw_file() + self._draw_file() elif type(self.target) == Directory: - self.draw_directory() + self._draw_directory() DisplayableContainer.draw(self) - def finalize(self): - if self.postpone_drawing: - self.target.load_content_if_outdated() - self.draw_directory() - self.postpone_drawing = False - def _preview_this_file(self, target): return target.document and not self.settings.preview_files - def draw_file(self): + def _draw_file(self): """Draw a preview of the file, if the settings allow it""" self.win.move(0, 0) if not self.target.accessible: @@ -112,7 +106,7 @@ class FileList(Widget, DisplayableContainer): self.pager.visible = True self.pager.set_source(f) - def draw_directory(self): + def _draw_directory(self): """Draw the contents of a directory""" from ranger.fsobject.directory import Directory import stat @@ -173,7 +167,7 @@ class FileList(Widget, DisplayableContainer): self.color_reset() return - self.set_scroll_begin() + self._set_scroll_begin() selected_i = self.target.pointer for line in range(self.hei): @@ -239,7 +233,7 @@ class FileList(Widget, DisplayableContainer): self.color_reset() - def get_scroll_begin(self): + def _get_scroll_begin(self): """Determines scroll_begin (the position of the first displayed file)""" offset = self.settings.scroll_offset dirsize = len(self.target) @@ -263,7 +257,7 @@ class FileList(Widget, DisplayableContainer): if original > dirsize - winsize: self.target.scroll_begin = dirsize - winsize - return self.get_scroll_begin() + return self._get_scroll_begin() if projected < upper_limit and projected > lower_limit: return original @@ -278,19 +272,19 @@ class FileList(Widget, DisplayableContainer): return original - def set_scroll_begin(self): + def _set_scroll_begin(self): """Updates the scroll_begin value""" - self.scroll_begin = self.get_scroll_begin() + self.scroll_begin = self._get_scroll_begin() self.target.scroll_begin = self.scroll_begin # TODO: does not work if options.scroll_offset is high, # relative > 1 and you scroll from scroll_begin = 1 to 0 def scroll(self, relative): """scroll by n lines""" - self.set_scroll_begin() + self._set_scroll_begin() old_value = self.target.scroll_begin self.target.scroll_begin += relative - self.set_scroll_begin() + self._set_scroll_begin() if self.target.scroll_begin == old_value: self.target.move(relative = relative) |