summary refs log tree commit diff stats
path: root/ranger
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 /ranger
parentf5b7240a28004cffcd5c14ab4ba3c022d0bd589a (diff)
downloadranger-2b82ef62212c9a8d8702523c2720eb10b6b2bb28.tar.gz
improved auto-previews
Diffstat (limited to 'ranger')
-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()
 
id='n43' href='#n43'>43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347