Repository

- Handle left and right keys in the plaintext view

Parent commits : 68d01eef4cd8d5283ffca637159858582a94e331,
Children commits :

By lds on 2008-12-21 21:03:08
- Handle left and right keys in the plaintext view
- Use the space key to fold/unfold nodes


git-svn-id: http://shan/svn/repos/factorize@16 51b56bfc-b269-4856-8701-af1c38ee6d62

Difference with parent commit 68d01eef4cd8d5283ffca637159858582a94e331
Files modified:
gui.py
--- 
+++ 
@@ -24,6 +24,11 @@
 		s.first_node = s.disp_node
 		s.highlighted = 0
 		s.highlighted_node = None
+	
+	def Resize(s, y, x):
+		s.x_size = (x/2) - 1
+		s.y_size = y - 1
+		s.pad = curses.newpad(s.y_size,s.x_size)
 
 	def Display(s):
 		s.i = 0
@@ -33,8 +38,6 @@
 		while s.i < s.y_size - 1 and s.current_node != None:
 			s.DispTree()
 
-		#sys.exit(0)
-	
 		#clean the remaining part of the screen
 		for x in xrange(0, s.x_size):
 			for y in range(s.i, s.y_size - 1):
@@ -274,13 +277,15 @@
 		elif c == curses.KEY_NPAGE:
 			for i in xrange(1, 10):
 				s.CursorDown()
+		elif c == ord(' '):
+			if s.tree.highlighted_node and s.tree.highlighted_node != s.tree.root:
+				s.tree.highlighted_node.folded = not s.tree.highlighted_node.folded 
 		elif c == curses.KEY_RIGHT:
-			if s.tree.highlighted_node and s.tree.highlighted_node != s.tree.root:
-				s.tree.highlighted_node.folded = False
-
+			s.tree.x_off += 1
 		elif c == curses.KEY_LEFT:
-			if s.tree.highlighted_node and s.tree.highlighted_node != s.tree.root:
-				s.tree.highlighted_node.folded = True
+			s.tree.x_off -= 1
+		if s.tree.x_off < 0:
+			s.tree.x_off = 0
 
 def main(stdscr, log, opt):
 	curses.savetty()
@@ -290,6 +295,10 @@
 		plain = PlainView(log, opt)
 		gui = Gui(stdscr, tree)
 		kb_handler = gui
+
+		(y, x) = stdscr.getmaxyx()
+		tree.Resize(y, x)
+		plain.Resize(y, x)
 
 		while 1:
 			tree.Display()
@@ -305,6 +314,10 @@
 					kb_handler = plain
 				else:
 					kb_handler = gui
+			elif c == curses.KEY_RESIZE:
+				y, x = stdscr.getmaxyx()
+				tree.Resize(y, x)
+				plain.Resize(y, x)
 			else:
 				kb_handler.HandleKeys(c)
 

plain_gui.py
--- 
+++ 
@@ -10,6 +10,12 @@
 		s.x_size = 100
 		s.y_size = 40
 		s.log = log
+		s.pad = curses.newpad(s.y_size,s.x_size)
+
+	def Resize(s, y, x):
+		s.x_size = (x/2) - 1
+		s.y_size = y - 1
+		s.x_pos = (x/2) + 1
 		s.pad = curses.newpad(s.y_size,s.x_size)
 
 	def Match(s, line, highlighted):
@@ -53,9 +59,15 @@
 			s.y_off += 10
 		elif c == curses.KEY_PPAGE:
 			s.y_off -= 10
+		elif c == curses.KEY_LEFT:
+			s.x_off -= 1
+		elif c == curses.KEY_RIGHT:
+			s.x_off += 1
 
 		if s.y_off < 0:
 			s.y_off = 0
 		if s.y_off + s.y_size >= len(s.log.lines):
 			s.y_off = len(s.log.lines) - s.y_size
+		if s.x_off < 0:
+			s.x_off = 0