summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-05-17 21:44:49 +0200
committerhut <hut@lavabit.com>2010-05-17 21:44:49 +0200
commit1337039291f72d1514fe95586c585234b66436d3 (patch)
tree64d86e2f22a0d418b7af806b4c00692b39af4b54
parentf4c646d8a61710747e157ebac2e27ebfacf7b54c (diff)
downloadranger-1337039291f72d1514fe95586c585234b66436d3.tar.gz
customized David Barnetts code + polished stuff
1. removed StringIO dependency (Pager.set_source works with strings too)
2. fixed check for settings.preview_files
3. removed FileSystemObject.get_preview_source dummy method
   (This method is meaningless for directories, so they should not
   inherit it?)
-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: