[meld] Support interactive searching in folder comparisons



commit 622a5f3fb4586fe0402c74a16b097e98a24edf9a
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Jun 23 06:02:43 2013 +1000

    Support interactive searching in folder comparisons

 meld/dirdiff.py |    4 ++++
 meld/tree.py    |   16 ++++++++++++++++
 meld/vcview.py  |   22 +---------------------
 3 files changed, 21 insertions(+), 21 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 360f31b..9f927af 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -322,6 +322,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
             self.focus_in_events.append(handler_id)
             handler_id = treeview.connect("focus-out-event", self.on_treeview_focus_out_event)
             self.focus_out_events.append(handler_id)
+            treeview.set_search_equal_func(self.model.treeview_search_cb)
         self.current_path, self.prev_path, self.next_path = None, None, None
         self.on_treeview_focus_out_event(None, None)
         self.focus_pane = None
@@ -1461,3 +1462,6 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
             app.disconnect(h)
 
         return gtk.RESPONSE_OK
+
+    def on_find_activate(self, *extra):
+        self.focus_pane.emit("start-interactive-search")
diff --git a/meld/tree.py b/meld/tree.py
index 8a341d7..ad17508 100644
--- a/meld/tree.py
+++ b/meld/tree.py
@@ -216,3 +216,19 @@ class DiffTreeStore(gtk.TreeStore):
                 break
 
         return prev_path, next_path
+
+    def treeview_search_cb(self, model, column, key, it):
+        # If the key contains a path separator, search the whole path,
+        # otherwise just use the filename. If the key is all lower-case, do a
+        # case-insensitive match.
+        abs_search = key.find('/') >= 0
+        lower_key = key.islower()
+
+        for path in model.value_paths(it):
+            if not path:
+                continue
+            lineText = path if abs_search else os.path.basename(path)
+            lineText = lineText.lower() if lower_key else lineText
+            if lineText.find(key) != -1:
+                return False
+        return True
diff --git a/meld/vcview.py b/meld/vcview.py
index e0f4b6b..1d27080 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -224,7 +224,7 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
         selection.set_mode(gtk.SELECTION_MULTIPLE)
         selection.connect("changed", self.on_treeview_selection_changed)
         self.treeview.set_headers_visible(1)
-        self.treeview.set_search_equal_func(self.treeview_search_cb)
+        self.treeview.set_search_equal_func(self.model.treeview_search_cb)
         self.current_path, self.prev_path, self.next_path = None, None, None
 
         self.column_name_map = {}
@@ -851,23 +851,3 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
 
     def on_find_activate(self, *extra):
         self.treeview.emit("start-interactive-search")
-
-    def treeview_search_cb(self, model, column, key, it):
-        """Callback function for searching in VcView treeview"""
-        path = model.value_path(it, 0)
-
-        # if query text contains slash, search in full path
-        if key.find('/') >= 0:
-            lineText = path
-        else:
-            lineText = os.path.basename(path)
-
-        # Perform case-insensitive matching if query text is all lower-case
-        if key.islower():
-            lineText = lineText.lower()
-
-        if lineText.find(key) >= 0:
-            # line matches
-            return False
-        else:
-            return True


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