Create some basic architecture to persist metadata across containers being removed/recreated as terminals are exiting. Fixes LP#711356
This commit is contained in:
parent
7a49cd47bc
commit
c6fca1dd73
@ -63,6 +63,11 @@ class Container(object):
|
||||
"""Return a list of direct child widgets, if any"""
|
||||
return(self.children)
|
||||
|
||||
def get_child_metadata(self, widget):
|
||||
"""Return metadata that would be useful to recreate ourselves after our
|
||||
child is .remove()d and .add()ed"""
|
||||
return None
|
||||
|
||||
def split_horiz(self, widget, cwd=None):
|
||||
"""Split this container horizontally"""
|
||||
return(self.split_axis(widget, True, cwd))
|
||||
@ -75,7 +80,7 @@ class Container(object):
|
||||
"""Default axis splitter. This should be implemented by subclasses"""
|
||||
raise NotImplementedError('split_axis')
|
||||
|
||||
def add(self, widget):
|
||||
def add(self, widget, metadata=None):
|
||||
"""Add a widget to the container"""
|
||||
raise NotImplementedError('add')
|
||||
|
||||
|
@ -153,10 +153,10 @@ class Notebook(Container, gtk.Notebook):
|
||||
self.show_all()
|
||||
terminal.grab_focus()
|
||||
|
||||
def add(self, widget):
|
||||
def add(self, widget, metadata=None):
|
||||
"""Add a widget to the container"""
|
||||
dbg('adding a new tab')
|
||||
self.newtab(widget=widget)
|
||||
self.newtab(widget=widget, metadata=metadata)
|
||||
|
||||
def remove(self, widget):
|
||||
"""Remove a widget from the container"""
|
||||
@ -176,6 +176,18 @@ class Notebook(Container, gtk.Notebook):
|
||||
self.add(newwidget)
|
||||
self.reorder_child(newwidget, page_num)
|
||||
|
||||
def get_child_metadata(self, widget):
|
||||
"""Fetch the relevant metadata for a widget which we'd need
|
||||
to recreate it when it's readded"""
|
||||
metadata = {}
|
||||
metadata['tabnum'] = self.page_num(widget)
|
||||
label = self.get_tab_label(widget)
|
||||
if not label:
|
||||
dbg('unable to find label for widget: %s' % widget)
|
||||
else:
|
||||
metadata['label'] = label.get_label()
|
||||
return metadata
|
||||
|
||||
def get_children(self):
|
||||
"""Return an ordered list of our children"""
|
||||
children = []
|
||||
@ -183,7 +195,7 @@ class Notebook(Container, gtk.Notebook):
|
||||
children.append(self.get_nth_page(page))
|
||||
return(children)
|
||||
|
||||
def newtab(self, debugtab=False, widget=None, cwd=None):
|
||||
def newtab(self, debugtab=False, widget=None, cwd=None, metadata=None):
|
||||
"""Add a new tab, optionally supplying a child widget"""
|
||||
dbg('making a new tab')
|
||||
maker = Factory()
|
||||
@ -218,20 +230,29 @@ class Notebook(Container, gtk.Notebook):
|
||||
handler = handler[0]
|
||||
self.connect_child(widget, signal, handler, *args)
|
||||
|
||||
if metadata and metadata.has_key('tabnum'):
|
||||
tabpos = metadata['tabnum']
|
||||
else:
|
||||
tabpos = -1
|
||||
|
||||
label = TabLabel(self.window.get_title(), self)
|
||||
if metadata and metadata.has_key('label'):
|
||||
dbg('creating TabLabel with text: %s' % metadata['label'])
|
||||
label.set_custom_label(metadata['label'])
|
||||
label.connect('close-clicked', self.closetab)
|
||||
|
||||
label.show_all()
|
||||
widget.show_all()
|
||||
|
||||
self.append_page(widget, None)
|
||||
dbg('inserting page at position: %s' % tabpos)
|
||||
self.insert_page(widget, None, tabpos)
|
||||
self.set_tab_label(widget, label)
|
||||
self.set_tab_label_packing(widget, not self.config['scroll_tabbar'],
|
||||
not self.config['scroll_tabbar'],
|
||||
gtk.PACK_START)
|
||||
|
||||
self.set_tab_reorderable(widget, True)
|
||||
self.set_current_page(-1)
|
||||
self.set_current_page(tabpos)
|
||||
self.show_all()
|
||||
if maker.isinstance(widget, 'Terminal'):
|
||||
widget.grab_focus()
|
||||
@ -395,6 +416,9 @@ class TabLabel(gtk.HBox):
|
||||
"""Update the text of our label"""
|
||||
self.label.set_text(text)
|
||||
|
||||
def get_label(self):
|
||||
return self.label.get_text()
|
||||
|
||||
def set_custom_label(self, text):
|
||||
"""Set a permanent label as if the user had edited it"""
|
||||
self.label.set_text(text)
|
||||
|
@ -73,7 +73,7 @@ class Paned(Container):
|
||||
|
||||
self.show_all()
|
||||
|
||||
def add(self, widget):
|
||||
def add(self, widget, metadata=None):
|
||||
"""Add a widget to the container"""
|
||||
if len(self.children) == 0:
|
||||
self.pack1(widget, True, True)
|
||||
@ -143,10 +143,13 @@ class Paned(Container):
|
||||
sibling = self.children[0]
|
||||
self.remove(sibling)
|
||||
|
||||
metadata = None
|
||||
parent = self.get_parent()
|
||||
metadata = parent.get_child_metadata(self)
|
||||
dbg('metadata obtained for %s: %s' % (self, metadata))
|
||||
parent.remove(self)
|
||||
self.cnxids.remove_all()
|
||||
parent.add(sibling)
|
||||
parent.add(sibling, metadata)
|
||||
sibling.grab_focus()
|
||||
del(self)
|
||||
else:
|
||||
|
@ -355,7 +355,7 @@ class Window(Container, gtk.Window):
|
||||
self.hide()
|
||||
|
||||
|
||||
def add(self, widget):
|
||||
def add(self, widget, metadata=None):
|
||||
"""Add a widget to the window by way of gtk.Window.add()"""
|
||||
maker = Factory()
|
||||
gtk.Window.add(self, widget)
|
||||
|
Loading…
Reference in New Issue
Block a user