Refactor the next/prev directional navigation to work properly

This commit is contained in:
Chris Jones 2010-02-14 22:03:06 +00:00
parent fdb5784b15
commit b78938a145
1 changed files with 17 additions and 9 deletions

View File

@ -3,6 +3,7 @@
# GPL v2 only # GPL v2 only
"""window.py - class for the main Terminator window""" """window.py - class for the main Terminator window"""
import copy
import pygtk import pygtk
pygtk.require('2.0') pygtk.require('2.0')
import gobject import gobject
@ -513,21 +514,28 @@ class Window(Container, gtk.Window):
def navigate_terminal(self, terminal, direction): def navigate_terminal(self, terminal, direction):
"""Navigate around terminals""" """Navigate around terminals"""
_containers, terminals = util.enumerate_descendants(self) _containers, terminals = util.enumerate_descendants(self)
visibles = self.get_visible_terminals()
current = terminals.index(terminal) current = terminals.index(terminal)
length = len(terminals) length = len(terminals)
next = None next = None
if length <= 1: if length <= 1 or len(visibles) <= 1:
return return
if direction == 'next': if direction in ['next', 'prev']:
next = current + 1 tmpterms = copy.copy(terminals)
if next >= length: tmpterms = tmpterms[current+1:]
next = 0 tmpterms.extend(terminals[0:current])
elif direction == 'prev':
next = current - 1 if direction == 'next':
if next < 0: tmpterms.reverse()
next = length - 1
next = 0
while len(tmpterms) > 0:
tmpitem = tmpterms.pop()
if tmpitem in visibles:
next = terminals.index(tmpitem)
break
elif direction in ['left', 'right', 'up', 'down']: elif direction in ['left', 'right', 'up', 'down']:
layout = self.get_visible_terminals() layout = self.get_visible_terminals()
allocation = terminal.get_allocation() allocation = terminal.get_allocation()