[glade] GladePropertyShell: Be forgiving for invalid properties.



commit 618c18633894bf25945cd69ffc5fc28bdd115d0e
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Mon Apr 15 15:42:21 2013 +0900

    GladePropertyShell: Be forgiving for invalid properties.
    
    If the property class is not reachable for the loaded widget, just
    silently fail to load, this helps for cases where GladeButtonEditor
    also handles subclasses so some properties might or might not be
    editable.

 gladeui/glade-property-shell.c | 40 +++++++++++++++++++++++++++++++++-------
 1 file changed, 33 insertions(+), 7 deletions(-)
---
diff --git a/gladeui/glade-property-shell.c b/gladeui/glade-property-shell.c
index ccd5009..51364dd 100644
--- a/gladeui/glade-property-shell.c
+++ b/gladeui/glade-property-shell.c
@@ -218,24 +218,50 @@ glade_property_shell_load (GladeEditable   *editable,
 
   if (widget)
     {
-      GladeWidgetAdaptor *adaptor = glade_widget_get_adaptor (widget);
+      GladeWidgetAdaptor *adaptor = NULL;
+
+      /* Use the parent adaptor if we're a packing property */
+      if (priv->packing)
+       {
+         GladeWidget *parent = glade_widget_get_parent (widget);
+
+         if (parent)
+           adaptor = glade_widget_get_adaptor (parent);
+       }
+      else
+       adaptor = glade_widget_get_adaptor (widget);
 
       /* Need to rebuild the internal editor */
       if (priv->adaptor != adaptor)
        {
+         GladePropertyClass *pclass = NULL;
+
          if (priv->property_editor)
            gtk_widget_destroy (GTK_WIDGET (priv->property_editor));
 
          priv->adaptor = adaptor;
 
-         /* Construct custom editor property if specified */
-         if (g_type_is_a (priv->editor_type, GLADE_TYPE_EDITOR_PROPERTY))
+         if (adaptor)
            {
-             GladePropertyClass *pclass;
-
-             pclass = glade_widget_adaptor_get_property_class (priv->adaptor,
-                                                               priv->property_name);
+             if (priv->packing)
+               pclass = glade_widget_adaptor_get_pack_property_class (priv->adaptor,
+                                                                      priv->property_name);
+             else
+               pclass = glade_widget_adaptor_get_property_class (priv->adaptor,
+                                                                 priv->property_name);
+           }
 
+         /* Be forgiving, allow usage of properties that wont work, so that
+          * some editors can include properties for subclasses, and hide
+          * those properties if they're not applicable
+          */
+         if (pclass == NULL)
+           {
+             priv->property_editor = NULL;
+           }
+         /* Construct custom editor property if specified */
+         else if (g_type_is_a (priv->editor_type, GLADE_TYPE_EDITOR_PROPERTY))
+           {
              priv->property_editor = g_object_new (priv->editor_type,
                                                    "property-class", pclass,
                                                    "use-command", priv->use_command,


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