[meld] dirdiff: Migrate a tuple-ising path helper to our treehelpers module



commit 009241e6d36bb389502658e7a5f217b34507448f
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Dec 17 09:15:29 2017 +1000

    dirdiff: Migrate a tuple-ising path helper to our treehelpers module

 meld/dirdiff.py     | 8 +++-----
 meld/treehelpers.py | 9 +++++++++
 2 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 9e3b43e6..dc35ef79 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -44,7 +44,7 @@ from meld.conf import _
 from meld.misc import all_same
 from meld.recent import RecentType
 from meld.settings import bind_settings, meldsettings, settings
-from meld.treehelpers import refocus_deleted_path
+from meld.treehelpers import refocus_deleted_path, tree_path_as_tuple
 from meld.ui.cellrenderers import (
     CellRendererByteSize, CellRendererDate, CellRendererFileMode)
 
@@ -684,8 +684,6 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
         todo = [rootpath]
         expanded = set()
 
-        tuple_tree_path = lambda p: tuple(p.get_indices())
-
         shadowed_entries = []
         invalid_filenames = []
         while len(todo):
@@ -798,7 +796,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
                         not all(os.path.isdir(f) for f in roots)):
                     self.model.add_empty(it)
                     if self.model.iter_parent(it) is None:
-                        expanded.add(tuple_tree_path(rootpath))
+                        expanded.add(tree_path_as_tuple(rootpath))
                 else:
                     # At this point, we have an empty folder tree node; we can
                     # prune this and any ancestors that then end up empty.
@@ -824,7 +822,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
                         it = parent
 
             if differences:
-                expanded.add(tuple_tree_path(path))
+                expanded.add(tree_path_as_tuple(path))
 
         if invalid_filenames or shadowed_entries:
             self._show_tree_wide_errors(invalid_filenames, shadowed_entries)
diff --git a/meld/treehelpers.py b/meld/treehelpers.py
index b8f6afb9..edd321d4 100644
--- a/meld/treehelpers.py
+++ b/meld/treehelpers.py
@@ -17,6 +17,15 @@
 from gi.repository import Gtk
 
 
+def tree_path_as_tuple(path):
+    """Get the path indices as a tuple
+
+    This helper only exists because we often want to use tree paths
+    as set members or dictionary keys, and this is a convenient option.
+    """
+    return tuple(path.get_indices())
+
+
 def tree_path_prev(path):
     if not path or path[-1] == 0:
         return None


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