[meld] ui.notebook: Move handling for tab label changes to MeldNotebook



commit 7f4c75767f2129a26ab008dc5f831a3af91ddac7
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Nov 6 07:44:47 2015 +1000

    ui.notebook: Move handling for tab label changes to MeldNotebook

 data/ui/meldapp.ui  |    1 +
 meld/meldwindow.py  |   16 +++-------------
 meld/ui/notebook.py |   22 ++++++++++++++++++++++
 3 files changed, 26 insertions(+), 13 deletions(-)
---
diff --git a/data/ui/meldapp.ui b/data/ui/meldapp.ui
index 932aef7..42ada89 100644
--- a/data/ui/meldapp.ui
+++ b/data/ui/meldapp.ui
@@ -32,6 +32,7 @@
             <signal name="page-reordered" handler="after_page_reordered" after="yes" swapped="no"/>
             <signal name="switch-page" handler="on_switch_page" swapped="no"/>
             <signal name="switch-page" handler="after_switch_page" after="yes" swapped="no"/>
+            <signal name="page-label-changed" handler="on_page_label_changed" swapped="no"/>
           </object>
           <packing>
             <property name="expand">True</property>
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index 6c7620e..f284208 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -389,18 +389,8 @@ class MeldWindow(gnomeglade.Component):
     def after_page_reordered(self, notebook, page, page_num):
         self._update_page_action_sensitivity()
 
-    def on_notebook_label_changed(self, component, text, tooltip):
-        page = component.widget
-        nbl = self.notebook.get_tab_label(page)
-        nbl.set_label_text(text)
-        nbl.set_tooltip_text(tooltip)
-
-        # Only update the window title if the current page is active
-        if self.notebook.get_current_page() == self.notebook.page_num(page):
-            self.widget.set_title(text + " - Meld")
-        if isinstance(text, unicode):
-            text = text.encode('utf8')
-        self.notebook.child_set_property(page, "menu-label", text)
+    def on_page_label_changed(self, notebook, label_text):
+        self.widget.set_title(label_text + " - Meld")
 
     def on_can_undo(self, undosequence, can):
         self.actiongroup.get_action("Undo").set_sensitive(can)
@@ -558,7 +548,6 @@ class MeldWindow(gnomeglade.Component):
         if hasattr(page, 'scheduler'):
             self.scheduler.add_scheduler(page.scheduler)
         if isinstance(page, melddoc.MeldDoc):
-            page.connect("label-changed", self.on_notebook_label_changed)
             page.connect("file-changed", self.on_file_changed)
             page.connect("create-diff", lambda obj, arg, kwargs:
                          self.append_diff(arg, **kwargs))
@@ -570,6 +559,7 @@ class MeldWindow(gnomeglade.Component):
     def append_new_comparison(self):
         doc = newdifftab.NewDiffTab(self)
         self._append_page(doc, "document-new")
+        self.notebook.on_label_changed(doc, _("New comparison"), None)
 
         def diff_created_cb(doc, newdoc):
             doc.on_delete_event()
diff --git a/meld/ui/notebook.py b/meld/ui/notebook.py
index 916533b..1a50f89 100644
--- a/meld/ui/notebook.py
+++ b/meld/ui/notebook.py
@@ -25,6 +25,7 @@ class MeldNotebook(Gtk.Notebook):
 
     __gsignals__ = {
         'tab-switch': (GObject.SignalFlags.ACTION, None, (int,)),
+        'page-label-changed': (0, None, (GObject.TYPE_STRING,)),
     }
 
     css = """
@@ -88,6 +89,8 @@ class MeldNotebook(Gtk.Notebook):
 
         self.connect('button-press-event', self.on_button_press_event)
         self.connect('popup-menu', self.on_popup_menu)
+        self.connect('page-added', self.on_page_added)
+        self.connect('page-removed', self.on_page_removed)
 
     def do_tab_switch(self, notebook, page_num):
         notebook.set_current_page(page_num)
@@ -126,3 +129,22 @@ class MeldNotebook(Gtk.Notebook):
         page_num = self.get_current_page()
         child = self.get_nth_page(page_num)
         self.reorder_child(child, page_num + 1)
+
+    def on_page_added(self, notebook, child, page_num, *args):
+        child.pyobject.connect("label-changed", self.on_label_changed)
+
+    def on_page_removed(self, notebook, child, page_num, *args):
+        child.pyobject.disconnect_by_func(self.on_label_changed)
+
+    def on_label_changed(self, component, text, tooltip):
+        page = component.widget
+        nbl = self.get_tab_label(page)
+        nbl.set_label_text(text)
+        nbl.set_tooltip_text(tooltip)
+
+        # Only update the window title if the current page is active
+        if self.get_current_page() == self.page_num(page):
+            self.emit('page-label-changed', text)
+        if isinstance(text, unicode):
+            text = text.encode('utf8')
+        self.child_set_property(page, "menu-label", text)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]