Browse Source

locate select: strip common prefix from search results

Fabian Peter Hammerle 8 years ago
parent
commit
80efeab427
1 changed files with 24 additions and 9 deletions
  1. 24 9
      osex/locate.py

+ 24 - 9
osex/locate.py

@@ -74,6 +74,9 @@ class LocateRootNode(ioex.selector.Node):
     def get_common_prefix_display_height(self):
         return self._common_prefix_display_height
 
+    def showing_common_prefix(self):
+        return self._common_prefix_display_height > 0
+
     def get_header_height(self):
         return self.get_patterns_height() + self.get_common_prefix_display_height()
 
@@ -138,18 +141,30 @@ class LocateRootNode(ioex.selector.Node):
             self._window.refresh()
         else:
             for path in paths:
-                self._append_child(ioex.selector.StaticNode(path))
+                self._append_child(LocatePathNode(path))
             self.common_prefix = os.path.dirname(os.path.commonprefix(paths))
             self.show_common_prefix()
 
+class LocatePathNode(ioex.selector.Node):
+
+    def __init__(self, path):
+        super(LocatePathNode, self).__init__()
+        self.path = path
+
+    def get_label(self):
+        if self.get_parent().showing_common_prefix():
+            return self.path[len(self.get_parent().common_prefix) + 1:]
+        else:
+            return self.path
+
 def locate_select(
-        stdscr, 
-        patterns = [], 
-        match_all = False, 
-        ignore_case = False, 
-        update_database = False, 
-        multiple = False, 
-        database_path = None, 
+        stdscr,
+        patterns = [],
+        match_all = False,
+        ignore_case = False,
+        update_database = False,
+        multiple = False,
+        database_path = None,
         update_require_visibility = None
         ):
 
@@ -174,4 +189,4 @@ def locate_select(
     if selection is None:
         return None
     else:
-        return [n.get_label() for n in selection]
+        return [n.path for n in selection]