summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2013-03-09 20:33:38 +0100
committerhut <hut@lavabit.com>2013-03-09 20:33:54 +0100
commitd51f8d5a3f1b4addaff34ccffb2291b136117627 (patch)
treeecc04257024664ad6656fa546e0cbc1e3a415b7e
parenta78f5a7898805f83fcb61d0d72c931cc87cfc17e (diff)
downloadranger-d51f8d5a3f1b4addaff34ccffb2291b136117627.tar.gz
config/commands.py: faster filtering
-rw-r--r--ranger/config/commands.py4
-rw-r--r--ranger/container/directory.py46
-rw-r--r--ranger/gui/widgets/browsercolumn.py4
3 files changed, 35 insertions, 19 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 8d670731..f80d1838 100644
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -1027,7 +1027,7 @@ class scout(Command):
 
     def cancel(self):
         self.fm.thisdir.temporary_filter = None
-        self.fm.thisdir.load_content(schedule=False)
+        self.fm.thisdir.refilter()
 
     def quick(self):
         asyoutype = self.AS_YOU_TYPE in self.flags
@@ -1036,7 +1036,7 @@ class scout(Command):
         if self.PERM_FILTER in self.flags and asyoutype:
             self.fm.thisdir.filter = self._build_regex()
         if self.FILTER in self.flags or self.PERM_FILTER in self.flags:
-            self.fm.thisdir.load_content(schedule=False)
+            self.fm.thisdir.refilter()
         if self._count(move=asyoutype) == 1 and self.AUTO_OPEN in self.flags:
             return True
         return False
diff --git a/ranger/container/directory.py b/ranger/container/directory.py
index 2e8c6d6b..2e28082f 100644
--- a/ranger/container/directory.py
+++ b/ranger/container/directory.py
@@ -55,11 +55,14 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
 
     filenames = None
     files = None
+    files_all = None
     filter = None
     temporary_filter = None
     marked_items = None
     scroll_begin = 0
 
+    mod_time = 0
+
     mount_path = '/'
     disk_usage = 0
 
@@ -100,7 +103,7 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
 
         for opt in ('hidden_filter', 'show_hidden'):
             self.settings.signal_bind('setopt.' + opt,
-                self.request_reload, weak=True, autosort=False)
+                self.refilter, weak=True, autosort=False)
 
         self.settings = LocalSettings(path, self.settings)
 
@@ -164,6 +167,19 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
         else:
             return []
 
+    def refilter(self, signal=None):
+        if not self.files_all:
+            return # propably not loaded yet
+
+        self.mod_time = time()
+
+        if not self.settings.show_hidden and self.settings.hidden_filter:
+            hidden_filter = re.compile(self.settings.hidden_filter)
+        else:
+            hidden_filter = None
+        self.files = [f for f in self.files_all if accept_file(
+            f.basename, self, hidden_filter, self.filter)]
+
     # XXX: Check for possible race conditions
     def load_bit_by_bit(self):
         """An iterator that loads a part on every next() call
@@ -183,11 +199,6 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
 
                 self.mount_path = mount_path(mypath)
 
-                if not self.settings.show_hidden and self.settings.hidden_filter:
-                    hidden_filter = re.compile(self.settings.hidden_filter)
-                else:
-                    hidden_filter = None
-
                 filelist = os.listdir(mypath)
 
                 if self._cumulative_size_calculated:
@@ -208,9 +219,8 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
                 if self.is_link:
                     self.infostring = '->' + self.infostring
 
-                filenames = [mypath + (mypath == '/' and fname or '/' + fname)\
-                        for fname in filelist if accept_file(
-                            fname, self, hidden_filter, self.filter)]
+                filenames = [mypath + (mypath == '/' and fname or '/' + fname)
+                        for fname in filelist]
                 yield
 
                 self.load_content_mtime = os.stat(mypath).st_mtime
@@ -262,10 +272,11 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
                 self.vcs_outdated = False
 
                 self.filenames = filenames
-                self.files = files
+                self.files_all = files
+                self.refilter()
 
                 self._clear_marked_items()
-                for item in self.files:
+                for item in self.files_all:
                     if item.path in marked_paths:
                         item._mark(True)
                         self.marked_items.append(item)
@@ -281,6 +292,7 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
                         self.move(to=0)
             else:
                 self.filenames = None
+                self.files_all = None
                 self.files = None
 
             self.cycle_list = None
@@ -332,7 +344,7 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
 
     def sort(self):
         """Sort the contained files"""
-        if self.files is None:
+        if self.files_all is None:
             return
 
         old_pointed_obj = self.pointed_obj
@@ -349,19 +361,21 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
                 sort_func == sort_naturally:
             sort_func = sort_naturally_icase
 
-        self.files.sort(key = sort_func)
+        self.files_all.sort(key = sort_func)
 
         if self.settings.sort_reverse:
-            self.files.reverse()
+            self.files_all.reverse()
 
         if self.settings.sort_directories_first:
-            self.files.sort(key = sort_by_directory)
+            self.files_all.sort(key = sort_by_directory)
 
         if self.pointer is not None:
             self.move_to_obj(old_pointed_obj)
         else:
             self.correct_pointer()
 
+        self.refilter()
+
     def _get_cumulative_size(self):
         if self.size == 0:
             return 0
@@ -488,7 +502,7 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
 
         if self.load_content_once(*a, **k): return True
 
-        if self.files is None or self.content_outdated:
+        if self.files_all is None or self.content_outdated:
             self.load_content(*a, **k)
             return True
 
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index 55be3569..155c4dc6 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -20,6 +20,7 @@ class BrowserColumn(Pager):
     display_vcsstate   = True
     scroll_begin = 0
     target = None
+    last_target_mod_time = 0
     last_redraw_time = -1
     ellipsis = { False: '~', True: '…' }
 
@@ -148,7 +149,8 @@ class BrowserColumn(Pager):
                 self.need_redraw = True
                 self.old_thisfile = self.target.pointed_obj
 
-            if self.target.load_content_if_outdated() \
+            if self.last_target_mod_time < self.target.mod_time \
+            or self.target.load_content_if_outdated() \
             or self.target.sort_if_outdated() \
             or self.last_redraw_time < self.target.last_update_time:
                 self.need_redraw = True