[glade] Added GladePropertyShell class.



commit 715b85deae9398205e1acb0b32663c47e56a48ae
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Sat Apr 13 17:25:15 2013 +0900

    Added GladePropertyShell class.
    
    The GladePropertyShell automates the creation of a child editor property.

 gladeui/Makefile.am            |   2 +
 gladeui/glade-property-shell.c | 299 +++++++++++++++++++++++++++++++++++++++++
 gladeui/glade-property-shell.h |  73 ++++++++++
 3 files changed, 374 insertions(+)
---
diff --git a/gladeui/Makefile.am b/gladeui/Makefile.am
index d643648..a68c600 100644
--- a/gladeui/Makefile.am
+++ b/gladeui/Makefile.am
@@ -103,6 +103,7 @@ libgladeui_2_la_SOURCES = \
        glade-property.c \
        glade-property-class.c \
        glade-property-label.c \
+       glade-property-shell.c \
        glade-signal.c \
        glade-signal-class.c \
        glade-signal-editor.c \
@@ -155,6 +156,7 @@ libgladeuiinclude_HEADERS = \
        glade-property.h \
        glade-property-class.h \
        glade-property-label.h \
+       glade-property-shell.h \
        glade-signal.h \
        glade-signal-class.h \
        glade-signal-editor.h \
diff --git a/gladeui/glade-property-shell.c b/gladeui/glade-property-shell.c
new file mode 100644
index 0000000..a446d83
--- /dev/null
+++ b/gladeui/glade-property-shell.c
@@ -0,0 +1,299 @@
+/*
+ * Copyright (C) 2013 Tristan Van Berkom.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public 
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Authors:
+ *   Tristan Van Berkom <tvb gnome org>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n-lib.h>
+
+#include "glade.h"
+#include "glade-widget.h"
+#include "glade-popup.h"
+#include "glade-property-shell.h"
+
+/* GObjectClass */
+static void      glade_property_shell_finalize          (GObject         *object);
+static void      glade_property_shell_set_real_property (GObject         *object,
+                                                        guint            prop_id,
+                                                        const GValue    *value,
+                                                        GParamSpec      *pspec);
+static void      glade_property_shell_get_real_property (GObject         *object,
+                                                        guint            prop_id,
+                                                        GValue          *value,
+                                                        GParamSpec      *pspec);
+
+struct _GladePropertyShellPrivate
+{
+  /* Current State */
+  GladeWidgetAdaptor  *adaptor;
+  GladeEditorProperty *property_editor;
+
+  /* Properties, used to load the internal editor */
+  gchar               *property_name;
+  guint                packing : 1;
+  guint                use_command : 1;
+};
+
+enum {
+  PROP_0,
+  PROP_PROPERTY_NAME,
+  PROP_PACKING,
+  PROP_USE_COMMAND,
+};
+
+G_DEFINE_TYPE (GladePropertyShell, glade_property_shell, GTK_TYPE_BOX);
+
+static void
+glade_property_shell_init (GladePropertyShell *shell)
+{
+  shell->priv = 
+    G_TYPE_INSTANCE_GET_PRIVATE (shell,
+                                GLADE_TYPE_PROPERTY_SHELL,
+                                GladePropertyShellPrivate);
+
+  shell->priv->packing = FALSE;
+  shell->priv->use_command = TRUE;
+}
+
+static void
+glade_property_shell_class_init (GladePropertyShellClass *class)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+  
+  gobject_class->finalize = glade_property_shell_finalize;
+  gobject_class->set_property = glade_property_shell_set_real_property;
+  gobject_class->get_property = glade_property_shell_get_real_property;
+
+  g_object_class_install_property
+      (gobject_class, PROP_PROPERTY_NAME,
+       g_param_spec_string ("property-name", _("Property Name"),
+                           _("The property name to use when loading by widget"),
+                           NULL, G_PARAM_READWRITE));
+
+  g_object_class_install_property
+      (gobject_class, PROP_PACKING,
+       g_param_spec_boolean ("packing", _("Packing"),
+                            _("Whether the property to load is a packing property or not"),
+                            FALSE, G_PARAM_READWRITE));
+
+  g_object_class_install_property
+      (gobject_class, PROP_USE_COMMAND,
+       g_param_spec_boolean ("use-command", _("Use Command"),
+                            _("Whether to use the GladeCommand API when modifying properties"),
+                            FALSE, G_PARAM_READWRITE));
+
+  g_type_class_add_private (gobject_class, sizeof (GladePropertyShellPrivate));
+}
+
+
+/***********************************************************
+ *                     GObjectClass                        *
+ ***********************************************************/
+static void
+glade_property_shell_finalize (GObject *object)
+{
+  GladePropertyShell *shell = GLADE_PROPERTY_SHELL (object);
+
+  g_free (shell->priv->property_name);
+
+  G_OBJECT_CLASS (glade_property_shell_parent_class)->finalize (object);
+}
+
+static void
+glade_property_shell_set_real_property (GObject         *object,
+                                       guint            prop_id,
+                                       const GValue    *value,
+                                       GParamSpec      *pspec)
+{
+  GladePropertyShell *shell = GLADE_PROPERTY_SHELL (object);
+
+  switch (prop_id)
+    {
+    case PROP_PROPERTY_NAME:
+      glade_property_shell_set_property_name (shell, g_value_get_string (value));
+      break;
+    case PROP_PACKING:
+      glade_property_shell_set_packing (shell, g_value_get_boolean (value));
+      break;
+    case PROP_USE_COMMAND:
+      glade_property_shell_set_use_command (shell, g_value_get_boolean (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+glade_property_shell_get_real_property (GObject         *object,
+                                       guint            prop_id,
+                                       GValue          *value,
+                                       GParamSpec      *pspec)
+{
+  GladePropertyShell *shell = GLADE_PROPERTY_SHELL (object);
+
+  switch (prop_id)
+    {
+    case PROP_PROPERTY_NAME:
+      g_value_set_string (value, glade_property_shell_get_property_name (shell));
+      break;
+    case PROP_PACKING:
+      g_value_set_boolean (value, glade_property_shell_get_packing (shell));
+      break;
+    case PROP_USE_COMMAND:
+      g_value_set_boolean (value, glade_property_shell_get_use_command (shell));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+/***********************************************************
+ *                            API                          *
+ ***********************************************************/
+GtkWidget *
+glade_property_shell_new (void)
+{
+  return g_object_new (GLADE_TYPE_PROPERTY_SHELL, NULL);
+}
+
+void
+glade_property_shell_load_by_widget (GladePropertyShell *shell,
+                                    GladeWidget        *widget)
+{
+  GladePropertyShellPrivate *priv;
+
+  g_return_if_fail (GLADE_IS_PROPERTY_SHELL (shell));
+  g_return_if_fail (widget == NULL || GLADE_IS_WIDGET (widget));
+  g_return_if_fail (shell->priv->property_name != NULL);
+
+  priv = shell->priv;
+
+  if (widget)
+    {
+      GladeWidgetAdaptor *adaptor = glade_widget_get_adaptor (widget);
+
+      /* Need to rebuild the internal editor */
+      if (priv->adaptor != adaptor)
+       {
+         if (priv->property_editor)
+           gtk_widget_destroy (GTK_WIDGET (priv->property_editor));
+
+         priv->adaptor = adaptor;
+
+         priv->property_editor = 
+           glade_widget_adaptor_create_eprop_by_name (priv->adaptor,
+                                                      priv->property_name,
+                                                      priv->packing,
+                                                      priv->use_command);
+
+         if (priv->property_editor)
+           gtk_container_add (GTK_CONTAINER (shell), GTK_WIDGET (priv->property_editor));
+       }
+
+      /* If we have an editor for the right adaptor, load it */
+      if (priv->property_editor)
+       glade_editor_property_load_by_widget (priv->property_editor, widget);
+    }
+  else if (priv->property_editor)
+    glade_editor_property_load_by_widget (priv->property_editor, NULL);
+}
+
+void
+glade_property_shell_set_property_name (GladePropertyShell *shell,
+                                       const gchar        *property_name)
+{
+  GladePropertyShellPrivate *priv;
+
+  g_return_if_fail (GLADE_IS_PROPERTY_SHELL (shell));
+
+  priv = shell->priv;
+
+  if (g_strcmp0 (priv->property_name, property_name))
+    {
+      g_free (priv->property_name);
+      priv->property_name = g_strdup (property_name);
+
+      g_object_notify (G_OBJECT (shell), "property-name");
+    }
+}
+
+const gchar *
+glade_property_shell_get_property_name (GladePropertyShell *shell)
+{
+  g_return_val_if_fail (GLADE_IS_PROPERTY_SHELL (shell), NULL);
+
+  return shell->priv->property_name;
+}
+
+void
+glade_property_shell_set_packing (GladePropertyShell *shell,
+                                 gboolean            packing)
+{
+  GladePropertyShellPrivate *priv;
+
+  g_return_if_fail (GLADE_IS_PROPERTY_SHELL (shell));
+
+  priv = shell->priv;
+
+  if (priv->packing != packing)
+    {
+      priv->packing = packing;
+
+      g_object_notify (G_OBJECT (shell), "packing");
+    }
+}
+
+gboolean
+glade_property_shell_get_packing (GladePropertyShell *shell)
+{
+  g_return_val_if_fail (GLADE_IS_PROPERTY_SHELL (shell), FALSE);
+
+  return shell->priv->packing;
+}
+
+void
+glade_property_shell_set_use_command (GladePropertyShell *shell,
+                                     gboolean            use_command)
+{
+  GladePropertyShellPrivate *priv;
+
+  g_return_if_fail (GLADE_IS_PROPERTY_SHELL (shell));
+
+  priv = shell->priv;
+
+  if (priv->use_command != use_command)
+    {
+      priv->use_command = use_command;
+
+      g_object_notify (G_OBJECT (shell), "use-command");
+    }
+}
+
+gboolean
+glade_property_shell_get_use_command (GladePropertyShell *shell)
+{
+  g_return_val_if_fail (GLADE_IS_PROPERTY_SHELL (shell), FALSE);
+
+  return shell->priv->use_command;
+}
diff --git a/gladeui/glade-property-shell.h b/gladeui/glade-property-shell.h
new file mode 100644
index 0000000..75b168d
--- /dev/null
+++ b/gladeui/glade-property-shell.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2013 Tristan Van Berkom.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public 
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Authors:
+ *   Tristan Van Berkom <tvb gnome org>
+ */
+#ifndef __GLADE_PROPERTY_SHELL_H__
+#define __GLADE_PROPERTY_SHELL_H__
+
+#include <gtk/gtk.h>
+#include <gladeui/glade-xml-utils.h>
+#include <gladeui/glade-property-class.h>
+#include <gladeui/glade-property.h>
+
+G_BEGIN_DECLS
+
+#define GLADE_TYPE_PROPERTY_SHELL            (glade_property_shell_get_type ())
+#define GLADE_PROPERTY_SHELL(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_PROPERTY_SHELL, 
GladePropertyShell))
+#define GLADE_PROPERTY_SHELL_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_PROPERTY_SHELL, 
GladePropertyShellClass))
+#define GLADE_IS_PROPERTY_SHELL(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_PROPERTY_SHELL))
+#define GLADE_IS_PROPERTY_SHELL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_PROPERTY_SHELL))
+#define GLADE_PROPERTY_SHELL_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_PROPERTY_SHELL, 
GladePropertyShellClass))
+
+typedef struct _GladePropertyShell             GladePropertyShell;
+typedef struct _GladePropertyShellClass        GladePropertyShellClass;
+typedef struct _GladePropertyShellPrivate      GladePropertyShellPrivate;
+
+struct _GladePropertyShell
+{
+  /*< private >*/
+  GtkBox box;
+
+  GladePropertyShellPrivate *priv;
+};
+
+struct _GladePropertyShellClass
+{
+  GtkBoxClass parent_class;
+};
+
+GType          glade_property_shell_get_type          (void) G_GNUC_CONST;
+
+GtkWidget     *glade_property_shell_new               (void);
+
+void           glade_property_shell_load_by_widget    (GladePropertyShell *shell,
+                                                      GladeWidget        *widget);
+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_packing       (GladePropertyShell *shell,
+                                                      gboolean            packing);
+gboolean       glade_property_shell_get_packing       (GladePropertyShell *shell);
+void           glade_property_shell_set_use_command   (GladePropertyShell *shell,
+                                                      gboolean            use_command);
+gboolean       glade_property_shell_get_use_command   (GladePropertyShell *shell);
+
+G_END_DECLS
+
+#endif /* __GLADE_PROPERTY_SHELL_H__ */


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