glade3 r1990 - in trunk: . gladeui



Author: tvb
Date: Thu Oct 23 17:30:14 2008
New Revision: 1990
URL: http://svn.gnome.org/viewvc/glade3?rev=1990&view=rev

Log:

	* gladeui/Makefile.am, gladeui/glade-editable.[ch], gladeui/glade-editor-table.[ch]:
	- Added GladeEditable interface used as pages by GladeEditor
	- Added GladeEditorTable widget to implmenemt the editable as the traditional table
	  with sorted properties

	* gladeui/glade-editor.[ch]: Removed lots of code, now uses GladeEditables returned
	  by thier adaptors.

	* gladeui/glade-editor-property.c: Removed obsolete doc-search signal.

	* gladeui/glade-widget-adaptor.[ch]: Added GladeCreateEditableFunc to allow backends
	  to define layouts of pages in the editor.



Added:
   trunk/gladeui/glade-editable.c
   trunk/gladeui/glade-editable.h
   trunk/gladeui/glade-editor-table.c
   trunk/gladeui/glade-editor-table.h
Modified:
   trunk/ChangeLog
   trunk/gladeui/Makefile.am
   trunk/gladeui/glade-editor-property.c
   trunk/gladeui/glade-editor-property.h
   trunk/gladeui/glade-editor.c
   trunk/gladeui/glade-editor.h
   trunk/gladeui/glade-property-class.h
   trunk/gladeui/glade-widget-adaptor.c
   trunk/gladeui/glade-widget-adaptor.h
   trunk/gladeui/glade-xml-utils.h
   trunk/gladeui/glade.h

Modified: trunk/gladeui/Makefile.am
==============================================================================
--- trunk/gladeui/Makefile.am	(original)
+++ trunk/gladeui/Makefile.am	Thu Oct 23 17:30:14 2008
@@ -64,7 +64,9 @@
 	glade-accumulators.h \
 	glade-widget-action.c \
 	glade-name-context.c \
-	glade-displayable-values.c 
+	glade-displayable-values.c \
+	glade-editable.c \
+	glade-editor-table.c
 
 libgladeui_1_la_CPPFLAGS =  \
 	$(common_defines)   \
@@ -115,7 +117,9 @@
 	glade-catalog.h \
 	glade-widget-action.h \
 	glade-name-context.h \
-	glade-displayable-values.h
+	glade-displayable-values.h \
+	glade-editable.h \
+	glade-editor-table.h
 
 
 if PLATFORM_WIN32

Added: trunk/gladeui/glade-editable.c
==============================================================================
--- (empty file)
+++ trunk/gladeui/glade-editable.c	Thu Oct 23 17:30:14 2008
@@ -0,0 +1,81 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * glade-name-context.c
+ *
+ * Copyright (C) 2008 Tristan Van Berkom.
+ *
+ * Authors:
+ *   Tristan Van Berkom <tvb gnome org>
+ *
+ * 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.
+ *
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n-lib.h>
+
+#include <string.h>
+#include <stdlib.h>
+
+
+#include "glade-widget.h"
+#include "glade-editable.h"
+
+
+static void
+glade_editable_class_init (gpointer g_iface)
+{	
+	/* */
+}
+
+GType
+glade_editable_get_type (void)
+{
+  static GType editable_type = 0;
+
+  if (!editable_type)
+    editable_type =
+      g_type_register_static_simple (G_TYPE_INTERFACE, "GladeEditable",
+				       sizeof (GladeEditableIface),
+				       (GClassInitFunc) glade_editable_class_init,
+				       0, NULL, (GTypeFlags)0);
+
+  return editable_type;
+}
+
+/**
+ * glade_editable_load:
+ * @editable: A #GladeEditable
+ * @widget: the #GladeWidget to load
+ *
+ */
+void
+glade_editable_load (GladeEditable *editable,
+		     GladeWidget   *widget)
+{
+	GladeEditableIface *iface;
+	g_return_if_fail (GLADE_IS_EDITABLE (editable));
+	g_return_if_fail (widget == NULL || GLADE_IS_WIDGET (widget));
+
+	iface = GLADE_EDITABLE_GET_IFACE (editable);
+
+	if (iface->load)
+		iface->load (editable, widget);
+	else
+		g_critical ("No GladeEditable::load() support on type %s", 
+			    G_OBJECT_TYPE_NAME (editable));
+}

Added: trunk/gladeui/glade-editable.h
==============================================================================
--- (empty file)
+++ trunk/gladeui/glade-editable.h	Thu Oct 23 17:30:14 2008
@@ -0,0 +1,47 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+#ifndef __GLADE_EDITABLE_H__
+#define __GLADE_EDITABLE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GLADE_TYPE_EDITABLE            (glade_editable_get_type ())
+#define GLADE_EDITABLE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EDITABLE, GladeEditable))
+#define GLADE_EDITABLE_CLASS(obj)      (G_TYPE_CHECK_CLASS_CAST ((obj), GLADE_TYPE_EDITABLE, GladeEditableIface))
+#define GLADE_IS_EDITABLE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EDITABLE))
+#define GLADE_EDITABLE_GET_IFACE(obj)  (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GLADE_TYPE_EDITABLE, GladeEditableIface))
+
+
+typedef struct _GladeEditable      GladeEditable; /* Dummy typedef */
+typedef struct _GladeEditableIface GladeEditableIface;
+
+typedef enum
+{
+	GLADE_PAGE_GENERAL,
+	GLADE_PAGE_COMMON,
+	GLADE_PAGE_PACKING,
+	GLADE_PAGE_ATK,
+	GLADE_PAGE_QUERY
+} GladeEditorPageType;
+
+
+struct _GladeEditableIface
+{
+	GTypeInterface g_iface;
+
+	/* virtual table */
+	void          (* load)       (GladeEditable  *editable,
+				      GladeWidget    *widget);
+
+};
+
+GType     glade_editable_get_type    (void) G_GNUC_CONST;
+void      glade_editable_load        (GladeEditable *editable,
+				      GladeWidget   *widget);
+
+
+G_END_DECLS
+
+#endif /* __GLADE_EDITABLE_H__ */

Modified: trunk/gladeui/glade-editor-property.c
==============================================================================
--- trunk/gladeui/glade-editor-property.c	(original)
+++ trunk/gladeui/glade-editor-property.c	Thu Oct 23 17:30:14 2008
@@ -57,16 +57,9 @@
 	PROP_USE_COMMAND
 };
 
-enum {
-	GTK_DOC_SEARCH,
-	LAST_SIGNAL
-};
-
 static GtkTableClass             *table_class;
 static GladeEditorPropertyClass  *editor_property_class;
 
-static guint                      glade_editor_property_signals[LAST_SIGNAL] = { 0 };
-
 #define GLADE_PROPERTY_TABLE_ROW_SPACING 2
 #define FLAGS_COLUMN_SETTING             0
 #define FLAGS_COLUMN_SYMBOL              1
@@ -570,26 +563,6 @@
 	eprop_class->load          = glade_editor_property_load_common;
 	eprop_class->create_input  = NULL;
 
-	/**
-	 * GladeEditorProperty::gtk-doc-search:
-	 * @gladeeditor: the #GladeEditorProperty which received the signal.
-	 * @arg1: the (#gchar *) book to search or %NULL
-	 * @arg2: the (#gchar *) page to search or %NULL
-	 * @arg3: the (#gchar *) search string or %NULL
-	 *
-	 * Emitted when the editor property requests that a doc-search be performed.
-	 */
-	glade_editor_property_signals[GTK_DOC_SEARCH] =
-		g_signal_new ("gtk-doc-search",
-			      G_TYPE_FROM_CLASS (object_class),
-			      G_SIGNAL_RUN_LAST,
-			      G_STRUCT_OFFSET (GladeEditorPropertyClass,
-					       gtk_doc_search),
-			      NULL, NULL,
-			      glade_marshal_VOID__STRING_STRING_STRING,
-			      G_TYPE_NONE, 3, 
-			      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
-
 	/* Properties */
 	g_object_class_install_property 
 		(object_class, PROP_PROPERTY_CLASS,

Modified: trunk/gladeui/glade-editor-property.h
==============================================================================
--- trunk/gladeui/glade-editor-property.h	(original)
+++ trunk/gladeui/glade-editor-property.h	Thu Oct 23 17:30:14 2008
@@ -123,11 +123,6 @@
 
 	GtkWidget  *(* create_input)  (GladeEditorProperty *);
 
-	void        (* gtk_doc_search)(GladeEditorProperty *, 
-				       const gchar *,
-				       const gchar *,
-				       const gchar *);
-
 };
 
 

Added: trunk/gladeui/glade-editor-table.c
==============================================================================
--- (empty file)
+++ trunk/gladeui/glade-editor-table.c	Thu Oct 23 17:30:14 2008
@@ -0,0 +1,371 @@
+/* -*- 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 "glade-editor-table.h"
+
+static void      glade_editor_table_init               (GladeEditorTable      *self);
+static void      glade_editor_table_class_init         (GladeEditorTableClass *klass);
+static void      glade_editor_table_finalize           (GObject               *object);
+static void      glade_editor_table_editable_init      (GladeEditableIface    *iface);
+static void      glade_editor_table_grab_focus         (GtkWidget             *widget);
+static void      append_packing_items                  (GladeEditorTable      *table,
+							GladeWidget           *widget);
+
+G_DEFINE_TYPE_WITH_CODE (GladeEditorTable, glade_editor_table, GTK_TYPE_TABLE,
+                         G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE,
+                                                glade_editor_table_editable_init));
+
+static void
+glade_editor_table_class_init (GladeEditorTableClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+	object_class->finalize     = glade_editor_table_finalize;
+	widget_class->grab_focus   = glade_editor_table_grab_focus;
+}
+
+static void
+glade_editor_table_init (GladeEditorTable *self)
+{
+
+}
+
+static void
+glade_editor_table_finalize (GObject *object)
+{
+	GladeEditorTable *table = GLADE_EDITOR_TABLE (object);
+
+	table->properties =
+		(g_list_free (table->properties), NULL);
+	glade_editable_load (GLADE_EDITABLE (table), NULL);
+
+	G_OBJECT_CLASS (glade_editor_table_parent_class)->finalize (object);
+}
+
+static void
+glade_editor_table_grab_focus (GtkWidget *widget)
+{
+	GladeEditorTable *editor_table = GLADE_EDITOR_TABLE (widget);
+	
+	if (editor_table->name_entry)
+		gtk_widget_grab_focus (editor_table->name_entry);
+	else if (editor_table->properties)
+		gtk_widget_grab_focus (GTK_WIDGET (editor_table->properties->data));
+	else
+		GTK_WIDGET_CLASS (glade_editor_table_parent_class)->grab_focus (widget);
+}
+
+
+static void
+widget_name_changed (GladeWidget      *widget,
+		     GParamSpec       *pspec,
+		     GladeEditorTable *table)
+{
+	table->loading = TRUE;
+	if (table->name_entry)
+		gtk_entry_set_text (GTK_ENTRY (table->name_entry), table->loaded_widget->name);
+	table->loading = FALSE;
+
+}	
+
+static void
+widget_finalized (GladeEditorTable *table,
+		  GladeWidget      *where_widget_was)
+{
+	table->loaded_widget = NULL;
+
+	glade_editable_load (GLADE_EDITABLE (table), NULL);
+}
+
+
+static void
+glade_editor_table_load (GladeEditable *editable,
+			 GladeWidget   *widget)
+{
+	GladeEditorTable    *table = GLADE_EDITOR_TABLE (editable);
+	GladeEditorProperty *property;
+	GList               *list;
+
+	/* abort mission */
+	if ((!table->loaded_widget && !widget) ||
+	    (table->loaded_widget && widget && table->loaded_widget == widget))
+		return;
+
+	table->loading = TRUE;
+
+	if (table->loaded_widget && table->name_entry)
+	{
+		g_signal_handlers_disconnect_by_func (G_OBJECT (table->loaded_widget),
+						      G_CALLBACK (widget_name_changed), table);
+
+		/* The widget could die unexpectedly... */
+		g_object_weak_unref (G_OBJECT (table->loaded_widget),
+				     (GWeakNotify)widget_finalized,
+				     table);
+	}
+
+	table->loaded_widget = widget;
+
+	if (table->loaded_widget && table->name_entry)
+	{
+		g_signal_connect (G_OBJECT (table->loaded_widget), "notify::name",
+				  G_CALLBACK (widget_name_changed), table);
+
+		/* The widget could die unexpectedly... */
+		g_object_weak_ref (G_OBJECT (table->loaded_widget),
+				     (GWeakNotify)widget_finalized,
+				     table);
+
+		gtk_entry_set_text (GTK_ENTRY (table->name_entry), widget->name);
+
+
+	}
+	else if (table->name_entry)
+		gtk_entry_set_text (GTK_ENTRY (table->name_entry), "");
+
+	/* If this is a packing page, we need to generate the properties here... */
+	if (table->loaded_widget && table->type == GLADE_PAGE_PACKING)
+		append_packing_items (table, table->loaded_widget);
+
+	/* Sync up properties, even if widget is NULL */
+	for (list = table->properties; list; list = list->next)
+	{
+		property = list->data;
+		glade_editor_property_load_by_widget (property, widget);
+	}
+
+	table->loading = FALSE;
+}
+
+static void
+glade_editor_table_editable_init (GladeEditableIface *iface)
+{
+	iface->load = glade_editor_table_load;
+}
+
+static void
+glade_editor_table_attach (GladeEditorTable *table, 
+			   GtkWidget *child, 
+			   gint pos, gint row)
+{
+	gtk_table_attach (GTK_TABLE (table), child,
+			  pos, pos+1, row, row +1,
+			  GTK_EXPAND | GTK_FILL,
+			  GTK_EXPAND | GTK_FILL,
+			  3, 1);
+}
+
+static gint
+property_class_comp (gconstpointer a, gconstpointer b)
+{
+	const GladePropertyClass *ca = a, *cb = b;
+	
+	if (ca->pspec->owner_type == cb->pspec->owner_type)
+	{
+		gdouble result = ca->weight - cb->weight;
+		/* Avoid cast to int */
+		if (result < 0.0) return -1;
+		else if (result > 0.0) return 1;
+		else return 0;
+	}
+	else
+	{
+		if (g_type_is_a (ca->pspec->owner_type, cb->pspec->owner_type))
+			return (ca->common || ca->packing) ? 1 : -1;
+		else
+			return (ca->common || ca->packing) ? -1 : 1;
+	}
+}
+
+static GList *
+get_sorted_properties (GladeWidgetAdaptor   *adaptor,
+		       GladeEditorPageType   type)
+{
+	GList *l, *list = NULL;
+	
+	for (l = adaptor->properties; l && l->data; l = g_list_next (l))
+	{
+		GladePropertyClass *klass = l->data;
+
+		/* Collect properties in our domain, query dialogs are allowed editor invisible properties */
+		if (GLADE_PROPERTY_CLASS_IS_TYPE (klass, type) && 
+		    (glade_property_class_is_visible (klass) || type != GLADE_PAGE_QUERY))
+			list = g_list_prepend (list, klass);
+			
+	}
+	return g_list_sort (list, property_class_comp);
+}
+
+static GladeEditorProperty *
+append_item (GladeEditorTable *table,
+	     GladePropertyClass *klass,
+	     gboolean from_query_dialog)
+{
+	GladeEditorProperty *property;
+
+	if (!(property = glade_widget_adaptor_create_eprop 
+	      (GLADE_WIDGET_ADAPTOR (klass->handle), 
+	       klass, from_query_dialog == FALSE)))
+	{
+		g_critical ("Unable to create editor for property '%s' of class '%s'",
+			    klass->id, GLADE_WIDGET_ADAPTOR (klass->handle)->name);
+		return NULL;
+	}
+
+	gtk_widget_show (GTK_WIDGET (property));
+	gtk_widget_show_all (property->item_label);
+
+	glade_editor_table_attach (table, property->item_label, 0, table->rows);
+	glade_editor_table_attach (table, GTK_WIDGET (property), 1, table->rows);
+
+	table->rows++;
+
+	return property;
+}
+
+
+static void
+append_items (GladeEditorTable     *table,
+	      GladeWidgetAdaptor   *adaptor,
+	      GladeEditorPageType   type)
+{
+	GladeEditorProperty *property;
+	GladePropertyClass  *property_class;
+	GList *list, *sorted_list;
+
+	sorted_list = get_sorted_properties (adaptor, type);
+	for (list = sorted_list; list != NULL; list = list->next)
+	{
+		property_class = (GladePropertyClass *) list->data;
+
+		property = append_item (table, property_class, type == GLADE_PAGE_QUERY);
+		table->properties = g_list_prepend (table->properties, property);
+	}
+	g_list_free (sorted_list);
+
+	table->properties = g_list_reverse (table->properties);
+}
+
+static void
+append_packing_items (GladeEditorTable     *table,
+		      GladeWidget          *widget)
+{
+	GladeEditorProperty *eprop;
+	GladeProperty       *property;
+	GList *list;
+
+	for (list = widget->packing_properties; list != NULL; list = list->next)
+	{
+		property       = list->data;
+
+		eprop = append_item (table, property->klass, FALSE);
+		table->properties = g_list_prepend (table->properties, eprop);
+	}
+
+	table->properties = g_list_reverse (table->properties);
+}
+
+
+static void
+widget_name_edited (GtkWidget *editable, GladeEditorTable *table)
+{
+	GladeWidget *widget;
+	gchar *new_name;
+	
+	g_return_if_fail (GTK_IS_EDITABLE (editable));
+	g_return_if_fail (GLADE_IS_EDITOR_TABLE (table));
+	
+	if (table->loading) return;
+
+	widget = table->loaded_widget;
+	new_name = gtk_editable_get_chars (GTK_EDITABLE (editable), 0, -1);
+
+	if (glade_project_available_widget_name (widget->project, widget, new_name))
+		glade_command_set_name (widget, new_name);
+	g_free (new_name);
+}
+
+
+static void
+append_name_field (GladeEditorTable *table)
+{
+	GtkWidget *label;
+	gchar     *text = _("The Object's name");
+	
+	/* Name */
+	label = gtk_label_new (_("Name:"));
+	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+	gtk_widget_show (label);
+
+	table->name_entry = gtk_entry_new ();
+	gtk_widget_show (table->name_entry);
+
+	gtk_widget_set_tooltip_text (label, text);
+	gtk_widget_set_tooltip_text (table->name_entry, text);
+
+	g_signal_connect (G_OBJECT (table->name_entry), "activate",
+			  G_CALLBACK (widget_name_edited), table);
+	g_signal_connect (G_OBJECT (table->name_entry), "changed",
+			  G_CALLBACK (widget_name_edited), table);
+
+	glade_editor_table_attach (table, label, 0, table->rows);
+	glade_editor_table_attach (table, table->name_entry, 1, table->rows);
+
+	table->rows++;
+}
+
+/**
+ * glade_editor_table_new:
+ * @adaptor: A #GladeWidgetAdaptor
+ * @type: The #GladeEditorPageType
+ *
+ * Creates a new #GladeEditorTable. 
+ *
+ * Returns: a new #GladeEditorTable
+ *
+ */
+GtkWidget *
+glade_editor_table_new (GladeWidgetAdaptor   *adaptor,
+			GladeEditorPageType   type)
+{
+	GladeEditorTable *table;
+
+	g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
+
+	table = g_object_new (GLADE_TYPE_EDITOR_TABLE, NULL);
+	table->adaptor = adaptor;
+	table->type = type;
+	
+	if (type == GLADE_PAGE_GENERAL)
+		append_name_field (table);
+
+	append_items (table, adaptor, type);
+
+	gtk_widget_show (GTK_WIDGET (table));
+
+	return GTK_WIDGET (table);
+}

Added: trunk/gladeui/glade-editor-table.h
==============================================================================
--- (empty file)
+++ trunk/gladeui/glade-editor-table.h	Thu Oct 23 17:30:14 2008
@@ -0,0 +1,86 @@
+/* -*- 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_EDITOR_BUTTON_H_
+#define _GLADE_EDITOR_BUTTON_H_
+
+#include <gtk/gtk.h>
+#include <gladeui/glade-editable.h>
+
+
+G_BEGIN_DECLS
+
+#define GLADE_TYPE_EDITOR_TABLE	            (glade_editor_table_get_type ())
+#define GLADE_EDITOR_TABLE(obj)		    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EDITOR_TABLE, GladeEditorTable))
+#define GLADE_EDITOR_TABLE_CLASS(klass)	    (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EDITOR_TABLE, GladeEditorTableClass))
+#define GLADE_IS_EDITOR_TABLE(obj)	    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EDITOR_TABLE))
+#define GLADE_IS_EDITOR_TABLE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EDITOR_TABLE))
+#define GLADE_EDITOR_TABLE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_EDITOR_TABLE, GladeEditorEditorClass))
+
+typedef struct _GladeEditorTable        GladeEditorTable;
+typedef struct _GladeEditorTableClass   GladeEditorTableClass;
+
+struct _GladeEditorTable
+{
+	GtkTable  parent;
+
+	GladeWidgetAdaptor *adaptor; /* The GladeWidgetAdaptor this
+				      * table was created for.
+				      */
+
+	GladeWidget *loaded_widget; /* A pointer to the currently loaded GladeWidget
+				     */
+	
+	GtkWidget *name_entry; /* A pointer to the gtk_entry that holds
+				* the name of the widget. This is the
+				* first item _pack'ed to the table_widget.
+				* We have a pointer here because it is an
+				* entry which will not be created from a
+				* GladeProperty but rather from code.
+				*/
+
+	GList *properties; /* A list of GladeEditorPropery items.
+			    * For each row in the gtk_table, there is a
+			    * corrsponding GladeEditorProperty struct.
+			    */
+
+	GladeEditorPageType type; /* Is this table to be used in the common tab, ?
+				   * the general tab, a packing tab or the query popup ?
+				   */
+
+	gboolean  loading; /* Avoid recursion while loading values into widgets
+			    */
+
+	gint rows;
+};
+
+struct _GladeEditorTableClass
+{
+	GtkTableClass parent;
+};
+
+GType            glade_editor_table_get_type (void);
+GtkWidget       *glade_editor_table_new      (GladeWidgetAdaptor   *adaptor,
+					      GladeEditorPageType   type);
+
+G_END_DECLS
+
+#endif  /* _GLADE_EDITOR_TABLE_H_ */

Modified: trunk/gladeui/glade-editor.c
==============================================================================
--- trunk/gladeui/glade-editor.c	(original)
+++ trunk/gladeui/glade-editor.c	Thu Oct 23 17:30:14 2008
@@ -85,18 +85,6 @@
 
 }
 
-
-static void
-glade_editor_gtk_doc_search_cb (GladeEditorProperty *eprop,
-				const gchar         *book,
-				const gchar         *page,
-				const gchar         *search,
-				GladeEditor         *editor)
-{
-	/* Just act as a hub for search signals here */
-	glade_editor_search_doc_search (editor, book, page, search);
-}
-
 static void
 glade_editor_set_property (GObject      *object,
 			   guint         prop_id,
@@ -265,7 +253,6 @@
 	}
 }
 
-
 static GtkWidget *
 glade_editor_create_info_button (GladeEditor *editor)
 {
@@ -286,7 +273,6 @@
 	return button;
 }
 
-
 static GtkWidget *
 glade_editor_create_reset_button (GladeEditor *editor)
 {
@@ -306,6 +292,7 @@
 	return button;
 }
 
+
 static void
 glade_editor_update_class_warning_cb (GladeWidget  *widget,
 				      GParamSpec   *pspec,
@@ -319,6 +306,7 @@
 	gtk_widget_set_tooltip_text (editor->warning, widget->support_warning);
 }
 
+
 static void
 glade_editor_update_class_field (GladeEditor *editor)
 {
@@ -349,6 +337,14 @@
 	}
 }
 
+static void
+glade_editor_update_widget_name_cb (GladeWidget  *widget,
+				    GParamSpec   *pspec,
+				    GladeEditor  *editor)
+{
+	glade_editor_update_class_field (editor);
+}
+
 static GtkWidget *
 glade_editor_setup_class_field (GladeEditor *editor)
 {
@@ -390,9 +386,9 @@
 	editor->page_common  = glade_editor_notebook_page (editor, _("_Common"));
 	editor->page_signals = glade_editor_notebook_page (editor, _("_Signals"));
 	editor->page_atk     = glade_editor_notebook_page (editor, _("Accessibility"));
-	editor->widget_tables = NULL;
-	editor->packing_etable = NULL;
-	editor->loading = FALSE;
+	editor->editables    = NULL;
+	editor->packing_page = NULL;
+	editor->loading      = FALSE;
 
 	editor->class_field = glade_editor_setup_class_field (editor);
 
@@ -469,323 +465,106 @@
 	return editor;
 }
 
-/*
- * We call this function when the user changes the widget name using the
- * entry on the properties editor.
- */
-static void
-glade_editor_widget_name_changed (GtkWidget *editable, GladeEditor *editor)
-{
-	GladeWidget *widget;
-	gchar *new_name;
-	
-	g_return_if_fail (GTK_IS_EDITABLE (editable));
-	g_return_if_fail (GLADE_IS_EDITOR (editor));
-	
-	if (editor->loading) return;
-
-	widget = editor->loaded_widget;
-	new_name = gtk_editable_get_chars (GTK_EDITABLE (editable), 0, -1);
-
-	if (glade_project_available_widget_name (widget->project, widget, new_name))
-		glade_command_set_name (widget, new_name);
-	g_free (new_name);
-}
-
-static void
-glade_editor_table_attach (GtkWidget *table, GtkWidget *child, gint pos, gint row)
-{
-	gtk_table_attach (GTK_TABLE (table), child,
-			  pos, pos+1, row, row +1,
-			  GTK_EXPAND | GTK_FILL,
-			  GTK_EXPAND | GTK_FILL,
-			  3, 1);
-}
-
-static GladeEditorProperty *
-glade_editor_table_append_item (GladeEditorTable *table,
-				GladePropertyClass *klass,
-				gboolean from_query_dialog)
-{
-	GladeEditorProperty *property;
-
-	if (!(property = glade_widget_adaptor_create_eprop 
-	      (GLADE_WIDGET_ADAPTOR (klass->handle), 
-	       klass, from_query_dialog == FALSE)))
-	{
-		g_critical ("Unable to create editor for property '%s' of class '%s'",
-			    klass->id, GLADE_WIDGET_ADAPTOR (klass->handle)->name);
-		return NULL;
-	}
-
-	gtk_widget_show (GTK_WIDGET (property));
-	gtk_widget_show_all (property->item_label);
-
-	g_signal_connect (G_OBJECT (property), "gtk-doc-search",
-			  G_CALLBACK (glade_editor_gtk_doc_search_cb), 
-			  table->editor);
-
-	glade_editor_table_attach (table->table_widget, property->item_label, 0, table->rows);
-	glade_editor_table_attach (table->table_widget, GTK_WIDGET (property), 1, table->rows);
-
-	table->rows++;
-
-	return property;
-}
-
-static void
-glade_editor_table_append_name_field (GladeEditorTable *table)
-{
-	GtkWidget *label;
-	gchar     *text = _("The Object's name");
-	
-	/* Name */
-	label = gtk_label_new (_("Name:"));
-	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-	gtk_widget_show (label);
-
-	table->name_entry = gtk_entry_new ();
-	gtk_widget_show (table->name_entry);
-
-	gtk_widget_set_tooltip_text (label, text);
-	gtk_widget_set_tooltip_text (table->name_entry, text);
-
-	g_signal_connect (G_OBJECT (table->name_entry), "activate",
-			  G_CALLBACK (glade_editor_widget_name_changed),
-			  table->editor);
-	
-	g_signal_connect (G_OBJECT (table->name_entry), "changed",
-			  G_CALLBACK (glade_editor_widget_name_changed),
-			  table->editor);
-
-	glade_editor_table_attach (table->table_widget, label, 0, table->rows);
-	glade_editor_table_attach (table->table_widget, table->name_entry, 1, table->rows);
-
-	table->rows++;
-}
-
-static gint
-glade_editor_property_class_comp (gconstpointer a, gconstpointer b)
-{
-	const GladePropertyClass *ca = a, *cb = b;
-	
-	if (ca->pspec->owner_type == cb->pspec->owner_type)
-	{
-		gdouble result = ca->weight - cb->weight;
-		/* Avoid cast to int */
-		if (result < 0.0) return -1;
-		else if (result > 0.0) return 1;
-		else return 0;
-	}
-	else
-	{
-		if (g_type_is_a (ca->pspec->owner_type, cb->pspec->owner_type))
-			return (ca->common || ca->packing) ? 1 : -1;
-		else
-			return (ca->common || ca->packing) ? -1 : 1;
-	}
-}
-
-static GList *
-glade_editor_get_sorted_properties (GladeWidgetAdaptor *adaptor)
-{
-	GList *l, *a = NULL, *b = NULL;
-	
-	for (l = adaptor->properties; l && l->data; l = g_list_next (l))
-	{
-		GladePropertyClass *klass = l->data;
-		
-		if (klass->common || klass->packing)
-			a = g_list_prepend (a, klass);
-		else
-			b = g_list_prepend (b, klass);
-	}
-	
-	a = g_list_sort (a, glade_editor_property_class_comp);
-	b = g_list_sort (b, glade_editor_property_class_comp);
-
-	return g_list_concat (a, b);
-}
-
-static gboolean
-glade_editor_table_append_items (GladeEditorTable     *table,
-				 GladeWidgetAdaptor   *adaptor,
-				 GladeEditorTableType  type)
-{
-	GladeEditorProperty *property;
-	GladePropertyClass  *property_class;
-	GList *list, *sorted_list;
-
-	sorted_list = glade_editor_get_sorted_properties (adaptor);
-	
-	for (list = sorted_list; list != NULL; list = list->next)
-	{
-		property_class = (GladePropertyClass *) list->data;
-
-		if (!glade_property_class_is_visible (property_class) && type != TABLE_TYPE_QUERY)
-			continue;
-		if (type == TABLE_TYPE_QUERY && !property_class->query)
-			continue;
-		else if (type == TABLE_TYPE_COMMON && !property_class->common)
-			continue;
-		else if (type == TABLE_TYPE_GENERAL && property_class->common)
-			continue;
-		else if (type == TABLE_TYPE_ATK && !property_class->atk)
-			 continue;
-		else if (type != TABLE_TYPE_ATK && property_class->atk)
-			 continue;
-
-		property = glade_editor_table_append_item (table, property_class, 
-							   type == TABLE_TYPE_QUERY);
-		table->properties = g_list_prepend (table->properties, property);
-	}
-	
-	g_list_free (sorted_list);
-	
-	return TRUE;
-}
-
-static GladeEditorTable *
-glade_editor_table_new (void)
-{
-	GladeEditorTable *table;
-
-	table = g_new0 (GladeEditorTable, 1);
-
-	table->table_widget = gtk_table_new (0, 0, FALSE);
-
-	g_object_ref (G_OBJECT(table->table_widget));
-
-	return table;
-}
-
-static void
-glade_editor_table_free (GladeEditorTable *etable)
-{
-	g_object_unref (G_OBJECT(etable->table_widget));
-	g_free (etable);
-}
-
-static GladeEditorTable *
-glade_editor_table_create (GladeEditor          *editor,
-			   GladeWidgetAdaptor   *adaptor,
-			   GladeEditorTableType  type)
-{
-	GladeEditorTable *table;
-
-	g_return_val_if_fail (GLADE_IS_EDITOR (editor), NULL);
-	g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
-
-	table = glade_editor_table_new ();
-	table->editor = editor;
-	table->adaptor = adaptor;
-	table->type = type;
-
-	if (type == TABLE_TYPE_GENERAL)
-		glade_editor_table_append_name_field (table);
-
-	if (!glade_editor_table_append_items (table, adaptor, type))
-		return NULL;
-
-	gtk_widget_show (table->table_widget);
-
-	return table;
-}
-
-static GladeEditorTable *
-glade_editor_get_table_from_class (GladeEditor *editor,
-				   GladeWidgetAdaptor *adaptor,
-				   GladeEditorTableType type)
+static GtkWidget *
+glade_editor_get_editable_by_adaptor (GladeEditor *editor,
+				      GladeWidgetAdaptor *adaptor,
+				      GladeEditorPageType type)
 {
-	GladeEditorTable *table;
+	GtkWidget *editable;
 	GList *list;
 
 	g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
+	g_return_val_if_fail (type != GLADE_PAGE_PACKING, NULL);
 
-	for (list = editor->widget_tables; list; list = list->next)
+	for (list = editor->editables; list; list = list->next)
 	{
-		table = list->data;
-		if (type != table->type)
+		editable = list->data;
+		if (type != GPOINTER_TO_INT (g_object_get_data (G_OBJECT (editable), "glade-editor-page-type")))
 			continue;
-		if (table->adaptor == adaptor)
-			return table;
+		if (g_object_get_data (G_OBJECT (editable), "glade-widget-adaptor") == adaptor)
+			return editable;
 	}
 
-	table = glade_editor_table_create (editor, adaptor, type);
-	g_return_val_if_fail (table != NULL, NULL);
+	editable = (GtkWidget *)glade_widget_adaptor_create_editable (adaptor, type);
+	g_return_val_if_fail (editable != NULL, NULL);
+
+	g_object_ref_sink (editable);
+	g_object_set_data (G_OBJECT (editable), "glade-editor-page-type", GINT_TO_POINTER (type));
+	g_object_set_data (G_OBJECT (editable), "glade-widget-adaptor", adaptor);
 
-	editor->widget_tables = g_list_prepend (editor->widget_tables, table);
+	editor->editables = g_list_prepend (editor->editables, editable);
 
-	return table;
+	return editable;
 }
 
 static void
-glade_editor_load_page (GladeEditor          *editor, 
-			GladeWidgetAdaptor   *adaptor,
-			GladeEditorTableType  type)
+glade_editor_load_editable_in_page (GladeEditor          *editor, 
+				    GladeWidgetAdaptor   *adaptor,
+				    GladeEditorPageType   type)
 {
-	GladeEditorTable *table;
-	GtkContainer *container = NULL;
-	GtkWidget *scrolled_window;
-	GList *list, *children;
+	GtkContainer  *container = NULL;
+	GtkWidget     *scrolled_window, *editable;
 	GtkAdjustment *adj;
 
 	/* Remove the old table that was in this container */
 	switch (type)
 	{
-	case TABLE_TYPE_GENERAL:
+	case GLADE_PAGE_GENERAL:
 		container = GTK_CONTAINER (editor->page_widget);
 		break;
-	case TABLE_TYPE_COMMON:
+	case GLADE_PAGE_COMMON:
 		container = GTK_CONTAINER (editor->page_common);
 		break;
-	case TABLE_TYPE_ATK:
+	case GLADE_PAGE_PACKING:
+		container = GTK_CONTAINER (editor->page_packing);
+		break;
+	case GLADE_PAGE_ATK:
 		container = GTK_CONTAINER (editor->page_atk);
 		break;
-	case TABLE_TYPE_PACKING:
-	case TABLE_TYPE_QUERY:
+	case GLADE_PAGE_QUERY:
 	default:
 		g_critical ("Unreachable code reached !");
 		break;
 	}
-
-	children = gtk_container_get_children (container);
-	for (list = children; list; list = list->next) {
-		GtkWidget *widget = list->data;
-		g_return_if_fail (GTK_IS_WIDGET (widget));
-		gtk_widget_ref (widget);
-		gtk_container_remove (container, widget);
-	}
-	g_list_free (children);
+	
+	/* Remove the editable (this will destroy on packing pages) */
+	if (GTK_BIN (container)->child)
+		gtk_container_remove (container, GTK_BIN (container)->child);
 
 	if (!adaptor)
 		return;
+	
+	if (type != GLADE_PAGE_PACKING)
+		editable = glade_editor_get_editable_by_adaptor (editor, adaptor, type);
+	else
+	{
+		/* Dont take a ref for packing pages, they are owned by thier container
+		 * until we update it. 
+		 */
+		editable = (GtkWidget *)glade_widget_adaptor_create_editable (adaptor, type);
+		editor->packing_page = editable;
+	}
 
-	table = glade_editor_get_table_from_class (editor, adaptor, type);
-
-	/* Attach the new table */
-	gtk_container_add (GTK_CONTAINER (container), table->table_widget);
+	/* Attach the new page */
+	gtk_container_add (GTK_CONTAINER (container), editable);
 
 	/* Enable tabbed keynav in the editor */
-	if (table)
-	{
-		scrolled_window = gtk_widget_get_parent (GTK_WIDGET (container));
-		scrolled_window = gtk_widget_get_parent (scrolled_window);
-
-		/* FIXME: Save pointer to the scrolled window (or just the
-		   adjustments) before hand. */
-		g_assert (GTK_IS_SCROLLED_WINDOW (scrolled_window));
-				
-		adj = gtk_scrolled_window_get_vadjustment
-			(GTK_SCROLLED_WINDOW (scrolled_window));
-		gtk_container_set_focus_vadjustment
-			(GTK_CONTAINER (table->table_widget), adj);
-		
-		adj = gtk_scrolled_window_get_hadjustment
-			(GTK_SCROLLED_WINDOW (scrolled_window));
+	scrolled_window = gtk_widget_get_parent (GTK_WIDGET (container));
+	scrolled_window = gtk_widget_get_parent (scrolled_window);
+	
+	/* FIXME: Save pointer to the scrolled window (or just the
+	   adjustments) before hand. */
+	g_assert (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+	
+	adj = gtk_scrolled_window_get_vadjustment
+		(GTK_SCROLLED_WINDOW (scrolled_window));
+	gtk_container_set_focus_vadjustment
+		(GTK_CONTAINER (editable), adj);
+	
+	adj = gtk_scrolled_window_get_hadjustment
+		(GTK_SCROLLED_WINDOW (scrolled_window));
 		gtk_container_set_focus_hadjustment
-			(GTK_CONTAINER (table->table_widget), adj);
-	}
+			(GTK_CONTAINER (editable), adj);
 }
 
 static void
@@ -801,80 +580,17 @@
 static void
 glade_editor_load_widget_class (GladeEditor *editor, GladeWidgetAdaptor *adaptor)
 {
-	glade_editor_load_page (editor, adaptor, TABLE_TYPE_GENERAL);
-	glade_editor_load_page (editor, adaptor, TABLE_TYPE_COMMON);
-	glade_editor_load_page (editor, adaptor, TABLE_TYPE_ATK);
+
+	glade_editor_load_editable_in_page (editor, adaptor, GLADE_PAGE_GENERAL);
+	glade_editor_load_editable_in_page (editor, adaptor, GLADE_PAGE_COMMON);
+	glade_editor_load_editable_in_page (editor, adaptor, GLADE_PAGE_PACKING);
+	glade_editor_load_editable_in_page (editor, adaptor, GLADE_PAGE_ATK);
 
 	glade_editor_load_signal_page  (editor);
 	
 	editor->loaded_adaptor = adaptor;
 }
 
-static gint
-glade_editor_property_comp (gconstpointer a, gconstpointer b)
-{
-	const GladeProperty *prop_a = a, *prop_b = b;
-	return glade_editor_property_class_comp (prop_a->klass, prop_b->klass);
-}
-
-static void
-glade_editor_load_packing_page (GladeEditor *editor, GladeWidget *widget)
-{
-	GladeEditorProperty *editor_property;
-	GladeProperty       *property;
-	GladeWidget         *parent;
-	GList               *list, *sorted_list;
-	GtkWidget           *child;
-
-	/* Remove the old properties */
-	if ((child = gtk_bin_get_child (GTK_BIN (editor->page_packing))) != NULL)
-		gtk_container_remove (GTK_CONTAINER (editor->page_packing), child);
-
-	/* Free the packing editor table */
-	if (editor->packing_etable)
-		editor->packing_etable =
-			(glade_editor_table_free (editor->packing_etable), NULL);
-
-	/* Free the packing editor properties (we gave ownership to 
-	 * packing_etable->table_widget, so no need to unref them here).
-	 */
-	editor->packing_eprops = (g_list_free (editor->packing_eprops), NULL);
-
-
-	/* if the widget is a toplevel there are no packing properties */
-	if (widget == NULL || (parent = glade_widget_get_parent (widget)) == NULL)
-		return;
-
-	/* Now add the new properties */
-	editor->packing_etable         = glade_editor_table_new ();
-	editor->packing_etable->editor = editor;
-	editor->packing_etable->type   = TABLE_TYPE_PACKING;
-
-	/* Sort packing properties by weight */
-	sorted_list = g_list_copy (widget->packing_properties);
-	sorted_list = g_list_sort (sorted_list, glade_editor_property_comp);
-	
-	for (list = sorted_list; list && list->data; list = list->next)
-	{
-		property               = GLADE_PROPERTY (list->data);
-		
-		if (glade_property_class_is_visible (property->klass) == FALSE)
-			continue;
-		
-		editor_property        = glade_editor_table_append_item (editor->packing_etable, 
-									 property->klass, FALSE);
-		editor->packing_eprops = g_list_prepend (editor->packing_eprops, editor_property);
-		glade_editor_property_load (editor_property, property);
-	}
-
-	g_list_free (sorted_list);
-	
-	gtk_widget_show (editor->packing_etable->table_widget);
-
-	gtk_container_add (GTK_CONTAINER (editor->page_packing), 
-			   editor->packing_etable->table_widget);
-}
-
 static void
 glade_editor_close_cb (GladeProject *project,
 		       GladeEditor  *editor)
@@ -886,45 +602,25 @@
 }
 
 static void
-glade_editor_load_table (GladeEditor         *editor, 
-			 GladeWidget         *widget,
-			 GladeEditorTableType type)
-{
-	GladeEditorProperty *property;
-	GladeEditorTable    *table;
-	GList               *list;
-
-	table = glade_editor_get_table_from_class
-		(editor, widget->adaptor, type);
-	if (table->name_entry)
-		gtk_entry_set_text (GTK_ENTRY (table->name_entry), widget->name);
-
-	for (list = table->properties; list; list = list->next)
-	{
-		property = list->data;
-		glade_editor_property_load_by_widget (property, widget);
-	}
-}
-
-static void
-glade_editor_update_widget_name_cb (GladeWidget  *widget,
-				    GParamSpec   *pspec,
-				    GladeEditor  *editor)
+glade_editor_load_editable (GladeEditor         *editor, 
+			    GladeWidget         *widget,
+			    GladeEditorPageType  type)
 {
-	GladeEditorTable *table;
+	GtkWidget *editable;
 
-	glade_editor_update_class_field (editor);
+	if (type == GLADE_PAGE_PACKING)
+		editable = editor->packing_page;
+	else
+		editable = glade_editor_get_editable_by_adaptor
+			(editor, widget->adaptor, type);
+	
+	g_assert (editable);
 
-	g_assert (editor->loaded_widget);
+	if (!widget) gtk_widget_hide (editable);
 
-	table = glade_editor_get_table_from_class
-		(editor, editor->loaded_adaptor, TABLE_TYPE_GENERAL);
+	glade_editable_load (GLADE_EDITABLE (editable), widget);
 
-	g_signal_handlers_block_by_func (G_OBJECT (table->name_entry), 
-					 glade_editor_widget_name_changed, editor);
-	gtk_entry_set_text (GTK_ENTRY (table->name_entry), editor->loaded_widget->name);
-	g_signal_handlers_unblock_by_func (G_OBJECT (table->name_entry), 
-					   glade_editor_widget_name_changed, editor);
+	if (widget) gtk_widget_show (editable);
 }
 
 static void
@@ -951,7 +647,6 @@
 	if (editor->loaded_adaptor != adaptor || adaptor == NULL)
 		glade_editor_load_widget_class (editor, adaptor);
 
-	glade_editor_load_packing_page (editor, widget);
 	glade_signal_editor_load_widget (editor->signal_editor, widget);
 
 	/* we are just clearing, we are done */
@@ -972,9 +667,10 @@
 	editor->loading = TRUE;
 
 	/* Load each GladeEditorProperty from 'widget' */
-	glade_editor_load_table (editor, widget, TABLE_TYPE_GENERAL);
-	glade_editor_load_table (editor, widget, TABLE_TYPE_COMMON);
-	glade_editor_load_table (editor, widget, TABLE_TYPE_ATK);
+	glade_editor_load_editable (editor, widget, GLADE_PAGE_GENERAL);
+	glade_editor_load_editable (editor, widget, GLADE_PAGE_COMMON);
+	glade_editor_load_editable (editor, widget, GLADE_PAGE_ATK);
+	glade_editor_load_editable (editor, widget, GLADE_PAGE_PACKING);
 
 	editor->loaded_widget = widget;
 	editor->loading = FALSE;
@@ -1046,11 +742,8 @@
 gboolean
 glade_editor_query_dialog (GladeEditor *editor, GladeWidget *widget)
 {
-	GtkWidget           *dialog;
-	GladeEditorTable    *table;
+	GtkWidget           *dialog, *editable;
 	gchar               *title;
-	GList               *list;
-	GladeEditorProperty *property;
 	gint		     answer;
 	gboolean	     retval = TRUE;
 
@@ -1071,19 +764,14 @@
 						 -1);
 	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
-	table = glade_editor_get_table_from_class (editor,
-						   widget->adaptor,
-						   TABLE_TYPE_QUERY);
-
+	editable = glade_editor_get_editable_by_adaptor (editor,
+							 widget->adaptor,
+							 GLADE_PAGE_QUERY);
 
 	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
-			    table->table_widget,
-			    FALSE, FALSE, 6);
-	for (list = table->properties; list; list = list->next)
-	{
-		property = list->data;
-		glade_editor_property_load_by_widget (property, widget);
-	}
+			    editable, FALSE, FALSE, 6);
+
+	glade_editable_load (GLADE_EDITABLE (editable), widget);
 
 	g_signal_connect (dialog, "style-set", 
 			  G_CALLBACK (query_dialog_style_set_cb),
@@ -1099,8 +787,7 @@
 	if (answer == GTK_RESPONSE_CANCEL)
 		retval = FALSE;
 
-	gtk_container_remove (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
-			      table->table_widget);
+	gtk_container_remove (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), editable);
 	
 	gtk_widget_destroy (dialog);
 	return retval;

Modified: trunk/gladeui/glade-editor.h
==============================================================================
--- trunk/gladeui/glade-editor.h	(original)
+++ trunk/gladeui/glade-editor.h	Thu Oct 23 17:30:14 2008
@@ -3,6 +3,7 @@
 #define __GLADE_EDITOR_H__
 
 #include <gladeui/glade-signal-editor.h>
+#include <gladeui/glade-editable.h>
 
 G_BEGIN_DECLS
 
@@ -14,21 +15,8 @@
 #define GLADE_IS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EDITOR))
 #define GLADE_EDITOR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_EDITOR, GladeEditorClass))
 
-#define GLADE_EDITOR_TABLE(t)       ((GladeEditorTable *)t)
-#define GLADE_IS_EDITOR_TABLE(t)    (t != NULL)
-
 typedef struct _GladeEditor          GladeEditor;
 typedef struct _GladeEditorClass     GladeEditorClass;
-typedef struct _GladeEditorTable     GladeEditorTable;
-
-typedef enum _GladeEditorTableType
-{
-	TABLE_TYPE_GENERAL,
-	TABLE_TYPE_COMMON,
-	TABLE_TYPE_PACKING,
-	TABLE_TYPE_ATK,
-	TABLE_TYPE_QUERY
-} GladeEditorTableType;
 
 /* The GladeEditor is a window that is used to display and modify widget
  * properties. The glade editor contains the details of the selected
@@ -78,20 +66,15 @@
 	GladeSignalEditor *signal_editor; /* The signal editor packed into vbox_signals
 					   */
 
-	GList *widget_tables; /* A list of GladeEditorTable. We have a table
-				* (gtktable) for each GladeWidgetClass, if
-				* we don't have one yet, we create it when
-				* we are asked to load a widget of a particular
-				* GladeWidgetClass
-				*/
-				
-	GladeEditorTable *packing_etable; /* Packing pages are dynamicly created each
-					   * selection, this pointer is only to free
-					   * the last packing page.
-					   */
-	 
-	GList            *packing_eprops; /* Current list of packing GladeEditorProperties
-					   */
+	GList *editables;     /* A list of GladeEditables. We have a widget
+			       * for each GladeWidgetAdaptor and we only load
+			       * them on demand
+			       */
+	
+	GtkWidget *packing_page; /* Packing pages are dynamicly created each
+				  * selection, this pointer is only to free
+				  * the last packing page.
+				  */
 
 	gboolean loading; /* Use when loading a GladeWidget into the editor
 			   * we set this flag so that we can ignore the
@@ -100,15 +83,12 @@
 			   * was loaded.
 			   */
 
-
 	gulong project_closed_signal_id; /* Unload widget when widget's project closes.
 					  */
 	gulong widget_warning_id; /* Update when widget changes warning messages.
 				   */
-	
-	gulong widget_name_id; /* Watch the actual widget name
-				*/
-
+	gulong widget_name_id;    /* Update class field when widget name changes
+				   */
 	GtkWidget *reset_button; /* The reset button
 				  */
 	
@@ -154,52 +134,6 @@
 
 };
 
-/* For each glade widget class that we have modified, we create a
- * GladeEditorTable. A GladeEditorTable is mainly a gtk_table with all the
- * widgets to edit a particular GladeWidgetClass (well the first tab of the
- * gtk notebook). When a widget of is selected
- * and going to be edited, we create a GladeEditorTable, when another widget
- * of the same class is loaded so that it can be edited, we just update the
- * contents of the editor table to relfect the values of that GladeWidget
- */
-struct _GladeEditorTable
-{
-	GladeEditor *editor; /* Handy pointer that avoids havving to pass the
-			      * editor arround.
-			      */
-	
-	GladeWidgetAdaptor *adaptor; /* The GladeWidgetAdaptor this
-				      * table belongs to.
-				      */
-
-	GtkWidget *table_widget; /* This widget is a gtk_vbox that is displayed
-				  * in the glade-editor when a widget of this
-				  * class is selected. It is hiden when another
-				  * type is selected. When we select a widget
-				  * we load into the inputs inside this table
-				  * the information about the selected widget.
-				  */
-	
-	GtkWidget *name_entry; /* A pointer to the gtk_entry that holds
-				* the name of the widget. This is the
-				* first item _pack'ed to the table_widget.
-				* We have a pointer here because it is an
-				* entry which will not be created from a
-				* GladeProperty but rather from code.
-				*/
-
-	GList *properties; /* A list of GladeEditorPropery items.
-			    * For each row in the gtk_table, there is a
-			    * corrsponding GladeEditorProperty struct.
-			    */
-
-	GladeEditorTableType type; /* Is this table to be used in the common tab, ?
-				    * the general tab, a packing tab or the query popup ?
-				    */
-
-	gint  rows;
-};
-
 
 GType        glade_editor_get_type           (void);
 

Modified: trunk/gladeui/glade-property-class.h
==============================================================================
--- trunk/gladeui/glade-property-class.h	(original)
+++ trunk/gladeui/glade-property-class.h	Thu Oct 23 17:30:14 2008
@@ -17,6 +17,23 @@
 #define GLADE_PROPERTY_CLASS(gpc)     ((GladePropertyClass *) gpc)
 #define GLADE_IS_PROPERTY_CLASS(gpc)  (gpc != NULL)
 
+
+/**
+ * GLADE_PROPERTY_CLASS_IS_TYPE:
+ * gpc: A #GladePropertyClass
+ * type: The #GladeEditorPageType to query
+ *
+ * Checks if @gpc is good to be loaded as @type
+ */
+#define GLADE_PROPERTY_CLASS_IS_TYPE(gpc, type)	                \
+	(((type) == GLADE_PAGE_GENERAL &&                       \
+	  !(gpc)->common && !(gpc)->packing && !(gpc)->atk) ||	\
+	 ((type) == GLADE_PAGE_COMMON  && (gpc)->common)    ||  \
+	 ((type) == GLADE_PAGE_PACKING && (gpc)->packing)   ||  \
+	 ((type) == GLADE_PAGE_ATK     && (gpc)->atk)       ||  \
+	 ((type) == GLADE_PAGE_QUERY   && (gpc)->query))
+
+
 #define GPC_OBJECT_DELIMITER ", "
 #define GPC_PROPERTY_NAMELEN 512  /* Enough space for a property name I think */
 
@@ -75,10 +92,6 @@
 			    * to be of possible use in plugin code.
 			    */
 
-	gboolean query; /* Whether we should explicitly ask the user about this property
-			 * when instantiating a widget with this property (through a popup
-			 * dialog).
-			 */
 
 	gboolean optional; /* Some properties are optional by nature like
 			    * default width. It can be set or not set. A
@@ -93,6 +106,10 @@
 	gboolean common;  /* Common properties go in the common tab */
 	gboolean atk;     /* Atk properties go in the atk tab */
 	gboolean packing; /* Packing properties go in the packing tab */
+	gboolean query;   /* Whether we should explicitly ask the user about this property
+			   * when instantiating a widget with this property (through a popup
+			   * dialog).
+			   */
 
 	
 	gboolean translatable; /* The property should be translatable, which

Modified: trunk/gladeui/glade-widget-adaptor.c
==============================================================================
--- trunk/gladeui/glade-widget-adaptor.c	(original)
+++ trunk/gladeui/glade-widget-adaptor.c	Thu Oct 23 17:30:14 2008
@@ -41,6 +41,7 @@
 #include "glade-marshallers.h"
 #include "glade-accumulators.h"
 #include "glade-displayable-values.h"
+#include "glade-editor-table.h"
 
 /* For g_file_exists */
 #include <sys/types.h>
@@ -1172,6 +1173,14 @@
 	return glade_property_class_make_string_from_gvalue (klass, value, fmt);
 }
 
+static GladeEditable *
+glade_widget_adaptor_object_create_editable (GladeWidgetAdaptor   *adaptor,
+					     GladeEditorPageType   type)
+{
+	return (GladeEditable *)glade_editor_table_new (adaptor, type);
+}
+
+
 /*******************************************************************************
             GladeWidgetAdaptor type registration and class initializer
  *******************************************************************************/
@@ -1219,8 +1228,7 @@
 	adaptor_class->write_child          = glade_widget_adaptor_object_write_child;
 	adaptor_class->create_eprop         = glade_widget_adaptor_object_create_eprop;
 	adaptor_class->string_from_value    = glade_widget_adaptor_object_string_from_value;
-
-
+	adaptor_class->create_editable      = glade_widget_adaptor_object_create_editable;
 
 	/* Base defaults here */
 	adaptor_class->fixed                = FALSE;
@@ -1502,6 +1510,11 @@
 					  &symbol))
 		klass->string_from_value = symbol;
 
+	if (glade_xml_load_sym_from_node (node, module,
+					  GLADE_TAG_CREATE_EDITABLE_FUNCTION,
+					  &symbol))
+		klass->create_editable = symbol;
+
 }
 
 static void
@@ -3557,7 +3570,7 @@
 
 
 /**
- * glade_widget_adaptor_string_from_value:
+ * glade_widget_adaptor_get_signal_class:
  * @adaptor: A #GladeWidgetAdaptor
  * @name: the name of the signal class.
  * 
@@ -3585,3 +3598,24 @@
 	return NULL;
 }
 
+
+/**
+ * glade_widget_adaptor_create_editable:
+ * @adaptor: A #GladeWidgetAdaptor
+ * @type: The #GladeEditorPageType
+ * 
+ * This is used to allow the backend to override the way an
+ * editor page is layed out (note that editor widgets are created
+ * on demand and not at startup).
+ *
+ * Returns: A new #GladeEditable widget
+ */
+GladeEditable *
+glade_widget_adaptor_create_editable (GladeWidgetAdaptor   *adaptor,
+				      GladeEditorPageType   type)
+{
+	g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
+
+	return GLADE_WIDGET_ADAPTOR_GET_CLASS
+		(adaptor)->create_editable (adaptor, type);
+}

Modified: trunk/gladeui/glade-widget-adaptor.h
==============================================================================
--- trunk/gladeui/glade-widget-adaptor.h	(original)
+++ trunk/gladeui/glade-widget-adaptor.h	Thu Oct 23 17:30:14 2008
@@ -6,6 +6,7 @@
 #include <gladeui/glade-property-class.h>
 #include <gladeui/glade-editor-property.h>
 #include <gladeui/glade-catalog.h>
+#include <gladeui/glade-editable.h>
 #include <glib-object.h>
 #include <gmodule.h>
 #include <gtk/gtk.h>
@@ -469,8 +470,9 @@
  * @fmt: The #GladeProjectFormat the string should conform to
  * 
  * For normal properties this is used to serialize
- * property values, for custom properties its still
- * needed to update the UI for undo/redo items etc.
+ * property values, for custom properties (only when new pspecs are 
+ * introduced) its needed for value comparisons in boxed pspecs 
+ * and also to update the UI for undo/redo items etc.
  *
  * Returns: A newly allocated string representation of @value
  */
@@ -480,6 +482,22 @@
 					       GladeProjectFormat  fmt);
 
 
+
+/**
+ * GladeCreateEditableFunc:
+ * @adaptor: A #GladeWidgetAdaptor
+ * @type: The #GladeEditorPageType
+ * 
+ * This is used to allow the backend to override the way an
+ * editor page is layed out (note that editor widgets are created
+ * on demand and not at startup).
+ *
+ * Returns: A new #GladeEditable widget
+ */
+typedef GladeEditable *(* GladeCreateEditableFunc) (GladeWidgetAdaptor   *adaptor,
+						    GladeEditorPageType   type);
+
+
 /* GladeSignalClass contains all the info we need for a given signal, such as
  * the signal name, and maybe more in the future 
  */
@@ -663,6 +681,8 @@
 	GladeCreateEPropFunc         create_eprop; /* Creates a GladeEditorProperty */
 
 	GladeStringFromValueFunc     string_from_value; /* Creates a string for a value */
+
+	GladeCreateEditableFunc      create_editable; /* Creates a page for the editor */
 };
 
 #define glade_widget_adaptor_create_widget(adaptor, query, ...) \
@@ -849,6 +869,9 @@
 							      const GValue       *value,
 							      GladeProjectFormat  fmt);
 
+GladeEditable       *glade_widget_adaptor_create_editable    (GladeWidgetAdaptor *adaptor,
+							      GladeEditorPageType type);
+
 GladeSignalClass    *glade_widget_adaptor_get_signal_class   (GladeWidgetAdaptor *adaptor,
 							      const gchar        *name);
 

Modified: trunk/gladeui/glade-xml-utils.h
==============================================================================
--- trunk/gladeui/glade-xml-utils.h	(original)
+++ trunk/gladeui/glade-xml-utils.h	Thu Oct 23 17:30:14 2008
@@ -138,6 +138,7 @@
 #define GLADE_TAG_WRITE_CHILD_FUNCTION            "write-child-function"
 #define GLADE_TAG_CREATE_EPROP_FUNCTION           "create-editor-property-function"
 #define GLADE_TAG_STRING_FROM_VALUE_FUNCTION      "string-from-value-function"
+#define GLADE_TAG_CREATE_EDITABLE_FUNCTION        "create-editable-function"
 #define GLADE_TAG_PROPERTIES                      "properties"
 #define GLADE_TAG_PACKING_PROPERTIES              "packing-properties"
 #define GLADE_TAG_PROPERTY                        "property"

Modified: trunk/gladeui/glade.h
==============================================================================
--- trunk/gladeui/glade.h	(original)
+++ trunk/gladeui/glade.h	Thu Oct 23 17:30:14 2008
@@ -44,5 +44,7 @@
 #include <gladeui/glade-builtins.h>
 #include <gladeui/glade-fixed.h>
 #include <gladeui/glade-name-context.h>
+#include <gladeui/glade-editable.h>
+#include <gladeui/glade-displayable-values.h>
 
 #endif /* __GLADE_H__ */



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