From 8db3c4b1732b497173e43da782d8c83406fb1a2e Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 31 Dec 2009 15:23:09 +0100 Subject: rename filelist(container) to browsercolumn/browserview --- doc/uml/128002 | 61 +++++-- doc/uml/128002.diagram | 51 +++--- doc/uml/134530.diagram | 2 +- ranger/gui/defaultui.py | 32 ++-- ranger/gui/widgets/browsercolumn.py | 280 ++++++++++++++++++++++++++++++++ ranger/gui/widgets/browserview.py | 112 +++++++++++++ ranger/gui/widgets/filelist.py | 280 -------------------------------- ranger/gui/widgets/filelistcontainer.py | 112 ------------- ranger/gui/widgets/statusbar.py | 14 +- 9 files changed, 491 insertions(+), 453 deletions(-) create mode 100644 ranger/gui/widgets/browsercolumn.py create mode 100644 ranger/gui/widgets/browserview.py delete mode 100644 ranger/gui/widgets/filelist.py delete mode 100644 ranger/gui/widgets/filelistcontainer.py diff --git a/doc/uml/128002 b/doc/uml/128002 index e6caf96d..d0d68427 100644 --- a/doc/uml/128002 +++ b/doc/uml/128002 @@ -59,7 +59,7 @@ format 70 end class 128002 "Displayable" - visibility package + abstract visibility package cpp_decl "" java_decl "" php_decl "" @@ -211,7 +211,7 @@ ${docstring}${body} end class 128130 "UI" - visibility package + abstract visibility package cpp_decl "" java_decl "" php_decl "" @@ -325,16 +325,16 @@ ${docstring}${body} end - classrelation 200322 // - relation 198274 o--- + classrelation 201090 // + relation 198658 o--- a role_name "" private python "${comment}${self}${name} = ${value} " - classrelation_ref 200322 // + classrelation_ref 201090 // b role_name "" private python "${comment}${self}${name} = ${value} " - classrelation_ref 200450 // + classrelation_ref 201218 // end end @@ -395,7 +395,7 @@ ${docstring}${body} end class 128386 "DisplayableContainer" - visibility package + abstract visibility package cpp_decl "" java_decl "" php_decl "" @@ -470,7 +470,7 @@ ${docstring}${members} end end - class 135170 "FileList" + class 135170 "BrowserColumn" visibility package cpp_decl "" java_decl "" @@ -494,7 +494,7 @@ ${docstring}${members} end end - class 135298 "FileListContainer" + class 135298 "BrowserView" visibility package cpp_decl "" java_decl "" @@ -532,6 +532,18 @@ ${docstring}${members} classrelation_ref 172930 // b parent class_ref 156034 // Widget end + + classrelation 200834 // + relation 198530 o--- + a role_name "" private + python "${comment}${self}${name} = ${value} +" + classrelation_ref 200834 // + b role_name "" private + python "${comment}${self}${name} = ${value} +" + classrelation_ref 200962 // + end end class 135426 "Console" @@ -906,7 +918,7 @@ ${docstring}${body} end class 155906 "FileSystemObject" - visibility package + abstract visibility package cpp_decl "" java_decl "" php_decl "" @@ -950,14 +962,23 @@ ${docstring}${body} end class 156034 "Widget" - visibility package - cpp_decl "" - java_decl "" - php_decl "" + abstract visibility package + cpp_decl "${comment}${template}class ${name}${inherit} { +${members}}; +${inlines} +" + java_decl "${comment}${@}${visibility}interface ${name}${extends} { +${members}} +" + php_decl "${comment}${visibility}interface ${name} { +${members}} +" python_2_2 python_decl "class ${name}${inherit}: ${docstring}${members} " - idl_decl "" + idl_decl "${comment}${abstract}${local}interface ${name}${inherit} { +${members}}; +" explicit_switch_type "" classrelation 172418 // @@ -968,8 +989,8 @@ ${docstring}${members} b parent class_ref 128002 // Displayable end - classrelation 200450 // - relation_ref 198274 // + classrelation 201218 // + relation_ref 198658 // end end @@ -1020,6 +1041,10 @@ ${docstring}${members} classrelation_ref 193282 // b parent class_ref 156034 // Widget end + + classrelation 200962 // + relation_ref 198530 // + end end class 175874 "StatusBar" @@ -1062,7 +1087,7 @@ ${docstring}${members} end end - class 176130 "ProcessManager" + class 176130 "TaskView" visibility package cpp_decl "" java_decl "" diff --git a/doc/uml/128002.diagram b/doc/uml/128002.diagram index 4765563d..ed57a90d 100644 --- a/doc/uml/128002.diagram +++ b/doc/uml/128002.diagram @@ -6,11 +6,11 @@ classcanvas 128002 class_ref 128002 // Displayable end classcanvas 128130 class_ref 128130 // UI draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default - xyz 182.852 356.327 2000 + xyz 182.852 363.327 2000 end classcanvas 128258 class_ref 128258 // DefaultUI draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default - xyz 159.717 432.896 2000 + xyz 159.717 439.896 2000 end classcanvas 128642 class_ref 128386 // DisplayableContainer draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default @@ -20,13 +20,13 @@ classcanvas 129410 class_ref 135042 // TitleBar draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 681.233 245.65 2000 end -classcanvas 129666 class_ref 135170 // FileList +classcanvas 129666 class_ref 135170 // BrowserColumn draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default - xyz 477.259 471.907 2000 + xyz 404.259 478.907 2000 end -classcanvas 129922 class_ref 135298 // FileListContainer +classcanvas 129922 class_ref 135298 // BrowserView draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default - xyz 477.3 562.8 2000 + xyz 504.3 562.8 2000 end classcanvas 131970 class_ref 135426 // Console draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default @@ -54,7 +54,7 @@ note 136962 "Defines no methods, just for classification" xyzwh 577 138 2000 135 77 classcanvas 137218 class_ref 175746 // Pager draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default - xyz 482 397 2000 + xyz 473 398 2000 end classcanvas 138370 class_ref 175874 // StatusBar draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default @@ -64,12 +64,12 @@ classcanvas 142338 class_ref 176002 // Notify draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 682 418 2000 end -classcanvas 142850 class_ref 176130 // ProcessManager +classcanvas 142850 class_ref 176130 // TaskView draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default - xyz 682 466 2000 + xyz 681 562 2000 end note 143362 "Inherits from pager to display file content" - xyzwh 316 482 2000 135 75 + xyzwh 292 619 2000 135 75 relationcanvas 128386 relation_ref 128002 // decenter_begin 529 from ref 128258 z 2001 to ref 128130 @@ -91,14 +91,15 @@ relationcanvas 130178 relation_ref 135554 // no_multiplicity_a no_multiplicity_b end relationcanvas 130562 relation_ref 135810 // - decenter_begin 238 + decenter_begin 200 + decenter_end 905 from ref 129922 z 2001 to ref 129666 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end relationcanvas 130690 relation_ref 135938 // decenter_begin 720 - decenter_end 495 + decenter_end 504 from ref 128642 z 2007 to ref 128002 no_role_a no_role_b no_multiplicity_a no_multiplicity_b @@ -135,8 +136,10 @@ relationcanvas 134274 relation_ref 149634 // no_multiplicity_a no_multiplicity_b end relationcanvas 134658 relation_ref 170754 // - decenter_end 708 - from ref 134530 z 2001 to ref 128002 + geometry HVH + from ref 134530 z 2001 to point 463 324 + line 145154 z 2001 to point 463 199 + line 145282 z 2001 to ref 128002 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end @@ -157,6 +160,7 @@ relationcanvas 134914 relation_ref 171010 // no_multiplicity_a no_multiplicity_b end relationcanvas 135938 relation_ref 171266 // + decenter_begin 836 from ref 129922 z 2001 to ref 134530 no_role_a no_role_b no_multiplicity_a no_multiplicity_b @@ -167,6 +171,7 @@ relationcanvas 137346 relation_ref 191234 // no_multiplicity_a no_multiplicity_b end relationcanvas 137602 relation_ref 191362 // + decenter_begin 722 from ref 129666 z 2001 to ref 137218 no_role_a no_role_b no_multiplicity_a no_multiplicity_b @@ -189,17 +194,25 @@ relationcanvas 142466 relation_ref 191618 // end relationcanvas 142978 relation_ref 191746 // geometry HVH - from ref 142850 z 2001 to point 655 485 + from ref 142850 z 2001 to point 655 581 line 143106 z 2001 to point 655 324 line 143234 z 2001 to ref 134530 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end -relationcanvas 143618 relation_ref 198274 // +relationcanvas 145538 relation_ref 198530 // + geometry HVr + decenter_begin 713 + from ref 129922 z 2001 to point 559 417 + line 146306 z 2001 to ref 137218 + no_role_a no_role_b + no_multiplicity_a no_multiplicity_b +end +relationcanvas 146434 relation_ref 198658 // geometry HVH - from ref 128130 z 2001 to point 394 375 - line 143746 z 2001 to point 394 324 - line 143874 z 2001 to ref 134530 + from ref 128130 z 2001 to point 394 382 + line 146562 z 2001 to point 394 324 + line 146690 z 2001 to ref 134530 no_role_a no_role_b no_multiplicity_a no_multiplicity_b end diff --git a/doc/uml/134530.diagram b/doc/uml/134530.diagram index cfd3b9c0..82785c7f 100644 --- a/doc/uml/134530.diagram +++ b/doc/uml/134530.diagram @@ -52,7 +52,7 @@ classcanvas 132610 class_ref 156034 // Widget draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 509 237 2017 end -classcanvas 133250 class_ref 135170 // FileList +classcanvas 133250 class_ref 135170 // BrowserColumn draw_all_relations default hide_attributes default hide_operations default hide_getset_operations default show_members_full_definition default show_members_visibility default show_members_stereotype default show_members_multiplicity default show_members_initialization default show_attribute_modifiers default member_max_width 0 show_parameter_dir default show_parameter_name default package_name_in_tab default class_drawing_mode default drawing_language default show_context_mode default auto_label_position default show_relation_modifiers default show_relation_visibility default show_infonote default shadow default show_stereotype_properties default xyz 553 430 2023 end diff --git a/ranger/gui/defaultui.py b/ranger/gui/defaultui.py index 08ec0b4b..540d088d 100644 --- a/ranger/gui/defaultui.py +++ b/ranger/gui/defaultui.py @@ -5,7 +5,7 @@ from ranger.gui.ui import UI class DefaultUI(UI): def setup(self): """Build up the UI by initializing widgets.""" - from ranger.gui.widgets.filelistcontainer import FileListContainer + from ranger.gui.widgets.browserview import BrowserView from ranger.gui.widgets.titlebar import TitleBar from ranger.gui.widgets.console import Console from ranger.gui.widgets.statusbar import StatusBar @@ -17,10 +17,10 @@ class DefaultUI(UI): self.titlebar = TitleBar(self.win) self.add_child(self.titlebar) - # Create the container for the filelists - self.filelist_container = FileListContainer(self.win, RATIO) - self.add_child(self.filelist_container) - self.main_filelist = self.filelist_container.main_filelist + # Create the browser view + self.browser = BrowserView(self.win, RATIO) + self.add_child(self.browser) + self.main_column = self.browser.main_column # Create the process manager self.pman = ProcessManager(self.win) @@ -32,7 +32,7 @@ class DefaultUI(UI): self.add_child(self.notify) # Create the status bar - self.status = StatusBar(self.win, self.main_filelist) + self.status = StatusBar(self.win, self.browser.main_column) self.add_child(self.status) # Create the console @@ -51,7 +51,7 @@ class DefaultUI(UI): notify_hei = min(max(1, y - 4), self.notify.requested_height) - self.filelist_container.resize(1, 0, y - 1 - notify_hei, x) + self.browser.resize(1, 0, y - 1 - notify_hei, x) self.pman.resize(1, 0, y - 1 - notify_hei, x) self.pager.resize(1, 0, y - 1 - notify_hei, x) self.notify.resize(y - notify_hei, 0, notify_hei, x) @@ -72,22 +72,22 @@ class DefaultUI(UI): self.console.focused = True self.pager.visible = False self.pager.focused = False - self.filelist_container.visible = True + self.browser.visible = True def open_pager(self): if self.console.focused: self.console.focused = False self.pager.visible = True self.pager.focused = True - self.filelist_container.visible = False + self.browser.visible = False return self.pager def open_embedded_pager(self): - self.filelist_container.open_pager() - return self.filelist_container.pager + self.browser.open_pager() + return self.browser.pager def close_embedded_pager(self): - self.filelist_container.close_pager() + self.browser.close_pager() def open_console(self, mode, string=''): if self.console.open(mode, string): @@ -101,18 +101,18 @@ class DefaultUI(UI): self.close_pager() def open_pman(self): - self.filelist_container.visible = False + self.browser.visible = False self.pman.visible = True self.pman.focused = True def close_pman(self): self.pman.visible = False - self.filelist_container.visible = True + self.browser.visible = True self.pman.focused = False def scroll(self, relative): - if self.main_filelist: - self.main_filelist.scroll(relative) + if self.browser and self.browser.main_column: + self.browser.main_column.scroll(relative) def throbber(self, string='.', remove=False): if remove: diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py new file mode 100644 index 00000000..055c9843 --- /dev/null +++ b/ranger/gui/widgets/browsercolumn.py @@ -0,0 +1,280 @@ +"""The BrowserColumn widget displays the contents of a directory or file.""" +from . import Widget +from .pager import Pager +from ranger import log + +class BrowserColumn(Pager, Widget): + main_display = False + display_infostring = False + scroll_begin = 0 + target = None + postpone_drawing = False + tagged_marker = '*' + + def __init__(self, win, level): + Pager.__init__(self, win) + Widget.__init__(self, win) + self.level = level + + def resize(self, y, x, hei, wid): + Widget.resize(self, y, x, hei, wid) + + def click(self, event): + """Handle a MouseEvent""" + from ranger.fsobject.fsobject import T_DIRECTORY + + if not (event.pressed(1) or event.pressed(3)): + return False + + if self.target is None: + pass + + elif self.target.type is T_DIRECTORY: + index = self.scroll_begin + event.y - self.y + + if event.pressed(1): + if not self.main_display: + self.fm.enter_dir(self.target.path) + + if index < len(self.target): + self.fm.move_pointer(absolute = index) + elif event.pressed(3): + try: + clicked_file = self.target[index] + self.fm.enter_dir(clicked_file.path) + except: + pass + + else: + if self.level > 0: + self.fm.move_right() + + return True + + def has_preview(self): + from ranger.fsobject.file import File + from ranger.fsobject.directory import Directory + + if self.target is None: + return False + + if isinstance(self.target, File): + if not self._preview_this_file(self.target): + return False + + return True + + def poke(self): + self.target = self.env.at_level(self.level) + + def draw(self): + """Call either _draw_file() or _draw_directory()""" + from ranger.fsobject.file import File + from ranger.fsobject.directory import Directory + +# self.pager.visible = False + if self.target is None: + pass + elif type(self.target) == File: + Pager.open(self) + self._draw_file() + elif type(self.target) == Directory: + self._draw_directory() + Widget.draw(self) + + def _preview_this_file(self, target): + return target.document and not self.settings.preview_files + + 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: + self.win.addnstr("not accessible", self.wid) + Pager.close(self) + return + + if not self._preview_this_file(self.target): + Pager.close(self) + return + + try: + f = open(self.target.path, 'r') + except: + Pager.close(self) + else: + self.set_source(f) + Pager.draw(self) + + def _draw_directory(self): + """Draw the contents of a directory""" + from ranger.fsobject.directory import Directory + import stat + + base_color = ['in_display'] + + self.target.use() + + self.win.move(0, 0) + + if not self.target.load_content_if_outdated(): + self.target.sort_if_outdated() + + if not self.target.content_loaded: + maxdirsize = self.settings.max_dirsize_for_autopreview + if not self.target.force_load and maxdirsize is not None \ + and self.target.accessible \ + and self.target.size > maxdirsize: + self.color(base_color, 'error') + self.win.addnstr("no preview", self.wid) + self.color_reset() + return + + if self.settings.auto_load_preview: + self.color(base_color) + self.win.addnstr("...", self.wid) + self.postpone_drawing = True + self.color_reset() + return + else: + self.color(base_color, 'error') + self.win.addnstr("not loaded", self.wid) + self.color_reset() + return + + if self.main_display: + base_color.append('maindisplay') + + if not self.target.accessible: + self.color(base_color, 'error') + self.win.addnstr("not accessible", self.wid) + self.color_reset() + return + + if self.target.empty(): + self.color(base_color, 'empty') + self.win.addnstr("empty", self.wid) + self.color_reset() + return + + self._set_scroll_begin() + + selected_i = self.target.pointer + for line in range(self.hei): + i = line + self.scroll_begin + + try: + drawed = self.target[i] + except IndexError: + break + + this_color = base_color + list(drawed.mimetype_tuple) + text = drawed.basename + tagged = drawed.realpath in self.fm.tags + + if i == selected_i: + this_color.append('selected') + + if drawed.marked: + this_color.append('marked') + + if tagged: + this_color.append('tagged') + if self.main_display: + text = self.tagged_marker + text + + if isinstance(drawed, Directory): + this_color.append('directory') + else: + this_color.append('file') + + if drawed.stat is not None and drawed.stat.st_mode & stat.S_IXUSR: + this_color.append('executable') + + if drawed.islink: + this_color.append('link') + this_color.append(drawed.exists and 'good' or 'bad') + + string = drawed.basename + try: + if self.main_display: + if tagged: + self.win.addnstr(line, 0, text, self.wid - 2) + elif self.wid > 1: + self.win.addnstr(line, 1, text, self.wid - 2) + else: + self.win.addnstr(line, 0, text, self.wid) + + if self.display_infostring and drawed.infostring: + info = drawed.infostring + x = self.wid - 1 - len(info) + if x > self.x: + self.win.addstr(line, x, str(info) + ' ') + except: + # the drawing of the last string will cause an error + # because ncurses tries to move out of the bounds + pass + + self.color_at(line, 0, self.wid, this_color) + + if self.main_display and tagged and self.wid > 2: + this_color.append('tag_marker') + self.color_at(line, 0, len(self.tagged_marker), this_color) + + self.color_reset() + + def _get_scroll_begin(self): + """Determines scroll_begin (the position of the first displayed file)""" + offset = self.settings.scroll_offset + dirsize = len(self.target) + winsize = self.hei + halfwinsize = winsize // 2 + index = self.target.pointer or 0 + original = self.target.scroll_begin + projected = index - original + + upper_limit = winsize - 1 - offset + lower_limit = offset + + if original < 0: + return 0 + + if dirsize < winsize: + return 0 + + if halfwinsize < offset: + return min( dirsize - winsize, max( 0, index - halfwinsize )) + + if original > dirsize - winsize: + self.target.scroll_begin = dirsize - winsize + return self._get_scroll_begin() + + if projected < upper_limit and projected > lower_limit: + return original + + if projected > upper_limit: + return min( dirsize - winsize, + original + (projected - upper_limit)) + + if projected < upper_limit: + return max( 0, + original - (lower_limit - projected)) + + return original + + def _set_scroll_begin(self): + """Updates the scroll_begin value""" + 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() + old_value = self.target.scroll_begin + self.target.scroll_begin += relative + self._set_scroll_begin() + + if self.target.scroll_begin == old_value: + self.target.move(relative = relative) + self.target.scroll_begin += relative diff --git a/ranger/gui/widgets/browserview.py b/ranger/gui/widgets/browserview.py new file mode 100644 index 00000000..ff0854f9 --- /dev/null +++ b/ranger/gui/widgets/browserview.py @@ -0,0 +1,112 @@ +"""The BrowserView manages a set of BrowserColumns.""" +from . import Widget +from .browsercolumn import BrowserColumn +from .pager import Pager +from ..displayable import DisplayableContainer + +class BrowserView(Widget, DisplayableContainer): + ratios = None + preview = True + preview_available = True + stretch_ratios = None + + def __init__(self, win, ratios, preview = True): + DisplayableContainer.__init__(self, win) + from functools import reduce + self.ratios = ratios + self.preview = preview + + # normalize ratios: + ratio_sum = float(reduce(lambda x,y: x + y, ratios)) + self.ratios = tuple(map(lambda x: x / ratio_sum, ratios)) + + if len(self.ratios) >= 2: + self.stretch_ratios = self.ratios[:-2] + \ + ((self.ratios[-2] + self.ratios[-1] * 0.9), \ + (self.ratios[-1] * 0.1)) + + offset = 1 - len(ratios) + if preview: offset += 1 + + for level in range(len(ratios)): + fl = BrowserColumn(self.win, level + offset) + self.add_child(fl) + + try: + self.main_column = self.container[preview and -2 or -1] + except IndexError: + self.main_column = None + else: + self.main_column.display_infostring = True + self.main_column.main_display = True + + self.pager = Pager(self.win, embedded=True) + self.add_child(self.pager) + + def resize(self, y, x, hei, wid): + """Resize all the columns according to the given ratio""" + DisplayableContainer.resize(self, y, x, hei, wid) + left = 0 + + cut_off_last = self.preview and not self.preview_available \ + and self.stretch_ratios + + if cut_off_last: + generator = zip(self.stretch_ratios, range(len(self.ratios))) + else: + generator = zip(self.ratios, range(len(self.ratios))) + + last_i = len(self.ratios) - 1 + + for ratio, i in generator: + wid = int(ratio * self.wid) + + if i == last_i: + wid = int(self.wid - left + 1) + + if i == last_i - 1: + self.pager.resize(0, left, hei, max(1, self.wid - left)) + + try: + self.container[i].resize(0, left, hei, max(1, wid-1)) + except KeyError: + pass + + left += wid + + def click(self, event): + n = event.ctrl() and 1 or 3 + if event.pressed(4): + self.fm.scroll(relative = -n) + elif event.pressed(2) or event.key_invalid(): + self.fm.scroll(relative = n) + else: + DisplayableContainer.click(self, event) + + def open_pager(self): + self.pager.visible = True + self.pager.focused = True + self.pager.open() + try: + self.container[-2].visible = False + self.container[-3].visible = False + except IndexError: + pass + + def close_pager(self): + self.pager.visible = False + self.pager.focused = False + self.pager.close() + try: + self.container[-2].visible = True + self.container[-3].visible = True + except IndexError: + pass + + def poke(self): + DisplayableContainer.poke(self) + if self.settings.collapse_preview and self.preview: + has_preview = self.container[-2].has_preview() + if self.preview_available != has_preview: + self.preview_available = has_preview + self.resize(self.y, self.x, self.hei, self.wid) diff --git a/ranger/gui/widgets/filelist.py b/ranger/gui/widgets/filelist.py deleted file mode 100644 index 4dd04ed1..00000000 --- a/ranger/gui/widgets/filelist.py +++ /dev/null @@ -1,280 +0,0 @@ -"""The FileList widget displays the contents of a directory or file.""" -from . import Widget -from .pager import Pager -from ranger import log - -class FileList(Pager, Widget): - main_display = False - display_infostring = False - scroll_begin = 0 - target = None - postpone_drawing = False - tagged_marker = '*' - - def __init__(self, win, level): - Pager.__init__(self, win) - Widget.__init__(self, win) - self.level = level - - def resize(self, y, x, hei, wid): - Widget.resize(self, y, x, hei, wid) - - def click(self, event): - """Handle a MouseEvent""" - from ranger.fsobject.fsobject import T_DIRECTORY - - if not (event.pressed(1) or event.pressed(3)): - return False - - if self.target is None: - pass - - elif self.target.type is T_DIRECTORY: - index = self.scroll_begin + event.y - self.y - - if event.pressed(1): - if not self.main_display: - self.fm.enter_dir(self.target.path) - - if index < len(self.target): - self.fm.move_pointer(absolute = index) - elif event.pressed(3): - try: - clicked_file = self.target[index] - self.fm.enter_dir(clicked_file.path) - except: - pass - - else: - if self.level > 0: - self.fm.move_right() - - return True - - def has_preview(self): - from ranger.fsobject.file import File - from ranger.fsobject.directory import Directory - - if self.target is None: - return False - - if isinstance(self.target, File): - if not self._preview_this_file(self.target): - return False - - return True - - def poke(self): - self.target = self.env.at_level(self.level) - - def draw(self): - """Call either _draw_file() or _draw_directory()""" - from ranger.fsobject.file import File - from ranger.fsobject.directory import Directory - -# self.pager.visible = False - if self.target is None: - pass - elif type(self.target) == File: - Pager.open(self) - self._draw_file() - elif type(self.target) == Directory: - self._draw_directory() - Widget.draw(self) - - def _preview_this_file(self, target): - return target.document and not self.settings.preview_files - - 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: - self.win.addnstr("not accessible", self.wid) - Pager.close(self) - return - - if not self._preview_this_file(self.target): - Pager.close(self) - return - - try: - f = open(self.target.path, 'r') - except: - Pager.close(self) - else: - self.set_source(f) - Pager.draw(self) - - def _draw_directory(self): - """Draw the contents of a directory""" - from ranger.fsobject.directory import Directory - import stat - - base_color = ['in_display'] - - self.target.use() - - self.win.move(0, 0) - - if not self.target.load_content_if_outdated(): - self.target.sort_if_outdated() - - if not self.target.content_loaded: - maxdirsize = self.settings.max_dirsize_for_autopreview - if not self.target.force_load and maxdirsize is not None \ - and self.target.accessible \ - and self.target.size > maxdirsize: - self.color(base_color, 'error') - self.win.addnstr("no preview", self.wid) - self.color_reset() - return - - if self.settings.auto_load_preview: - self.color(base_color) - self.win.addnstr("...", self.wid) - self.postpone_drawing = True - self.color_reset() - return - else: - self.color(base_color, 'error') - self.win.addnstr("not loaded", self.wid) - self.color_reset() - return - - if self.main_display: - base_color.append('maindisplay') - - if not self.target.accessible: - self.color(base_color, 'error') - self.win.addnstr("not accessible", self.wid) - self.color_reset() - return - - if self.target.empty(): - self.color(base_color, 'empty') - self.win.addnstr("empty", self.wid) - self.color_reset() - return - - self._set_scroll_begin() - - selected_i = self.target.pointer - for line in range(self.hei): - i = line + self.scroll_begin - - try: - drawed = self.target[i] - except IndexError: - break - - this_color = base_color + list(drawed.mimetype_tuple) - text = drawed.basename - tagged = drawed.realpath in self.fm.tags - - if i == selected_i: - this_color.append('selected') - - if drawed.marked: - this_color.append('marked') - - if tagged: - this_color.append('tagged') - if self.main_display: - text = self.tagged_marker + text - - if isinstance(drawed, Directory): - this_color.append('directory') - else: - this_color.append('file') - - if drawed.stat is not None and drawed.stat.st_mode & stat.S_IXUSR: - this_color.append('executable') - - if drawed.islink: - this_color.append('link') - this_color.append(drawed.exists and 'good' or 'bad') - - string = drawed.basename - try: - if self.main_display: - if tagged: - self.win.addnstr(line, 0, text, self.wid - 2) - elif self.wid > 1: - self.win.addnstr(line, 1, text, self.wid - 2) - else: - self.win.addnstr(line, 0, text, self.wid) - - if self.display_infostring and drawed.infostring: - info = drawed.infostring - x = self.wid - 1 - len(info) - if x > self.x: - self.win.addstr(line, x, str(info) + ' ') - except: - # the drawing of the last string will cause an error - # because ncurses tries to move out of the bounds - pass - - self.color_at(line, 0, self.wid, this_color) - - if self.main_display and tagged and self.wid > 2: - this_color.append('tag_marker') - self.color_at(line, 0, len(self.tagged_marker), this_color) - - self.color_reset() - - def _get_scroll_begin(self): - """Determines scroll_begin (the position of the first displayed file)""" - offset = self.settings.scroll_offset - dirsize = len(self.target) - winsize = self.hei - halfwinsize = winsize // 2 - index = self.target.pointer or 0 - original = self.target.scroll_begin - projected = index - original - - upper_limit = winsize - 1 - offset - lower_limit = offset - - if original < 0: - return 0 - - if dirsize < winsize: - return 0 - - if halfwinsize < offset: - return min( dirsize - winsize, max( 0, index - halfwinsize )) - - if original > dirsize - winsize: - self.target.scroll_begin = dirsize - winsize - return self._get_scroll_begin() - - if projected < upper_limit and projected > lower_limit: - return original - - if projected > upper_limit: - return min( dirsize - winsize, - original + (projected - upper_limit)) - - if projected < upper_limit: - return max( 0, - original - (lower_limit - projected)) - - return original - - def _set_scroll_begin(self): - """Updates the scroll_begin value""" - 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() - old_value = self.target.scroll_begin - self.target.scroll_begin += relative - self._set_scroll_begin() - - if self.target.scroll_begin == old_value: - self.target.move(relative = relative) - self.target.scroll_begin += relative diff --git a/ranger/gui/widgets/filelistcontainer.py b/ranger/gui/widgets/filelistcontainer.py deleted file mode 100644 index ed1922b8..00000000 --- a/ranger/gui/widgets/filelistcontainer.py +++ /dev/null @@ -1,112 +0,0 @@ -"""The FileListContainer manages a set of FileLists.""" -from . import Widget -from .filelist import FileList -from .pager import Pager -from ..displayable import DisplayableContainer - -class FileListContainer(Widget, DisplayableContainer): - ratios = None - preview = True - preview_available = True - stretch_ratios = None - - def __init__(self, win, ratios, preview = True): - DisplayableContainer.__init__(self, win) - from functools import reduce - self.ratios = ratios - self.preview = preview - - # normalize ratios: - ratio_sum = float(reduce(lambda x,y: x + y, ratios)) - self.ratios = tuple(map(lambda x: x / ratio_sum, ratios)) - - if len(self.ratios) >= 2: - self.stretch_ratios = self.ratios[:-2] + \ - ((self.ratios[-2] + self.ratios[-1] * 0.9), \ - (self.ratios[-1] * 0.1)) - - offset = 1 - len(ratios) - if preview: offset += 1 - - for level in range(len(ratios)): - fl = FileList(self.win, level + offset) - self.add_child(fl) - - try: - self.main_filelist = self.container[preview and -2 or -1] - except IndexError: - self.main_filelist = None - else: - self.main_filelist.display_infostring = True - self.main_filelist.main_display = True - - self.pager = Pager(self.win, embedded=True) - self.add_child(self.pager) - - def resize(self, y, x, hei, wid): - """Resize all the filelists according to the given ratio""" - DisplayableContainer.resize(self, y, x, hei, wid) - left = 0 - - cut_off_last = self.preview and not self.preview_available \ - and self.stretch_ratios - - if cut_off_last: - generator = zip(self.stretch_ratios, range(len(self.ratios))) - else: - generator = zip(self.ratios, range(len(self.ratios))) - - last_i = len(self.ratios) - 1 - - for ratio, i in generator: - wid = int(ratio * self.wid) - - if i == last_i: - wid = int(self.wid - left + 1) - - if i == last_i - 1: - self.pager.resize(0, left, hei, max(1, self.wid - left)) - - try: - self.container[i].resize(0, left, hei, max(1, wid-1)) - except KeyError: - pass - - left += wid - - def click(self, event): - n = event.ctrl() and 1 or 3 - if event.pressed(4): - self.fm.scroll(relative = -n) - elif event.pressed(2) or event.key_invalid(): - self.fm.scroll(relative = n) - else: - DisplayableContainer.click(self, event) - - def open_pager(self): - self.pager.visible = True - self.pager.focused = True - self.pager.open() - try: - self.container[-2].visible = False - self.container[-3].visible = False - except IndexError: - pass - - def close_pager(self): - self.pager.visible = False - self.pager.focused = False - self.pager.close() - try: - self.container[-2].visible = True - self.container[-3].visible = True - except IndexError: - pass - - def poke(self): - DisplayableContainer.poke(self) - if self.settings.collapse_preview and self.preview: - has_preview = self.container[-2].has_preview() - if self.preview_available != has_preview: - self.preview_available = has_preview - self.resize(self.y, self.x, self.hei, self.wid) diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py index 81616c82..1715a490 100644 --- a/ranger/gui/widgets/statusbar.py +++ b/ranger/gui/widgets/statusbar.py @@ -21,9 +21,9 @@ class StatusBar(Widget): old_wid = None result = None - def __init__(self, win, filelist=None): + def __init__(self, win, column=None): Widget.__init__(self, win) - self.filelist = filelist + self.column = column def draw(self): """Draw the statusbar""" @@ -74,8 +74,8 @@ class StatusBar(Widget): def _get_left_part(self): part = [] - if self.filelist is not None: - target = self.filelist.target.pointed_obj + if self.column is not None: + target = self.column.target.pointed_obj else: target = self.env.at_level(0).pointed_obj @@ -135,17 +135,17 @@ class StatusBar(Widget): def _get_right_part(self): part = [] - if self.filelist is None: + if self.column is None: return part - target = self.filelist.target + target = self.column.target # target = self.env.at_level(0) if not target.content_loaded or not target.accessible: return part pos = target.scroll_begin - max_pos = len(target) - self.filelist.hei + max_pos = len(target) - self.column.hei if target.marked_items: part.append([['scroll', 'marked'], 'Mrk']) -- cgit 1.4.1-2-gfad0