diff --git a/terminatorlib/container.py b/terminatorlib/container.py index e8057588..b75a31a2 100755 --- a/terminatorlib/container.py +++ b/terminatorlib/container.py @@ -83,6 +83,16 @@ class Container(object): """Remove a widget from the container""" 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): """Ensure we still have a reason to exist""" raise NotImplementedError('hoover') diff --git a/terminatorlib/notebook.py b/terminatorlib/notebook.py index 7b132c7e..45318702 100755 --- a/terminatorlib/notebook.py +++ b/terminatorlib/notebook.py @@ -142,6 +142,13 @@ class Notebook(Container, gtk.Notebook): self.disconnect_child(widget) 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): """Return an ordered list of our children""" children = [] diff --git a/terminatorlib/paned.py b/terminatorlib/paned.py index 2a82db86..02cedbaf 100755 --- a/terminatorlib/paned.py +++ b/terminatorlib/paned.py @@ -154,10 +154,9 @@ class Paned(Container): if len(self.children) == 1: dbg('Paned::hoover: We only have one child, die') parent = self.get_parent() - parent.remove(self) child = self.children[0] self.remove(child) - parent.add(child) + parent.replace(self, child) del(self) def resizeterm(self, widget, keyname): diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 8d11bea2..b3814521 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -895,6 +895,7 @@ for %s (%s)' % (name, urlplugin.__class__.__name__)) srcpaned.remove(widgetsrc) dstpaned.split_axis(dsthbox, pos in ['top', 'bottom'], None, widgetsrc, pos in ['bottom', 'right']) srcpaned.hoover() + widgetsrc.ensure_visible_and_focussed() def get_location(self, term, x, y): """Get our location within the terminal""" @@ -928,6 +929,23 @@ for %s (%s)' % (name, urlplugin.__class__.__name__)) if not self.vte.flags()>k.HAS_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): """Update our UI when we get focus""" self.emit('title-change', self.get_window_title())