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 in ['next', 'prev']:
tmpterms = copy.copy(terminals)
tmpterms = tmpterms[current+1:]
tmpterms.extend(terminals[0:current])
if direction == 'next': if direction == 'next':
next = current + 1 tmpterms.reverse()
if next >= length:
next = 0 next = 0
elif direction == 'prev': while len(tmpterms) > 0:
next = current - 1 tmpitem = tmpterms.pop()
if next < 0: if tmpitem in visibles:
next = length - 1 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()