[meld/pathlabel] iohelpers: Update label formatting for having a single direct parent



commit 27406737208b179ef5b2c065066c898a54f3184d
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Aug 15 08:32:27 2021 +1000

    iohelpers: Update label formatting for having a single direct parent
    
    This formatting changes the appearance of the PathLabel widget when you
    have e.g.,
    
      meld file.txt file2.txt
    
    such that the two files (or folders) are directly under the same parent
    folder. Unlike our other rules about PathLabel formatting, this one
    doesn't actually provide any additional information to distinguish the
    two panes... but not having two elements here kinda looks weird.

 meld/iohelpers.py      | 6 ++++++
 test/test_iohelpers.py | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/meld/iohelpers.py b/meld/iohelpers.py
index 33a8ef5c..62dab95c 100644
--- a/meld/iohelpers.py
+++ b/meld/iohelpers.py
@@ -212,6 +212,12 @@ def format_parent_relative_path(parent: Gio.File, descendant: Gio.File) -> str:
                 descendant_parent)
 
     show_parent = not parent.has_parent()
+    # It looks odd to have a single component, so if we don't have a
+    # base path, we'll use the direct parent. In this case the parent
+    # won't provide any disambiguation... it's just for appearances.
+    if not show_parent and not base_path_str:
+        base_path_str = parent.get_basename()
+
     label_segments = [
         '…' if not show_parent else None,
         base_path_str,
diff --git a/test/test_iohelpers.py b/test/test_iohelpers.py
index 9c1437f5..2ab3981f 100644
--- a/test/test_iohelpers.py
+++ b/test/test_iohelpers.py
@@ -43,7 +43,7 @@ def test_find_shared_parent_path(paths, expected_parent):
         (
             '/home/hey/',
             '/home/hey/foo.txt',
-            '…/foo.txt',
+            '…/hey/foo.txt',
         ),
         # Child is a direct child of parent and parent is the root
         (


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