[glade] GladeEditorProperty & GladePropertyShell: Added "custom-text" property



commit 79c6ce0ed9e33a9f845ab8cb7231572c5f30fa1a
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Sun May 5 16:50:16 2013 +0900

    GladeEditorProperty & GladePropertyShell: Added "custom-text" property
    
    Allows overriding the text which might show up in a GladeEpropCheck
    (or any item label created by a GladeEditorProperty, which might be
    created by a GladePropertyShell).

 gladeui/glade-editor-property.c |   84 +++++++++++++++++++++++++++++----------
 gladeui/glade-editor-property.h |    4 +-
 gladeui/glade-property-shell.c  |   51 ++++++++++++++++++++++-
 gladeui/glade-property-shell.h  |    3 +
 4 files changed, 118 insertions(+), 24 deletions(-)
---
diff --git a/gladeui/glade-editor-property.c b/gladeui/glade-editor-property.c
index e811de6..957980c 100644
--- a/gladeui/glade-editor-property.c
+++ b/gladeui/glade-editor-property.c
@@ -57,7 +57,8 @@ enum
   PROP_0,
   PROP_PROPERTY_CLASS,
   PROP_USE_COMMAND,
-  PROP_DISABLE_CHECK
+  PROP_DISABLE_CHECK,
+  PROP_CUSTOM_TEXT
 };
 
 enum
@@ -90,8 +91,10 @@ struct _GladeEditorPropertyPrivate
   gulong              sensitive_id;   /* signal connection id for sensitivity changes    */
   gulong              changed_id;     /* signal connection id for value changes          */
   gulong              enabled_id;     /* signal connection id for enable/disable changes */
-       
-  gboolean            loading;        /* True during glade_editor_property_load calls, this
+
+  gchar              *custom_text;    /* Custom text to display in the property label */
+
+  guint               loading : 1;    /* True during glade_editor_property_load calls, this
                                       * is used to avoid feedback from input widgets.
                                       */
   guint               committing : 1; /* True while the editor property itself is applying
@@ -190,6 +193,38 @@ glade_editor_property_commit_no_callback (GladeEditorProperty *eprop,
     g_signal_handler_unblock (G_OBJECT (eprop->priv->property), eprop->priv->changed_id);
 }
 
+
+void
+glade_editor_property_set_custom_text (GladeEditorProperty *eprop,
+                                      const gchar         *custom_text)
+{
+  GladeEditorPropertyPrivate *priv;
+
+  g_return_if_fail (GLADE_IS_EDITOR_PROPERTY (eprop));
+
+  priv = eprop->priv;
+
+  if (g_strcmp0 (priv->custom_text, custom_text) != 0)
+    {
+      g_free (priv->custom_text);
+      priv->custom_text = g_strdup (custom_text);
+
+      if (priv->item_label)
+       glade_property_label_set_custom_text (GLADE_PROPERTY_LABEL (priv->item_label),
+                                             custom_text);
+
+      g_object_notify (G_OBJECT (eprop), "custom-text");
+    }
+}
+
+const gchar *
+glade_editor_property_get_custom_text (GladeEditorProperty *eprop)
+{
+  g_return_val_if_fail (GLADE_IS_EDITOR_PROPERTY (eprop), NULL);
+
+  return eprop->priv->custom_text;
+}
+
 GtkWidget *
 glade_editor_property_get_item_label  (GladeEditorProperty *eprop)
 {
@@ -371,6 +406,8 @@ glade_editor_property_finalize (GObject *object)
   /* detatch from loaded property */
   glade_editor_property_load_common (eprop, NULL);
 
+  g_free (eprop->priv->custom_text);
+
   G_OBJECT_CLASS (table_class)->finalize (object);
 }
 
@@ -415,6 +452,9 @@ glade_editor_property_set_property (GObject *object,
              gtk_widget_show (eprop->priv->check);
          }
         break;
+      case PROP_CUSTOM_TEXT:
+       glade_editor_property_set_custom_text (eprop, g_value_get_string (value));
+       break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -440,6 +480,9 @@ glade_editor_property_real_get_property (GObject *object,
       case PROP_DISABLE_CHECK:
        g_value_set_boolean (value, eprop->priv->disable_check);
        break;
+      case PROP_CUSTOM_TEXT:
+       g_value_set_string (value, eprop->priv->custom_text);
+       break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -642,6 +685,13 @@ glade_editor_property_class_init (GladeEditorPropertyClass *eprop_class)
         _("Whether to explicitly disable the check button"),
         FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
+  g_object_class_install_property
+      (object_class, PROP_CUSTOM_TEXT,
+       g_param_spec_string
+       ("custom-text", _("Custom Text"),
+        _("Custom Text to display in the property label"),
+        NULL, G_PARAM_READWRITE));
+
   g_type_class_add_private (eprop_class, sizeof (GladeEditorPropertyPrivate));
 }
 
@@ -2388,7 +2438,6 @@ typedef struct
   GladeEditorProperty parent_instance;
 
   GtkWidget *button;
-  GtkWidget *label;
 } GladeEPropCheck;
 
 GLADE_MAKE_EPROP (GladeEPropCheck, glade_eprop_check)
@@ -2408,20 +2457,9 @@ glade_eprop_check_finalize (GObject *object)
 static void
 glade_eprop_check_load (GladeEditorProperty *eprop, GladeProperty *property)
 {
-  GladeEPropCheck *eprop_check = GLADE_EPROP_CHECK (eprop);
-  GladeWidget *widget;
-
   /* Chain up first */
   editor_property_class->load (eprop, property);
 
-  /* Load the inner label */
-  if (property)
-    {
-      widget = glade_property_get_widget (property);
-      if (widget)
-       glade_editable_load (GLADE_EDITABLE (eprop_check->label), widget);
-    }
-
   if (property)
     {
       GladeEPropCheck *eprop_check = GLADE_EPROP_CHECK (eprop);
@@ -2453,22 +2491,26 @@ glade_eprop_check_create_input (GladeEditorProperty *eprop)
 {
   GladeEPropCheck *eprop_check = GLADE_EPROP_CHECK (eprop);
   GladePropertyClass *pclass;
+  GtkWidget *label;
 
   pclass = eprop->priv->klass;
 
   /* Add the property label as the check button's child */
-  eprop_check->label = glade_property_label_new ();
-  glade_property_label_set_property_name (GLADE_PROPERTY_LABEL (eprop_check->label),
+  label = glade_editor_property_get_item_label (eprop);
+
+  glade_property_label_set_property_name (GLADE_PROPERTY_LABEL (label),
                                          glade_property_class_id (pclass));
-  glade_property_label_set_packing (GLADE_PROPERTY_LABEL (eprop_check->label),
+  glade_property_label_set_packing (GLADE_PROPERTY_LABEL (label),
                                    glade_property_class_get_is_packing (pclass));
-  glade_property_label_set_append_colon (GLADE_PROPERTY_LABEL (eprop_check->label), FALSE);
-  gtk_widget_show (eprop_check->label);
+  glade_property_label_set_append_colon (GLADE_PROPERTY_LABEL (label), FALSE);
+  glade_property_label_set_custom_text (GLADE_PROPERTY_LABEL (label),
+                                       eprop->priv->custom_text);
+  gtk_widget_show (label);
   
   eprop_check->button = gtk_check_button_new ();
   gtk_button_set_focus_on_click (GTK_BUTTON (eprop_check->button), FALSE);
 
-  gtk_container_add (GTK_CONTAINER (eprop_check->button), eprop_check->label);
+  gtk_container_add (GTK_CONTAINER (eprop_check->button), label);
 
   gtk_widget_set_halign (eprop_check->button, GTK_ALIGN_START);
   gtk_widget_set_valign (eprop_check->button, GTK_ALIGN_CENTER);
diff --git a/gladeui/glade-editor-property.h b/gladeui/glade-editor-property.h
index e8155bb..f7dd553 100644
--- a/gladeui/glade-editor-property.h
+++ b/gladeui/glade-editor-property.h
@@ -107,9 +107,11 @@ void                 glade_editor_property_load_by_widget (GladeEditorProperty *
 
 void                 glade_editor_property_commit         (GladeEditorProperty *eprop,
                                                           GValue              *value);
-
 void                 glade_editor_property_commit_no_callback (GladeEditorProperty *eprop,
                                                               GValue              *value);
+void                 glade_editor_property_set_custom_text(GladeEditorProperty *eprop,
+                                                          const gchar         *custom_text);
+const gchar         *glade_editor_property_get_custom_text(GladeEditorProperty *eprop);
 
 GtkWidget           *glade_editor_property_get_item_label  (GladeEditorProperty *eprop);
 GladePropertyClass  *glade_editor_property_get_pclass      (GladeEditorProperty *eprop);
diff --git a/gladeui/glade-property-shell.c b/gladeui/glade-property-shell.c
index a2bdc5c..d27cb6c 100644
--- a/gladeui/glade-property-shell.c
+++ b/gladeui/glade-property-shell.c
@@ -57,6 +57,7 @@ struct _GladePropertyShellPrivate
   /* Properties, used to load the internal editor */
   GType                editor_type;
   gchar               *property_name;
+  gchar               *custom_text;
   guint                packing : 1;
   guint                use_command : 1;
 };
@@ -66,7 +67,8 @@ enum {
   PROP_PROPERTY_NAME,
   PROP_PACKING,
   PROP_USE_COMMAND,
-  PROP_EDITOR_TYPE
+  PROP_EDITOR_TYPE,
+  PROP_CUSTOM_TEXT
 };
 
 enum
@@ -129,6 +131,12 @@ glade_property_shell_class_init (GladePropertyShellClass *class)
                            _("Specify the actual editor property type name to use for this shell"),
                            NULL, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
 
+  g_object_class_install_property
+      (gobject_class, PROP_CUSTOM_TEXT,
+       g_param_spec_string ("custom-text", _("Custom Text"),
+                           _("Custom Text to display in the property label"),
+                           NULL, G_PARAM_READWRITE));
+
   /**
    * GladePropertyShell::pre-commit:
    * @gladeeditorproperty: the #GladeEditorProperty which changed value
@@ -174,6 +182,7 @@ glade_property_shell_finalize (GObject *object)
   GladePropertyShell *shell = GLADE_PROPERTY_SHELL (object);
 
   g_free (shell->priv->property_name);
+  g_free (shell->priv->custom_text);
 
   G_OBJECT_CLASS (glade_property_shell_parent_class)->finalize (object);
 }
@@ -212,6 +221,9 @@ glade_property_shell_set_real_property (GObject         *object,
        priv->editor_type = type;
 
       break;
+    case PROP_CUSTOM_TEXT:
+      glade_property_shell_set_custom_text (shell, g_value_get_string (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -237,6 +249,9 @@ glade_property_shell_get_real_property (GObject         *object,
     case PROP_USE_COMMAND:
       g_value_set_boolean (value, glade_property_shell_get_use_command (shell));
       break;
+    case PROP_CUSTOM_TEXT:
+      g_value_set_string (value, glade_property_shell_get_custom_text (shell));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -284,6 +299,8 @@ glade_property_shell_set_eprop (GladePropertyShell  *shell,
 
       if (priv->property_editor)
        {
+         glade_editor_property_set_custom_text (priv->property_editor, priv->custom_text);
+
          priv->pre_commit_id = g_signal_connect (priv->property_editor, "commit",
                                                  G_CALLBACK (propagate_pre_commit), shell);
          priv->post_commit_id = g_signal_connect_after (priv->property_editor, "commit",
@@ -410,7 +427,7 @@ glade_property_shell_set_property_name (GladePropertyShell *shell,
 
   priv = shell->priv;
 
-  if (g_strcmp0 (priv->property_name, property_name))
+  if (g_strcmp0 (priv->property_name, property_name) != 0)
     {
       g_free (priv->property_name);
       priv->property_name = g_strdup (property_name);
@@ -428,6 +445,36 @@ glade_property_shell_get_property_name (GladePropertyShell *shell)
 }
 
 void
+glade_property_shell_set_custom_text (GladePropertyShell *shell,
+                                     const gchar        *custom_text)
+{
+  GladePropertyShellPrivate *priv;
+
+  g_return_if_fail (GLADE_IS_PROPERTY_SHELL (shell));
+
+  priv = shell->priv;
+
+  if (g_strcmp0 (priv->custom_text, custom_text) != 0)
+    {
+      g_free (priv->custom_text);
+      priv->custom_text = g_strdup (custom_text);
+
+      if (priv->property_editor)
+       glade_editor_property_set_custom_text (priv->property_editor, custom_text);
+
+      g_object_notify (G_OBJECT (shell), "custom-text");
+    }
+}
+
+const gchar *
+glade_property_shell_get_custom_text (GladePropertyShell *shell)
+{
+  g_return_val_if_fail (GLADE_IS_PROPERTY_SHELL (shell), NULL);
+
+  return shell->priv->custom_text;
+}
+
+void
 glade_property_shell_set_packing (GladePropertyShell *shell,
                                  gboolean            packing)
 {
diff --git a/gladeui/glade-property-shell.h b/gladeui/glade-property-shell.h
index 2c4c8fe..baace4b 100644
--- a/gladeui/glade-property-shell.h
+++ b/gladeui/glade-property-shell.h
@@ -59,6 +59,9 @@ GtkWidget     *glade_property_shell_new               (void);
 void           glade_property_shell_set_property_name (GladePropertyShell *shell,
                                                       const gchar        *property_name);
 const gchar   *glade_property_shell_get_property_name (GladePropertyShell *shell);
+void           glade_property_shell_set_custom_text   (GladePropertyShell *shell,
+                                                      const gchar        *custom_text);
+const gchar   *glade_property_shell_get_custom_text   (GladePropertyShell *shell);
 void           glade_property_shell_set_packing       (GladePropertyShell *shell,
                                                       gboolean            packing);
 gboolean       glade_property_shell_get_packing       (GladePropertyShell *shell);


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