summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-11-27 22:00:52 +0100
committerhut <hut@lavabit.com>2009-11-27 22:00:52 +0100
commitdb9bb0c9026b38acdf1174f2be5851acd47e066b (patch)
treefb641c0ce0b00a79488f4a61a51cec8cccfbd0d2 /ranger
parent9f36be13fa069a2a14fda8f2812269c4227d532f (diff)
downloadranger-db9bb0c9026b38acdf1174f2be5851acd47e066b.tar.gz
good things
Diffstat (limited to 'ranger')
-rw-r--r--ranger/directory.py44
-rw-r--r--ranger/environment.py2
-rw-r--r--ranger/fsobject.py18
-rw-r--r--ranger/wdisplay.py4
4 files changed, 25 insertions, 43 deletions
diff --git a/ranger/directory.py b/ranger/directory.py
index 57df2e13..665f9f7d 100644
--- a/ranger/directory.py
+++ b/ranger/directory.py
@@ -22,15 +22,10 @@ class Directory(ranger.fsobject.FSObject):
 		self.show_hidden = False
 		self.old_show_hidden = self.show_hidden
 	
-	def set_filter(self, string):
-		self.filter = string
-		self.load_content()
-	
 	def load_content(self):
 		from os.path import join, isdir, basename
 		from os import listdir
 
-		self.stop_if_frozen()
 		self.load_if_outdated()
 		self.content_loaded = True
 
@@ -42,8 +37,6 @@ class Directory(ranger.fsobject.FSObject):
 				if isinstance(self.filter, str) and self.filter in fname:
 					continue
 				filenames.append(join(self.path, fname))
-#			basenames = listdir(self.path)
-#			mapped = map(lambda name: join(self.path, name), basenames)
 			self.scroll_offset = 0
 			self.filenames = filenames
 			self.infostring = ' %d' % len(self.filenames) # update the infostring
@@ -60,8 +53,10 @@ class Directory(ranger.fsobject.FSObject):
 			self.files = files
 
 			if len(self.files) > 0:
-				self.pointed_index = 0
-				self.pointed_file = 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.move_pointer(absolute = 0)
 		else:
 			self.filenames = None
 			self.files = None
@@ -81,35 +76,42 @@ class Directory(ranger.fsobject.FSObject):
 			i += relative
 
 		self.pointed_index = i
-		self.fix_pointer()
+		self.correct_pointer()
 		return self.pointed_file
 
 	def move_pointer_to_file_path(self, path):
+		if path is None: return
+		try: path = path.path
+		except AttributeError: pass
+
 		self.load_content_once()
 		i = 0
 		for f in self.files:
 			if f.path == path:
 				self.move_pointer(absolute = i)
-				return
+				return True
 			i += 1
+		return False
 
-
-	def fix_pointer(self):
+	def correct_pointer(self):
 		i = self.pointed_index
-		if i >= len(self.files): i = len(self.files) - 1
-		if i < 0: i = 0
+
+		if i >= len(self.files):
+			i = len(self.files) - 1
+
+		if i < 0:
+			i = 0
+
 		self.pointed_index = i
 		self.pointed_file = self[i]
 		
 	def load_content_once(self):
-		self.stop_if_frozen()
 		if not self.content_loaded:
 			self.load_content()
 			return True
 		return False
 
 	def load_content_if_outdated(self):
-		self.stop_if_frozen()
 		if self.load_content_once(): return True
 
 		if self.old_show_hidden != self.show_hidden:
@@ -128,15 +130,9 @@ class Directory(ranger.fsobject.FSObject):
 
 	def __len__(self):
 		if not self.accessible: raise ranger.fsobject.NotLoadedYet()
-		return len(self.filenames)
+		return len(self.files)
 	
 	def __getitem__(self, key):
 		if not self.accessible: raise ranger.fsobject.NotLoadedYet()
 		return self.files[key]
 
-if __name__ == '__main__':
-	d = Directory('.')
-	d.load_filenames()
-	print(d.filenames)
-	print(d[1])
-
diff --git a/ranger/environment.py b/ranger/environment.py
index d5678695..d6635e9f 100644
--- a/ranger/environment.py
+++ b/ranger/environment.py
@@ -52,7 +52,7 @@ class Environment():
 				last_path = path.path
 				continue
 
-			log(( path.path, last_path ))
+#			log(( path.path, last_path ))
 			path.move_pointer_to_file_path(last_path)
 			last_path = path.path
 
diff --git a/ranger/fsobject.py b/ranger/fsobject.py
index 7a131891..099d3c5c 100644
--- a/ranger/fsobject.py
+++ b/ranger/fsobject.py
@@ -31,7 +31,6 @@ class FSObject(object):
 	# load() reads useful information about the file from the file system
 	# and caches it in instance attributes.
 	def load(self):
-		self.stop_if_frozen()
 		self.loaded = True
 
 		import os
@@ -66,14 +65,12 @@ class FSObject(object):
 			self.accessible = False
 
 	def load_once(self):
-		self.stop_if_frozen()
 		if not self.loaded:
 			self.load()
 			return True
 		return False
 
 	def load_if_outdated(self):
-		self.stop_if_frozen()
 		if self.load_once(): return True
 
 		import os
@@ -84,18 +81,3 @@ class FSObject(object):
 			self.load()
 			return True
 		return False
-
-	def clone(self):
-		clone = type(self)(self.path)
-		for key in iter(self.__dict__):
-			clone.__dict__[key] = self.__dict__[key]
-		return clone
-
-	def frozen_clone(self):
-		clone = self.clone()
-		clone.frozen = True
-		return clone
-
-	def stop_if_frozen(self):
-		if self.frozen: raise FrozenException('Cannot modify datastructure while it is frozen')
-
diff --git a/ranger/wdisplay.py b/ranger/wdisplay.py
index d0962149..55c0c563 100644
--- a/ranger/wdisplay.py
+++ b/ranger/wdisplay.py
@@ -94,6 +94,10 @@ class WDisplay(ranger.widget.Widget):
 		if halfwinsize < offset:
 			return min( dirsize - winsize, max( 0, index - halfwinsize ))
 
+		if original > dirsize - winsize:
+			self.target.scroll_begin = dirsize - winsize
+			return self.get_scroll_begin()
+
 		if projected < upper_limit and projected > lower_limit:
 			return original