summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--TODO2
-rw-r--r--ranger/fsobject/file.py19
-rw-r--r--ranger/fsobject/fsobject.py6
-rw-r--r--ranger/gui/widgets/browsercolumn.py2
4 files changed, 8 insertions, 21 deletions
diff --git a/TODO b/TODO
index 84ecc811..d2aac406 100644
--- a/TODO
+++ b/TODO
@@ -84,7 +84,7 @@ Bugs
    (X) #74  10/03/21  console doesn't scroll
    (X) #78  10/03/31  broken preview when deleting all files in a directory
    (X) #85  10/04/26  no automatic reload of directory after using :filter
-   ( ) #87  10/05/10  files are not properly closed after previewing
+   (X) #87  10/05/10  files are not properly closed after previewing
    ( ) #88  10/05/10  race conditions for data loading from FS
    (X) #90  10/05/11  no link target for broken links
 
diff --git a/ranger/fsobject/file.py b/ranger/fsobject/file.py
index 1d25e7d8..2619fa35 100644
--- a/ranger/fsobject/file.py
+++ b/ranger/fsobject/file.py
@@ -14,16 +14,13 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import re
-import stat
 import zipfile
-from StringIO import StringIO
+from ranger.fsobject import FileSystemObject
 
 N_FIRST_BYTES = 20
 control_characters = set(chr(n) for n in
 		set(range(0, 9)) | set(range(14, 32)))
 
-from ranger.fsobject import FileSystemObject
-
 # Don't even try to preview files which mach this regular expression:
 PREVIEW_BLACKLIST = re.compile(r"""
 		# look at the extension:
@@ -45,6 +42,7 @@ PREVIEW_BLACKLIST = re.compile(r"""
 		$
 """, re.VERBOSE | re.IGNORECASE)
 
+# Preview these files (almost) always:
 PREVIEW_WHITELIST = re.compile(r"""
 		\.(
 			txt | py | c
@@ -76,13 +74,10 @@ class File(FileSystemObject):
 		return False
 
 	def has_preview(self):
-		if not (self.is_file \
-				and self.accessible \
-				and self.stat \
-				and not self.is_device \
-				and not self.stat.st_mode & stat.S_IFIFO):
+		if not self.fm.settings.preview_files:
+			return False
+		if not self.accessible or self.is_fifo or self.is_device:
 			return False
-
 		if PREVIEW_WHITELIST.search(self.basename):
 			return True
 		if PREVIEW_BLACKLIST.search(self.basename):
@@ -93,7 +88,5 @@ class File(FileSystemObject):
 
 	def get_preview_source(self):
 		if self.extension == 'zip':
-			contents = '\n'.join(zipfile.ZipFile(self.path).namelist())
-			return StringIO(contents)
+			return '\n'.join(zipfile.ZipFile(self.path).namelist())
 		return open(self.path, 'r')
-
diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py
index d570d009..985efb2d 100644
--- a/ranger/fsobject/fsobject.py
+++ b/ranger/fsobject/fsobject.py
@@ -301,9 +301,3 @@ class FileSystemObject(MimeTypeAware, FileManagerAware):
 			self.load()
 			return True
 		return False
-
-	def get_preview_source(self):
-		"""
-		Override this to get a file object for a preview pane, or None for
-		no preview.
-		"""
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index a2c5d165..d617e64e 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -92,7 +92,7 @@ class BrowserColumn(Pager):
 		return True
 
 	def has_preview(self):
-		if self.target is None or self.settings.preview_files == False:
+		if self.target is None:
 			return False
 
 		if self.target.is_file:
74' href='#n274'>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 348