summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-22 13:00:46 +0100
committerhut <hut@lavabit.com>2009-12-22 13:00:46 +0100
commit2b82ef62212c9a8d8702523c2720eb10b6b2bb28 (patch)
tree30af2022555898741fba36e090a4350bf4f26ab9
parentf5b7240a28004cffcd5c14ab4ba3c022d0bd589a (diff)
downloadranger-2b82ef62212c9a8d8702523c2720eb10b6b2bb28.tar.gz
improved auto-previews
-rw-r--r--ranger/actions.py18
-rw-r--r--ranger/defaults/keys.py1
-rw-r--r--ranger/defaults/options.py2
-rw-r--r--ranger/fsobject/__init__.py4
-rw-r--r--ranger/fsobject/directory.py73
-rw-r--r--ranger/fsobject/fsobject.py4
-rw-r--r--ranger/gui/widgets/filelist.py18
-rw-r--r--ranger/gui/widgets/statusbar.py4
-rw-r--r--ranger/shared/settings.py1
9 files changed, 84 insertions, 41 deletions
diff --git a/ranger/actions.py b/ranger/actions.py
index 2def74bc..e699053c 100644
--- a/ranger/actions.py
+++ b/ranger/actions.py
@@ -2,6 +2,7 @@ import os
 import shutil
 
 from ranger.shared import EnvironmentAware, SettingsAware
+from ranger import fsobject
 
 class Actions(EnvironmentAware, SettingsAware):
 	def search_forward(self):
@@ -66,9 +67,9 @@ class Actions(EnvironmentAware, SettingsAware):
 		"""Enter the current directory or execute the current file"""
 		cf = self.env.cf
 		if not self.env.enter_dir(cf):
-			if not self.execute_file(cf, mode = mode):
-				self.open_console('@')
-
+			if cf is not None:
+				if not self.execute_file(cf, mode = mode):
+					self.open_console('@')
 
 	def history_go(self, relative):
 		"""Move back and forth in the history"""
@@ -137,6 +138,17 @@ class Actions(EnvironmentAware, SettingsAware):
 		"""Toggle a boolean option named <string>"""
 		if isinstance(self.env.settings[string], bool):
 			self.env.settings[string] ^= True
+	
+	def force_load_preview(self, obj=None):
+		if not obj:
+			obj = self.env.cf
+
+		if isinstance(obj, fsobject.Directory):
+			if not obj.force_load:
+				obj.force_load = True
+			else:
+				obj.load_content()
+
 
 # ------------------------------------ filesystem operations
 
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index 55bafb6a..98ecd6c1 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -35,6 +35,7 @@ def initialize_commands(command_list):
 	bind('gg', do('move_pointer', absolute = 0))
 	bind('G', do('move_pointer', absolute = -1))
 	bind('E', do('edit_file'))
+	bind('o', do('force_load_preview'))
 
 	bind('yy', 'cp', do('copy'))
 	bind('cut', do('cut'))
diff --git a/ranger/defaults/options.py b/ranger/defaults/options.py
index d466b5dc..bfc82625 100644
--- a/ranger/defaults/options.py
+++ b/ranger/defaults/options.py
@@ -11,3 +11,5 @@ directories_first = True
 preview_files = False
 max_history_size = 20
 auto_load_preview = True
+
+max_dirsize_for_autopreview = 300
diff --git a/ranger/fsobject/__init__.py b/ranger/fsobject/__init__.py
index fde46fc9..ce765e1e 100644
--- a/ranger/fsobject/__init__.py
+++ b/ranger/fsobject/__init__.py
@@ -10,3 +10,7 @@ BAD_INFO = None
 
 class NotLoadedYet(Exception):
 	pass
+
+from ranger.fsobject.file import File
+from ranger.fsobject.directory import Directory, NoDirectoryGiven
+from ranger.fsobject.fsobject import FileSystemObject
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py
index 08e6ff87..fea7be34 100644
--- a/ranger/fsobject/directory.py
+++ b/ranger/fsobject/directory.py
@@ -16,7 +16,6 @@ class NoDirectoryGiven(Exception):
 	pass
 
 class Directory(SuperClass, SettingsAware):
-	content_loaded = False
 	scheduled = False
 	enterable = False
 
@@ -51,41 +50,43 @@ class Directory(SuperClass, SettingsAware):
 		from os import listdir
 
 		self.load_if_outdated()
-		self.content_loaded = True
-
-		if self.exists and self.runnable:
-			filenames = []
-			for fname in listdir(self.path):
-				if not self.settings.show_hidden and fname[0] == '.':
-					continue
-				if isinstance(self.filter, str) and self.filter in fname:
-					continue
-				filenames.append(join(self.path, fname))
-			self.scroll_offset = 0
-			self.filenames = filenames
-			self.infostring = ' %d' % len(self.filenames) # update the infostring
-			files = []
-			for name in self.filenames:
-				if isdir(name):
-					f = Directory(name)
-				else:
-					f = File(name)
-				f.load()
-				files.append(f)
-
-			self.files = files
-			self.old_directories_first = None
-#			self.sort()
-
-			if len(self.files) > 0:
-				if self.pointed_file is not None:
-					self.move_pointer_to_file_path(self.pointed_file)
-#				if self.pointed_file is None:
-#					self.correct_pointer()
-		else:
-			self.filenames = None
-			self.files = None
-			self.infostring = BAD_INFO
+
+		try:
+			self.stopped = False
+			if self.exists and self.runnable:
+				filenames = []
+				for fname in listdir(self.path):
+					if not self.settings.show_hidden and fname[0] == '.':
+						continue
+					if isinstance(self.filter, str) and self.filter in fname:
+						continue
+					filenames.append(join(self.path, fname))
+				self.scroll_offset = 0
+				self.filenames = filenames
+				self.infostring = ' %d' % len(self.filenames) # update the infostring
+				files = []
+				for name in self.filenames:
+					if isdir(name):
+						f = Directory(name)
+					else:
+						f = File(name)
+					f.load()
+					files.append(f)
+
+				self.files = files
+				self.old_directories_first = None
+
+				if len(self.files) > 0:
+					if self.pointed_file is not None:
+						self.move_pointer_to_file_path(self.pointed_file)
+			else:
+				self.filenames = None
+				self.files = None
+				self.infostring = BAD_INFO
+			self.content_loaded = True
+		except (KeyboardInterrupt, ValueError):
+			self.stopped = True
+			
 
 	def sort(self):
 		"""Sort the containing files"""
diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py
index 86fa7c32..854b05ac 100644
--- a/ranger/fsobject/fsobject.py
+++ b/ranger/fsobject/fsobject.py
@@ -5,6 +5,8 @@ DOCUMENT_BASENAMES = 'README TODO LICENSE'.split()
 from . import T_FILE, T_DIRECTORY, T_UNKNOWN, T_NONEXISTANT, BAD_INFO
 from ranger.shared import MimeTypeAware, FileManagerAware
 class FileSystemObject(MimeTypeAware, FileManagerAware):
+	content_loaded = False
+	force_load = False
 	path = None
 	basename = None
 	basename_lower = None
@@ -26,6 +28,8 @@ class FileSystemObject(MimeTypeAware, FileManagerAware):
 
 	last_used = None
 
+	stopped = False
+
 	video = False
 	image = False
 	audio = False
diff --git a/ranger/gui/widgets/filelist.py b/ranger/gui/widgets/filelist.py
index 1e5c748d..58dcd856 100644
--- a/ranger/gui/widgets/filelist.py
+++ b/ranger/gui/widgets/filelist.py
@@ -111,11 +111,27 @@ class FileList(Widget):
 		self.target.use()
 
 		if not self.target.content_loaded:
+			if self.target.force_load:
+				self.target.stopped = False
+
+			else:
+				if not self.target.stopped:
+					maxdirsize = self.settings.max_dirsize_for_autopreview
+					if maxdirsize is not None and self.target.accessible \
+							and self.target.size > maxdirsize:
+						self.target.stopped = True
+
+				if self.target.stopped:
+					self.color(base_color, 'error')
+					self.win.addnstr(self.y, self.x, "no preview", self.wid)
+					self.color_reset()
+					return
+
 			if self.settings.auto_load_preview:
 				self.color(base_color)
 				self.win.addnstr(self.y, self.x, "...", self.wid)
-				self.color_reset()
 				self.postpone_drawing = True
+				self.color_reset()
 				return
 			else:
 				self.color(base_color, 'error')
diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py
index 79bc0032..f99882b1 100644
--- a/ranger/gui/widgets/statusbar.py
+++ b/ranger/gui/widgets/statusbar.py
@@ -99,6 +99,9 @@ class StatusBar(Widget):
 		else:
 			target = self.env.at_level(0)
 
+		if not target.content_loaded:
+			return part
+
 		if self.filelist is not None:
 			pos = target.scroll_begin
 			max_pos = len(target) - self.filelist.hei
@@ -115,7 +118,6 @@ class StatusBar(Widget):
 				part.append([['scroll', 'all'], 'All'])
 		return part
 
-
 	def _combine_parts(self, left, right):
 		"""Combines left and right, filling the middle with spaces and
 		removing elements which don't have enough room to fit in.
diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py
index 5541b191..0132ac97 100644
--- a/ranger/shared/settings.py
+++ b/ranger/shared/settings.py
@@ -2,6 +2,7 @@ ALLOWED_SETTINGS = """
 show_hidden scroll_offset directories_first
 preview_files max_history_size colorscheme
 collapse_preview auto_load_preview
+max_dirsize_for_autopreview
 apps keys
 """.split()