glade3 r2009 - in trunk: . plugins/gtk+



Author: tvb
Date: Tue Oct 28 16:42:46 2008
New Revision: 2009
URL: http://svn.gnome.org/viewvc/glade3?rev=2009&view=rev

Log:
	
	* plugins/gtk+/glade-store-editor.[ch], plugins/gtk+/Makefile.am,
	plugins/gtk+/gtk+.xml.in, plugins/gtk+/glade-gtk.c:
	Added liststore/treestore editor widget (only to better format the "columns"
	and "data" properties so that it takes the whole width with the treeview.



Added:
   trunk/plugins/gtk+/glade-store-editor.c
   trunk/plugins/gtk+/glade-store-editor.h
Modified:
   trunk/ChangeLog
   trunk/plugins/gtk+/Makefile.am
   trunk/plugins/gtk+/glade-gtk.c
   trunk/plugins/gtk+/gtk+.xml.in

Modified: trunk/plugins/gtk+/Makefile.am
==============================================================================
--- trunk/plugins/gtk+/Makefile.am	(original)
+++ trunk/plugins/gtk+/Makefile.am	Tue Oct 28 16:42:46 2008
@@ -26,7 +26,7 @@
 libgladegtk_la_SOURCES     = glade-gtk.c glade-accels.c glade-attributes.c glade-convert.c fixed-bg.xpm \
 	glade-column-types.c  glade-model-data.c glade-text-button.c glade-cell-renderer-button.c \
 	glade-icon-sources.c glade-button-editor.c glade-tool-button-editor.c glade-image-editor.c \
-	glade-image-item-editor.c glade-icon-factory-editor.c
+	glade-image-item-editor.c glade-icon-factory-editor.c glade-store-editor.c
 
 libgladegtk_la_LDFLAGS     = -module -avoid-version $(AM_LDFLAGS)
 libgladegtk_la_LIBADD      = $(libgladeui) $(GTK_LIBS)
@@ -34,7 +34,8 @@
 libgladegtkincludedir= $(includedir)/libgladeui-1.0/gladeui
 libgladegtkinclude_HEADERS = glade-gtk.h glade-accels.h glade-attributes.h glade-column-types.h glade-model-data.h \
 	glade-text-button.h glade-cell-renderer-button.h glade-icon-sources.h glade-button-editor.h \
-	glade-tool-button-editor.h glade-image-editor.h glade-image-item-editor.h glade-icon-factory-editor.h
+	glade-tool-button-editor.h glade-image-editor.h glade-image-item-editor.h glade-icon-factory-editor.h \
+	glade-store-editor.h
 
 if PLATFORM_WIN32
 libgladegtk_la_LDFLAGS += -no-undefined

Modified: trunk/plugins/gtk+/glade-gtk.c
==============================================================================
--- trunk/plugins/gtk+/glade-gtk.c	(original)
+++ trunk/plugins/gtk+/glade-gtk.c	Tue Oct 28 16:42:46 2008
@@ -36,6 +36,7 @@
 #include "glade-image-editor.h"
 #include "glade-image-item-editor.h"
 #include "glade-icon-factory-editor.h"
+#include "glade-store-editor.h"
 
 #include <gladeui/glade-editor-property.h>
 #include <gladeui/glade-base-editor.h>
@@ -8494,6 +8495,21 @@
 	return eprop;
 }
 
+GladeEditable *
+glade_gtk_store_create_editable (GladeWidgetAdaptor  *adaptor,
+				 GladeEditorPageType  type)
+{
+	GladeEditable *editable;
+
+	/* Get base editable */
+	editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type);
+
+	if (type == GLADE_PAGE_GENERAL)
+		return (GladeEditable *)glade_store_editor_new (adaptor, editable);
+
+	return editable;
+}
+
 gchar *
 glade_gtk_store_string_from_value (GladeWidgetAdaptor *adaptor,
 				   GladePropertyClass *klass,

Added: trunk/plugins/gtk+/glade-store-editor.c
==============================================================================
--- (empty file)
+++ trunk/plugins/gtk+/glade-store-editor.c	Tue Oct 28 16:42:46 2008
@@ -0,0 +1,232 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008 Tristan Van Berkom.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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>
+ */
+
+#include <config.h>
+#include <gladeui/glade.h>
+#include <glib/gi18n-lib.h>
+#include <gdk/gdkkeysyms.h>
+
+#include "glade-store-editor.h"
+
+
+static void glade_store_editor_finalize        (GObject              *object);
+
+static void glade_store_editor_editable_init   (GladeEditableIface *iface);
+
+static void glade_store_editor_grab_focus      (GtkWidget            *widget);
+
+
+G_DEFINE_TYPE_WITH_CODE (GladeStoreEditor, glade_store_editor, GTK_TYPE_VBOX,
+                         G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE,
+                                                glade_store_editor_editable_init));
+
+
+static void
+glade_store_editor_class_init (GladeStoreEditorClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+	object_class->finalize     = glade_store_editor_finalize;
+	widget_class->grab_focus   = glade_store_editor_grab_focus;
+}
+
+static void
+glade_store_editor_init (GladeStoreEditor *self)
+{
+}
+
+static void
+project_changed (GladeProject      *project,
+		 GladeCommand      *command,
+		 gboolean           execute,
+		 GladeStoreEditor  *store_editor)
+{
+	if (!GTK_WIDGET_MAPPED (store_editor))
+		return;
+
+	/* Reload on all commands */
+	glade_editable_load (GLADE_EDITABLE (store_editor), store_editor->loaded_widget);
+}
+
+
+static void
+project_finalized (GladeStoreEditor *store_editor,
+		   GladeProject       *where_project_was)
+{
+	store_editor->loaded_widget = NULL;
+
+	glade_editable_load (GLADE_EDITABLE (store_editor), NULL);
+}
+
+static void
+glade_store_editor_load (GladeEditable *editable,
+			 GladeWidget   *widget)
+{
+	GladeStoreEditor    *store_editor = GLADE_STORE_EDITOR (editable);
+	GList               *l;
+
+	/* Since we watch the project*/
+	if (store_editor->loaded_widget)
+	{
+		/* watch custom-child and use-stock properties here for reloads !!! */
+
+		g_signal_handlers_disconnect_by_func (G_OBJECT (store_editor->loaded_widget->project),
+						      G_CALLBACK (project_changed), store_editor);
+
+		/* The widget could die unexpectedly... */
+		g_object_weak_unref (G_OBJECT (store_editor->loaded_widget->project),
+				     (GWeakNotify)project_finalized,
+				     store_editor);
+	}
+
+	/* Mark our widget... */
+	store_editor->loaded_widget = widget;
+
+	if (store_editor->loaded_widget)
+	{
+		/* This fires for undo/redo */
+		g_signal_connect (G_OBJECT (store_editor->loaded_widget->project), "changed",
+				  G_CALLBACK (project_changed), store_editor);
+
+		/* The widget/project could die unexpectedly... */
+		g_object_weak_ref (G_OBJECT (store_editor->loaded_widget->project),
+				   (GWeakNotify)project_finalized,
+				   store_editor);
+	}
+
+	/* load the embedded editable... */
+	if (store_editor->embed)
+		glade_editable_load (GLADE_EDITABLE (store_editor->embed), widget);
+
+	for (l = store_editor->properties; l; l = l->next)
+		glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget);
+}
+
+static void
+glade_store_editor_set_show_name (GladeEditable *editable,
+				   gboolean       show_name)
+{
+	GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (editable);
+
+	glade_editable_set_show_name (GLADE_EDITABLE (store_editor->embed), show_name);
+}
+
+static void
+glade_store_editor_editable_init (GladeEditableIface *iface)
+{
+	iface->load = glade_store_editor_load;
+	iface->set_show_name = glade_store_editor_set_show_name;
+}
+
+static void
+glade_store_editor_finalize (GObject *object)
+{
+	GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (object);
+
+	if (store_editor->properties)
+		g_list_free (store_editor->properties);
+	store_editor->properties = NULL;
+	store_editor->embed      = NULL;
+
+	glade_editable_load (GLADE_EDITABLE (object), NULL);
+
+	G_OBJECT_CLASS (glade_store_editor_parent_class)->finalize (object);
+}
+
+static void
+glade_store_editor_grab_focus (GtkWidget *widget)
+{
+	GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (widget);
+
+	gtk_widget_grab_focus (store_editor->embed);
+}
+
+GtkWidget *
+glade_store_editor_new (GladeWidgetAdaptor *adaptor,
+			GladeEditable      *embed)
+{
+	GladeStoreEditor    *store_editor;
+	GladeEditorProperty *eprop;
+	GtkWidget           *frame, *alignment, *label, *vbox;
+
+	g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
+	g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL);
+
+	/* Pack the parent on top... */
+	store_editor = g_object_new (GLADE_TYPE_STORE_EDITOR, NULL);
+	store_editor->embed = GTK_WIDGET (embed);
+	gtk_box_pack_start (GTK_BOX (store_editor), GTK_WIDGET (embed), FALSE, FALSE, 0);
+
+	/* -------------- The columns area here -------------- */
+	/* Label item in frame label widget on top.. */
+	eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "columns", FALSE, TRUE);
+	store_editor->properties = g_list_prepend (store_editor->properties, eprop);
+	frame = gtk_frame_new (NULL);
+	gtk_frame_set_label_widget (GTK_FRAME (frame), eprop->item_label);
+	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
+	gtk_box_pack_start (GTK_BOX (store_editor), frame, FALSE, FALSE, 12);
+
+	/* Alignment/Vbox in frame... */
+	alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F);
+	gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0);
+	gtk_container_add (GTK_CONTAINER (frame), alignment);
+	vbox = gtk_vbox_new (FALSE, 0);
+	gtk_container_add (GTK_CONTAINER (alignment), vbox);
+
+	/* Add descriptive label */
+	label = gtk_label_new (_("Define columns for your liststore, "
+				 "giving them meaningful names will help you to retrieve "
+				 "them when setting cell renderer attributes."));
+	gtk_label_set_line_wrap (GTK_LABEL(label), TRUE);
+	gtk_label_set_line_wrap_mode (GTK_LABEL(label), PANGO_WRAP_WORD);
+	gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 6);
+	gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (eprop), FALSE, FALSE, 4);
+
+
+	/* -------------- The data area here -------------- */
+	/* Label item in frame label widget on top.. */
+	eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "data", FALSE, TRUE);
+	store_editor->properties = g_list_prepend (store_editor->properties, eprop);
+	frame = gtk_frame_new (NULL);
+	gtk_frame_set_label_widget (GTK_FRAME (frame), eprop->item_label);
+	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
+	gtk_box_pack_start (GTK_BOX (store_editor), frame, FALSE, FALSE, 12);
+
+	/* Alignment/Vbox in frame... */
+	alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F);
+	gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0);
+	gtk_container_add (GTK_CONTAINER (frame), alignment);
+	vbox = gtk_vbox_new (FALSE, 0);
+	gtk_container_add (GTK_CONTAINER (alignment), vbox);
+
+	/* Add descriptive label */
+	label = gtk_label_new (_("Add remove and edit rows of data (define some columns first)."));
+	gtk_label_set_line_wrap (GTK_LABEL(label), TRUE);
+	gtk_label_set_line_wrap_mode (GTK_LABEL(label), PANGO_WRAP_WORD);
+	gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 6);
+	gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (eprop), FALSE, FALSE, 4);
+
+	gtk_widget_show_all (GTK_WIDGET (store_editor));
+
+	return GTK_WIDGET (store_editor);
+}

Added: trunk/plugins/gtk+/glade-store-editor.h
==============================================================================
--- (empty file)
+++ trunk/plugins/gtk+/glade-store-editor.h	Tue Oct 28 16:42:46 2008
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008 Tristan Van Berkom.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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_STORE_EDITOR_H_
+#define _GLADE_STORE_EDITOR_H_
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GLADE_TYPE_STORE_EDITOR	            (glade_store_editor_get_type ())
+#define GLADE_STORE_EDITOR(obj)		    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_STORE_EDITOR, GladeStoreEditor))
+#define GLADE_STORE_EDITOR_CLASS(klass)	    (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_STORE_EDITOR, GladeStoreEditorClass))
+#define GLADE_IS_STORE_EDITOR(obj)	    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_STORE_EDITOR))
+#define GLADE_IS_STORE_EDITOR_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_STORE_EDITOR))
+#define GLADE_STORE_EDITOR_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_STORE_EDITOR, GladeStoreEditorClass))
+
+typedef struct _GladeStoreEditor        GladeStoreEditor;
+typedef struct _GladeStoreEditorClass   GladeStoreEditorClass;
+
+struct _GladeStoreEditor
+{
+	GtkVBox  parent;
+
+	GladeWidget *loaded_widget; /* A handy pointer to the loaded widget ... */
+
+	GtkWidget *embed;
+
+	GList *properties;         /* A list of eprops to update at load() time */
+};
+
+struct _GladeStoreEditorClass
+{
+	GtkVBoxClass parent;
+};
+
+GType            glade_store_editor_get_type (void);
+GtkWidget       *glade_store_editor_new      (GladeWidgetAdaptor *adaptor,
+					      GladeEditable      *editable);
+
+G_END_DECLS
+
+#endif  /* _GLADE_STORE_EDITOR_H_ */

Modified: trunk/plugins/gtk+/gtk+.xml.in
==============================================================================
--- trunk/plugins/gtk+/gtk+.xml.in	(original)
+++ trunk/plugins/gtk+/gtk+.xml.in	Tue Oct 28 16:42:46 2008
@@ -1644,15 +1644,16 @@
 			libglade-unsupported="True" toplevel="True">
       <set-property-function>glade_gtk_store_set_property</set-property-function>
       <create-editor-property-function>glade_gtk_store_create_eprop</create-editor-property-function>
+      <create-editable-function>glade_gtk_store_create_editable</create-editable-function>
       <string-from-value-function>glade_gtk_store_string_from_value</string-from-value-function>
       <write-widget-function>glade_gtk_store_write_widget</write-widget-function>
       <read-widget-function>glade_gtk_store_read_widget</read-widget-function>
       <properties>
-        <property id="columns" since="2.12" _name="Columns" save="False" construct-only="True">
+        <property id="columns" since="2.12" _name="Columns" save="False" construct-only="True" custom-layout="True">
           <spec>glade_standard_column_types_spec</spec>
           <_tooltip>Enter a list of column types for this data store</_tooltip>
         </property>
-        <property id="data" since="2.12" _name="Data" save="False">
+        <property id="data" since="2.12" _name="Data" save="False" custom-layout="True">
           <spec>glade_standard_model_data_spec</spec>
           <_tooltip>Enter a list of values to be applied on each row</_tooltip>
         </property>
@@ -1663,15 +1664,16 @@
 			libglade-unsupported="True" toplevel="True">
       <set-property-function>glade_gtk_store_set_property</set-property-function>
       <create-editor-property-function>glade_gtk_store_create_eprop</create-editor-property-function>
+      <create-editable-function>glade_gtk_store_create_editable</create-editable-function>
       <string-from-value-function>glade_gtk_store_string_from_value</string-from-value-function>
       <write-widget-function>glade_gtk_store_write_widget</write-widget-function>
       <read-widget-function>glade_gtk_store_read_widget</read-widget-function>
       <properties>
-        <property id="columns" since="2.12" _name="Columns" save="False" construct-only="True">
+        <property id="columns" since="2.12" _name="Columns" save="False" construct-only="True" custom-layout="True">
           <spec>glade_standard_column_types_spec</spec>
           <_tooltip>Enter a list of column types for this data store</_tooltip>
         </property>
-        <property id="data" since="2.12" _name="Data" save="False">
+        <property id="data" since="2.12" _name="Data" save="False" custom-layout="True">
           <spec>glade_standard_model_data_spec</spec>
           <_tooltip>Enter a list of values to be applied on each row</_tooltip>
         </property>



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