[meld] ui.util: Add property action helper for binding multiple target objects



commit d852a3b1f28e37367cd97f9dae2b6c1156bee884
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Jan 6 07:37:24 2019 +1000

    ui.util: Add property action helper for binding multiple target objects

 meld/ui/util.py | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
---
diff --git a/meld/ui/util.py b/meld/ui/util.py
index 1f38773a..821200ba 100644
--- a/meld/ui/util.py
+++ b/meld/ui/util.py
@@ -14,8 +14,11 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import logging
+from typing import List
 
-from gi.repository import Gio, Gtk
+from gi.repository import Gio
+from gi.repository import GObject
+from gi.repository import Gtk
 
 import meld.conf
 # Import support module to get all builder-constructed widgets in the namespace
@@ -96,3 +99,21 @@ def extract_accels_from_menu(model: Gio.MenuModel, app: Gtk.Application):
             more, name, submodel = it.get_next()
             if submodel:
                 extract_accels_from_menu(submodel, app)
+
+
+def make_multiobject_property_action(
+        obj_list: List[GObject.Object], prop_name: str) -> Gio.PropertyAction:
+    """Construct a property action linked to multiple objects
+
+    This is useful for creating actions linked to a GObject property,
+    where changing the property via the action should affect multiple
+    GObjects.
+
+    As an example, changing the text wrapping mode of a file comparison
+    pane should change the wrapping mode for *all* panes.
+    """
+    source, *targets = obj_list
+    action = Gio.PropertyAction.new(prop_name, source, prop_name)
+    for target in targets:
+        source.bind_property(prop_name, target, prop_name)
+    return action


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