When removing a notebook child and adding a new one we need to do it in one move so we can preserve the tab ordering. Closes LP #490627

This commit is contained in:
Chris Jones 2010-04-12 21:35:24 +01:00
parent 51ae3cd95a
commit bd3da1e8ff
4 changed files with 36 additions and 2 deletions

View File

@ -83,6 +83,16 @@ class Container(object):
"""Remove a widget from the container""" """Remove a widget from the container"""
raise NotImplementedError('remove') raise NotImplementedError('remove')
def replace(self, oldwidget, newwidget):
"""Replace the child oldwidget with newwidget. This is the bare minimum
required for this operation. Containers should override it if they have
more complex requirements"""
if not oldwidget in self.get_children():
err('%s is not a child of %s' % (oldwidget, self))
return
self.remove(oldwidget)
self.add(newwidget)
def hoover(self): def hoover(self):
"""Ensure we still have a reason to exist""" """Ensure we still have a reason to exist"""
raise NotImplementedError('hoover') raise NotImplementedError('hoover')

View File

@ -142,6 +142,13 @@ class Notebook(Container, gtk.Notebook):
self.disconnect_child(widget) self.disconnect_child(widget)
return(True) return(True)
def replace(self, oldwidget, newwidget):
"""Replace a tab's contents with a new widget"""
page_num = self.page_num(oldwidget)
self.remove(oldwidget)
self.add(newwidget)
self.reorder_child(newwidget, page_num)
def get_children(self): def get_children(self):
"""Return an ordered list of our children""" """Return an ordered list of our children"""
children = [] children = []

View File

@ -154,10 +154,9 @@ class Paned(Container):
if len(self.children) == 1: if len(self.children) == 1:
dbg('Paned::hoover: We only have one child, die') dbg('Paned::hoover: We only have one child, die')
parent = self.get_parent() parent = self.get_parent()
parent.remove(self)
child = self.children[0] child = self.children[0]
self.remove(child) self.remove(child)
parent.add(child) parent.replace(self, child)
del(self) del(self)
def resizeterm(self, widget, keyname): def resizeterm(self, widget, keyname):

View File

@ -895,6 +895,7 @@ for %s (%s)' % (name, urlplugin.__class__.__name__))
srcpaned.remove(widgetsrc) srcpaned.remove(widgetsrc)
dstpaned.split_axis(dsthbox, pos in ['top', 'bottom'], None, widgetsrc, pos in ['bottom', 'right']) dstpaned.split_axis(dsthbox, pos in ['top', 'bottom'], None, widgetsrc, pos in ['bottom', 'right'])
srcpaned.hoover() srcpaned.hoover()
widgetsrc.ensure_visible_and_focussed()
def get_location(self, term, x, y): def get_location(self, term, x, y):
"""Get our location within the terminal""" """Get our location within the terminal"""
@ -928,6 +929,23 @@ for %s (%s)' % (name, urlplugin.__class__.__name__))
if not self.vte.flags()&gtk.HAS_FOCUS: if not self.vte.flags()&gtk.HAS_FOCUS:
self.vte.grab_focus() self.vte.grab_focus()
def ensure_visible_and_focussed(self):
"""Make sure that we're visible and focussed"""
window = util.get_top_window(self)
topchild = window.get_child()
maker = Factory()
if maker.isinstance(topchild, 'Notebook'):
prevtmp = None
tmp = self.get_parent()
while tmp != topchild:
prevtmp = tmp
tmp = tmp.get_parent()
page = topchild.page_num(prevtmp)
topchild.set_current_page(page)
self.grab_focus()
def on_vte_focus(self, _widget): def on_vte_focus(self, _widget):
"""Update our UI when we get focus""" """Update our UI when we get focus"""
self.emit('title-change', self.get_window_title()) self.emit('title-change', self.get_window_title())