summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-01 22:33:03 +0100
committerhut <hut@lavabit.com>2009-12-01 22:33:03 +0100
commitd494f0195e5eccc97fd9a135046ff028dec14ae7 (patch)
tree6e5c8f6445595ff22d984b942ffa0004f3cb3862
parentc2b99d5235cadcd541ed00909f7df5e0ace7ac42 (diff)
downloadranger-d494f0195e5eccc97fd9a135046ff028dec14ae7.tar.gz
scrolling
-rw-r--r--ranger/fm.py6
-rw-r--r--ranger/gui/defaultui.py4
-rw-r--r--ranger/gui/ui.py9
-rw-r--r--ranger/gui/wdisplay.py16
4 files changed, 34 insertions, 1 deletions
diff --git a/ranger/fm.py b/ranger/fm.py
index e88ff964..55fd64f3 100644
--- a/ranger/fm.py
+++ b/ranger/fm.py
@@ -64,10 +64,14 @@ class FM():
 	def move_pointer(self, relative = 0, absolute = None):
 		self.env.cf = self.env.pwd.move_pointer(relative, absolute)
 
-	def move_pointer_by_pages(self, relative = 0):
+	def move_pointer_by_pages(self, relative):
 		self.env.cf = self.env.pwd.move_pointer(
 				relative = int(relative * self.env.termsize[0]))
 
+	def scroll(self, relative):
+		self.ui.scroll(relative)
+		self.env.cf = self.env.pwd.pointed_file
+
 	def redraw(self):
 		self.ui.redraw()
 
diff --git a/ranger/gui/defaultui.py b/ranger/gui/defaultui.py
index 419d8a4f..d4d89047 100644
--- a/ranger/gui/defaultui.py
+++ b/ranger/gui/defaultui.py
@@ -14,11 +14,15 @@ class DefaultUI(SuperClass):
 				WDisplay(self.win, self.colorscheme, -1),
 				WDisplay(self.win, self.colorscheme, 0),
 				WDisplay(self.win, self.colorscheme, 1) ]
+		self.main_display = self.displays[2]
 		self.displays[2].display_infostring = True
 		self.displays[2].main_display = True
 		for disp in self.displays:
 			self.add_widget(disp)
 	
+	def scroll(self, relative):
+		self.main_display.scroll(relative)
+
 	def resize(self):
 		SuperClass.resize(self)
 		y, x = self.win.getmaxyx()
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 78adde28..fb6e9193 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -41,9 +41,18 @@ class UI():
 					widg.click(event, fm)
 					break
 
+		if event.pressed(4) or event.pressed(2) or event.bstate & 134217728:
+			if event.pressed(4):
+				fm.scroll(relative = -3)
+			else:
+				fm.scroll(relative = 3)
+
 	def setup(self):
 		pass
 
+	def scroll(self, relative):
+		pass
+
 	def resize(self):
 		self.env.termsize = self.win.getmaxyx()
 
diff --git a/ranger/gui/wdisplay.py b/ranger/gui/wdisplay.py
index 2aba3a61..1379c24e 100644
--- a/ranger/gui/wdisplay.py
+++ b/ranger/gui/wdisplay.py
@@ -151,6 +151,9 @@ class WDisplay(SuperClass):
 		upper_limit = winsize - 1 - offset
 		lower_limit = offset
 
+		if original < 0:
+			return 0
+
 		if dirsize < winsize:
 			return 0
 
@@ -178,3 +181,16 @@ class WDisplay(SuperClass):
 		self.scroll_begin = self.get_scroll_begin()
 		self.target.scroll_begin = self.scroll_begin
 
+	# TODO: does not work if options.scroll_offset is high,
+	# relative > 1 and you scroll from scroll_begin = 1 to 0
+	def scroll(self, relative):
+		self.set_scroll_begin()
+		old_value = self.target.scroll_begin
+		self.target.scroll_begin += relative
+		self.set_scroll_begin()
+
+		if self.target.scroll_begin == old_value:
+			self.target.move_pointer(relative = relative)
+			self.target.scroll_begin += relative
+
+