[meld] ui.pathlabel: Fix path label display for very long filenames (#697)



commit d3b79365ff7f058bf2a94781185f89bfd6c4d88d
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Wed Aug 10 10:24:06 2022 +1000

    ui.pathlabel: Fix path label display for very long filenames (#697)
    
    This is an ugly fix, but really all we want is for the label in our
    GtkButton to ellipsize.

 meld/ui/pathlabel.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
---
diff --git a/meld/ui/pathlabel.py b/meld/ui/pathlabel.py
index b3cbdeb0..5f6c0b59 100644
--- a/meld/ui/pathlabel.py
+++ b/meld/ui/pathlabel.py
@@ -16,7 +16,7 @@
 import logging
 from typing import Optional
 
-from gi.repository import Gdk, Gio, GObject, Gtk
+from gi.repository import Gdk, Gio, GObject, Gtk, Pango
 
 from meld.conf import _
 from meld.iohelpers import (
@@ -152,6 +152,10 @@ class PathLabel(Gtk.MenuButton):
 
         self.insert_action_group('widget', action_group)
 
+        # GtkButton recreates its GtkLabel child whenever the label
+        # prop changes, so we need this notify callback.
+        self.connect('notify::label', self.label_changed_cb)
+
     def do_realize(self):
         # As a workaround for pygobject#341, we delay this binding until
         # realize, at which point the child object is correct.
@@ -163,6 +167,14 @@ class PathLabel(Gtk.MenuButton):
 
         return Gtk.MenuButton.do_realize(self)
 
+    def label_changed_cb(self, *args):
+        # Our label needs ellipsization to avoid forcing minimum window
+        # sizes for long filenames. This child iteration hack is
+        # required as GtkButton has no label access.
+        for child in self.get_children():
+            if isinstance(child, Gtk.Label):
+                child.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
+
     def get_display_label(self, binding, from_value) -> str:
         if self.custom_label:
             return self.custom_label


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