take in account hidden items for preloading
authorgc <gc>
Sat, 26 Apr 2008 15:00:31 +0000 (15:00 +0000)
committergc <gc>
Sat, 26 Apr 2008 15:00:31 +0000 (15:00 +0000)
bin/booh-classifier

index 76688e9..12e42b3 100644 (file)
@@ -478,19 +478,19 @@ def gc
     msg 3, "GC in #{Time.now - start} s"
 end
 
-def free_cache
+def free_cache(avoid)
     i = $allentries.index($mainview.get_shown_entry)
     return if i.nil?
     start = Time.now
     ($allentries.size - 1).downto($config['preload-distance'].to_i + 1) { |j|
         index = i + j
-        if i + j < $allentries.size
-            $allentries[i+j].free_pixbuf_full
-            $allentries[i+j].free_pixbuf_main
+        if i + j < $allentries.size && ! avoid.include?(i + j)
+            $allentries[i + j].free_pixbuf_full
+            $allentries[i + j].free_pixbuf_main
         end
-        if i - j > 0
-            $allentries[i-j].free_pixbuf_full
-            $allentries[i-j].free_pixbuf_main
+        if i - j >= 0 && ! avoid.include?(i - j)
+            $allentries[i - j].free_pixbuf_full
+            $allentries[i - j].free_pixbuf_main
         end
     }
     msg 3, "freeing done in #{Time.now - start} s"
@@ -516,30 +516,50 @@ def run_preloader_real
             return
         end
         index = $allentries.index($mainview.get_shown_entry)
-        for j in 1 .. $config['preload-distance'].to_i
-
-            i = index + j
-            if i < $allentries.size
-                $allentries[i].pixbuf_main(false)
-            end
-            #- in case just loaded another directory
-            if $preloader_force_exit
-                $preloader_running = false
-                $preloader_force_exit = false
-                return
-            end
-            #- in case moved fast
-            if index != $allentries.index($mainview.get_shown_entry)
-                msg 3, "*** >>>> moved already, rerun"
-                $preloader_running = false
-                run_preloader_real
-                return
+        index_right = index
+        index_left = index
+        loaded_right = 0
+        loaded_left = 0
+        right_done = false
+        left_done = false
+        loaded = []
+        while ! right_done || ! left_done
+            if ! right_done
+                index_right += 1
+                while index_right < $allentries.size && ! visible($allentries[index_right])
+                    index_right += 1
+                end
+                if index_right == $allentries.size
+                    right_done = true
+                else
+                    msg 3, "preloading #{$allentries[index_right].path}"
+                    $allentries[index_right].pixbuf_main(false)
+                    loaded << index_right
+                    loaded_right += 1
+                    if loaded_right == $config['preload-distance'].to_i
+                        right_done = true
+                    end
+                end
             end
 
-            i = index - j
-            if i >= 0
-                $allentries[i].pixbuf_main(false)
+            if ! left_done
+                index_left -= 1
+                while index_left >= 0 && ! visible($allentries[index_left])
+                    index_left -= 1
+                end
+                if index_left == -1
+                    left_done = true
+                else
+                    msg 3, "preloading #{$allentries[index_left].path}"
+                    $allentries[index_left].pixbuf_main(false)
+                    loaded << index_left
+                    loaded_left += 1
+                    if loaded_left == $config['preload-distance'].to_i
+                        left_done = true
+                    end
+                end
             end
+
             #- in case just loaded another directory
             if $preloader_force_exit
                 $preloader_running = false
@@ -554,7 +574,7 @@ def run_preloader_real
                 return
             end
         end
-        free_cache
+        free_cache(loaded)
     end
     $preloader_running = false
     msg 3, "*** << main preloading finished"
@@ -1416,31 +1436,43 @@ def execute
     end
 end
 
-def update_visibility(entry)
+def visible(entry)
     if ! entry.button
         #- not yet loaded
         return
     end
     if entry.labeled
         if entry.labeled.button.active?
-            entry.button.show
+            return true
         else
-            entry.button.hide
+            return false
         end
     elsif entry.removed
         if $toremove_button.active?
-            entry.button.show
+            return true
         else
-            entry.button.hide
+            return false
         end
     else
         if $unlabelled_button.active?
-            entry.button.show
+            return true
         else
-            entry.button.hide
+            return false
         end
     end
 end
+
+def update_visibility(entry)
+    v = visible(entry)
+    if v.nil?
+        return
+    end
+    if v
+        entry.button.show
+    else
+        entry.button.hide
+    end
+end
         
 def update_all_visibilities
     $allentries.each { |entry|