[meld: 3/6] Added duplicate folder message when trying to compare the same folder




commit 4ad9acc1682516a61287001e841b7155f26bfefe
Author: Jack <jack vanier16 outlook com>
Date:   Tue Dec 22 21:08:05 2020 -0500

    Added duplicate folder message when trying to compare the same folder

 meld/dirdiff.py    | 13 +++++++++++++
 meld/filediff.py   |  7 ++++---
 meld/ui/msgarea.py |  9 +++++++--
 3 files changed, 24 insertions(+), 5 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 50ed8234..517ba680 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -918,8 +918,13 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
             if differences:
                 expanded.add(tree_path_as_tuple(path))
 
+        duplicate_directories = list(set([p for p in roots
+            if roots.count(p) > 1]))
         if invalid_filenames or shadowed_entries:
             self._show_tree_wide_errors(invalid_filenames, shadowed_entries)
+        elif duplicate_directories:
+            # Since we can only load 3 dirs we can have at most 1 duplicate
+            self._show_duplicate_directory(duplicate_directories[0])
         elif rootpath == Gtk.TreePath.new_first() and not expanded:
             self._show_identical_status()
 
@@ -932,6 +937,14 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
         self.force_cursor_recalculate = True
         self.treeview[0].set_cursor(Gtk.TreePath.new_first())
 
+    def _show_duplicate_directory(self, duplicate_directory):
+        for index in range(self.num_panes):
+            primary = _(
+                "Folder %s was loaded more than once" % duplicate_directory)
+            msgarea = self.msgarea_mgr[index].add_dismissable_msg(
+                'dialog-error-symbolic', primary, "",
+                self.msgarea_mgr[:index]+self.msgarea_mgr[index+1:])
+
     def _show_identical_status(self):
         primary = _("Folders have no differences")
         identical_note = _(
diff --git a/meld/filediff.py b/meld/filediff.py
index c86a8c0e..5adc4057 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1813,11 +1813,12 @@ class FileDiff(Gtk.VBox, MeldDoc):
                 if tb.data.gfile]
         duplicate_files = list(set([p for p in paths if paths.count(p) > 1]))
         if duplicate_files:
-            for index, mgr in enumerate(self.msgarea_mgr):
+            for index in range(self.num_panes):
                 primary = _(
                     "File %s was loaded more than once." % duplicate_files[0])
-                mgr.add_dismissable_msg(
-                    'dialog-error-symbolic', primary, "")
+                self.msgarea_mgr[index].add_dismissable_msg(
+                    'dialog-error-symbolic', primary, "",
+                    self.msgarea_mgr[:index]+self.msgarea_mgr[index+1:])
         elif 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:
diff --git a/meld/ui/msgarea.py b/meld/ui/msgarea.py
index 5b482c5a..7ac3a866 100644
--- a/meld/ui/msgarea.py
+++ b/meld/ui/msgarea.py
@@ -103,10 +103,15 @@ class MsgAreaController(Gtk.HBox):
         self.pack_start(msgarea, True, True, 0)
         return msgarea
 
-    def add_dismissable_msg(self, icon, primary, secondary):
+    def add_dismissable_msg(self, icon, primary, secondary, other_panes=None):
+        def clear_all(*args):
+            self.clear()
+            if other_panes:
+                for pane in other_panes:
+                    pane.clear()
         msgarea = self.new_from_text_and_icon(icon, primary, secondary)
         msgarea.add_button(_("Hi_de"), Gtk.ResponseType.CLOSE)
-        msgarea.connect("response", lambda *args: self.clear())
+        msgarea.connect("response", clear_all)
         msgarea.show_all()
         return msgarea
 


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