[meld] Update identical files notification when diffs change (closes bgo#588743)



commit 79e14fce42d8bd0ae90cab358432007b1aad68ea
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Mar 12 17:08:05 2010 +1000

    Update identical files notification when diffs change (closes bgo#588743)
    
    FileDiff: Listen for Differ's diffs-changed signal, and update our
              identical-files notification accordingly.
    
    MsgAreaController: Add get/set_msg_id, as an optional method for keeping
                       track of which message is currently being shown.

 meld/filediff.py   |   38 +++++++++++++++++++++++++-------------
 meld/ui/msgarea.py |    8 ++++++++
 2 files changed, 33 insertions(+), 13 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 3eb4ead..baad39d 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -107,6 +107,9 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                  gtk.keysyms.Shift_R : MASK_SHIFT,
                  gtk.keysyms.Control_R : MASK_CTRL}
 
+    # Identifiers for MsgArea messages
+    (MSG_SAME,) = range(1)
+
     def __init__(self, prefs, num_panes):
         """Start up an filediff with num_panes empty contents.
         """
@@ -197,6 +200,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         for t in self.textview:
             t.connect("focus-in-event", self.on_current_diff_changed)
             t.connect("focus-out-event", self.on_current_diff_changed)
+        self.linediffer.connect("diffs-changed", self.on_diffs_changed)
 
     def on_focus_change(self):
         self.keymask = 0
@@ -753,19 +757,6 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         while step.next() is None:
             yield 1
 
-        error_message = True in [m.has_message() for m in self.msgarea_mgr]
-        if self.num_panes > 1 and self.linediffer.sequences_identical() and not error_message:
-            for index, mgr in enumerate(self.msgarea_mgr):
-                msgarea = mgr.new_from_text_and_icon(gtk.STOCK_INFO,
-                                                     _("Files are identical"))
-                button = msgarea.add_stock_button_with_text(_("Hide"),
-                                                            gtk.STOCK_CLOSE,
-                                                            gtk.RESPONSE_CLOSE)
-                if index == 0:
-                    button.props.label = _("Hi_de")
-                msgarea.connect("response", self.on_msgarea_identical_response)
-                msgarea.show_all()
-
         chunk, prev, next = self.linediffer.locate_chunk(1, 0)
         self.cursor.next = chunk
         if self.cursor.next is None:
@@ -786,6 +777,27 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         for i in self._diff_files(files, panetext):
             yield i
 
+    def on_diffs_changed(self, linediffer):
+        if self.linediffer.sequences_identical():
+            error_message = True in [m.has_message() for m in self.msgarea_mgr]
+            if self.num_panes == 1 or error_message:
+                return
+            for index, mgr in enumerate(self.msgarea_mgr):
+                msgarea = mgr.new_from_text_and_icon(gtk.STOCK_INFO,
+                                                     _("Files are identical"))
+                mgr.set_msg_id(FileDiff.MSG_SAME)
+                button = msgarea.add_stock_button_with_text(_("Hide"),
+                                                            gtk.STOCK_CLOSE,
+                                                            gtk.RESPONSE_CLOSE)
+                if index == 0:
+                    button.props.label = _("Hi_de")
+                msgarea.connect("response", self.on_msgarea_identical_response)
+                msgarea.show_all()
+        else:
+            for m in self.msgarea_mgr:
+                if m.get_msg_id() == FileDiff.MSG_SAME:
+                    m.clear()
+
     def on_msgarea_identical_response(self, msgarea, respid):
         for mgr in self.msgarea_mgr:
             mgr.clear()
diff --git a/meld/ui/msgarea.py b/meld/ui/msgarea.py
index 536316b..c83c9f3 100644
--- a/meld/ui/msgarea.py
+++ b/meld/ui/msgarea.py
@@ -221,15 +221,23 @@ class MsgAreaController(gtk.HBox):
         super(MsgAreaController, self).__init__()
 
         self.__msgarea = None
+        self.__msgid = None
 
     def has_message(self):
         return self.__msgarea is not None
 
+    def get_msg_id(self):
+        return self.__msgid
+
+    def set_msg_id(self, msgid):
+        self.__msgid = msgid
+
     def clear(self):
         if self.__msgarea is not None:
             self.remove(self.__msgarea)
             self.__msgarea.destroy()
             self.__msgarea = None
+        self.__msgid = None
 
     def new_from_text_and_icon(self, stockid, primary, secondary=None, buttons=[]):
         self.clear()



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