glade3 r1979 - in trunk: . gladeui plugins/gtk+



Author: tvb
Date: Sat Oct 18 09:52:19 2008
New Revision: 1979
URL: http://svn.gnome.org/viewvc/glade3?rev=1979&view=rev

Log:

	* plugins/gtk+/glade-model-data.c: Now support editing enum types

	* plugins/gtk+/glade-column-types.c: Generate a list of enum and flag column types to select from.



Modified:
   trunk/ChangeLog
   trunk/gladeui/glade-utils.c
   trunk/gladeui/glade-utils.h
   trunk/gladeui/glade-widget-adaptor.c
   trunk/gladeui/glade-widget-adaptor.h
   trunk/plugins/gtk+/glade-column-types.c
   trunk/plugins/gtk+/glade-model-data.c

Modified: trunk/gladeui/glade-utils.c
==============================================================================
--- trunk/gladeui/glade-utils.c	(original)
+++ trunk/gladeui/glade-utils.c	Sat Oct 18 09:52:19 2008
@@ -1967,6 +1967,36 @@
 	return string;
 }
 
+gint
+glade_utils_flags_value_from_string (GType flags_type, const gchar *strval)
+{
+	gint    value = 0;
+	GValue *gvalue;
+
+	if ((gvalue = glade_utils_value_from_string (flags_type, strval, NULL, NULL)) != NULL)
+	{
+		value = g_value_get_flags (gvalue);
+		g_value_unset (gvalue);
+		g_free (gvalue);
+	}
+	return value;
+}
+
+gchar *
+glade_utils_flags_string_from_value (GType flags_type, gint value)
+{
+	GValue gvalue = { 0, };
+	gchar *string;
+
+	g_value_init (&gvalue, flags_type);
+	g_value_set_flags (&gvalue, value);
+
+	string = glade_utils_string_from_value (&gvalue, GLADE_PROJECT_FORMAT_GTKBUILDER);
+	g_value_unset (&gvalue);
+
+	return string;
+}
+
 
 /* A hash table of generically created property classes for
  * fundamental types, so we can easily use glade's conversion
@@ -2148,11 +2178,6 @@
 	eclass = g_type_class_ref (enum_type);
 
 	store = gtk_list_store_new (1, G_TYPE_STRING);
-
-	gtk_list_store_append (store, &iter);
-	gtk_list_store_set (store, &iter,
-			    0, _("Unset"), 
-			    -1);
 	
 	for (i = 0; i < eclass->n_values; i++)
 	{

Modified: trunk/gladeui/glade-utils.h
==============================================================================
--- trunk/gladeui/glade-utils.h	(original)
+++ trunk/gladeui/glade-utils.h	Sat Oct 18 09:52:19 2008
@@ -133,9 +133,10 @@
 
 gchar            *glade_util_icon_name_to_filename (const gchar *value);
 
-gint              glade_utils_enum_value_from_string (GType enum_type, const gchar *strval);
-
-gchar            *glade_utils_enum_string_from_value (GType enum_type, gint value);
+gint              glade_utils_enum_value_from_string  (GType enum_type, const gchar *strval);
+gchar            *glade_utils_enum_string_from_value  (GType enum_type, gint value);
+gint              glade_utils_flags_value_from_string (GType enum_type, const gchar *strval);
+gchar            *glade_utils_flags_string_from_value (GType enum_type, gint value);
 
 GValue           *glade_utils_value_from_string   (GType               type,
 						   const gchar        *string,

Modified: trunk/gladeui/glade-widget-adaptor.c
==============================================================================
--- trunk/gladeui/glade-widget-adaptor.c	(original)
+++ trunk/gladeui/glade-widget-adaptor.c	Sat Oct 18 09:52:19 2008
@@ -1572,6 +1572,30 @@
 /*******************************************************************************
                                      API
  *******************************************************************************/
+static void
+accum_adaptor (GType              *type,
+	       GladeWidgetAdaptor *adaptor,
+	       GList             **list)
+{
+	*list = g_list_prepend (*list, adaptor);
+}
+
+/**
+ * glade_widget_adaptor_list_adaptors:
+ *
+ * Compiles a list of all registered adaptors.
+ *
+ * Returns: A newly allocated #GList which must be freed with g_list_free()
+ */
+GList *
+glade_widget_adaptor_list_adaptors (void)
+{
+	GList *adaptors = NULL;
+
+	g_hash_table_foreach (adaptor_hash, (GHFunc)accum_adaptor, &adaptors);
+	
+	return adaptors;
+}
 
 /**
  * glade_widget_adaptor_register:

Modified: trunk/gladeui/glade-widget-adaptor.h
==============================================================================
--- trunk/gladeui/glade-widget-adaptor.h	(original)
+++ trunk/gladeui/glade-widget-adaptor.h	Sat Oct 18 09:52:19 2008
@@ -679,6 +679,7 @@
 
 GType                glade_create_reason_get_type          (void) G_GNUC_CONST;
 
+GList               *glade_widget_adaptor_list_adaptors    (void);
 
 GladeWidgetAdaptor  *glade_widget_adaptor_from_catalog     (GladeCatalog         *catalog,
 							    GladeXmlNode         *class_node,

Modified: trunk/plugins/gtk+/glade-column-types.c
==============================================================================
--- trunk/plugins/gtk+/glade-column-types.c	(original)
+++ trunk/plugins/gtk+/glade-column-types.c	Sat Oct 18 09:52:19 2008
@@ -39,19 +39,70 @@
 	N_COLUMNS
 };
 
-static GtkTreeModel *types_model;
+static GtkTreeModel *types_model = NULL;
 
-static GtkListStore *
-column_types_store_new ()
+static gint 
+find_by_type (GType *a, GType *b)
 {
-	return gtk_list_store_new (N_COLUMNS,
-				   G_TYPE_STRING,
-				   G_TYPE_GTYPE,
-				   G_TYPE_STRING);
+	return *a - *b;
 }
 
 static void
-column_types_store_populate (GtkListStore *store)
+column_types_store_populate_enums_flags (GtkTreeStore *store,
+					 gboolean      enums)
+{
+	GtkTreeIter iter, parent_iter;
+	GList *types = NULL, *list, *l;
+	GList *adaptors = glade_widget_adaptor_list_adaptors ();
+
+	gtk_tree_store_append (store, &parent_iter, NULL);
+	gtk_tree_store_set (store, &parent_iter,
+			    COLUMN_NAME, enums ? _("Enumerations") : _("Flags"),
+			    -1);
+
+	for (list = adaptors; list; list = list->next)
+	{
+		GladeWidgetAdaptor *adaptor = list->data;
+		GladePropertyClass *pclass;
+
+		for (l = adaptor->properties; l; l = l->next)
+		{
+			pclass = l->data;
+
+			/* special case out a few of these... */
+			if (strcmp (g_type_name (pclass->pspec->value_type), "GladeGtkGnomeUIInfo") == 0 ||
+			    strcmp (g_type_name (pclass->pspec->value_type), "GladeStock") == 0 ||
+			    strcmp (g_type_name (pclass->pspec->value_type), "GladeStockImage") == 0 ||
+			    strcmp (g_type_name (pclass->pspec->value_type), "GladeGtkImageType") == 0 ||
+			    strcmp (g_type_name (pclass->pspec->value_type), "GladeGtkButtonType") == 0)
+				continue;
+
+			if ((enums ? G_TYPE_IS_ENUM (pclass->pspec->value_type) : 
+			     G_TYPE_IS_FLAGS (pclass->pspec->value_type)) &&
+			    !g_list_find_custom (types, &(pclass->pspec->value_type), 
+						 (GCompareFunc)find_by_type))
+			{
+				types = g_list_prepend (types, 
+							g_memdup (&(pclass->pspec->value_type), 
+								  sizeof (GType)));
+
+				gtk_tree_store_append (store, &iter, &parent_iter);
+				gtk_tree_store_set (store, &iter,
+						    COLUMN_NAME, g_type_name (pclass->pspec->value_type),
+						    COLUMN_GTYPE, pclass->pspec->value_type,
+						    -1);
+			}
+		}
+	}
+	g_list_free (adaptors);
+	g_list_foreach (types, (GFunc)g_free, NULL);
+	g_list_free (types);
+}
+
+/* TODO: Add submenus with a generated list of all known flag and enum types
+ */
+static void
+column_types_store_populate (GtkTreeStore *store)
 {
 	GtkTreeIter iter;
 	gint i;
@@ -69,14 +120,16 @@
 		G_TYPE_DOUBLE,
 		G_TYPE_STRING,
 		G_TYPE_POINTER,
-		G_TYPE_PARAM,
 		G_TYPE_OBJECT,
 		GDK_TYPE_PIXBUF};
+
+	column_types_store_populate_enums_flags (store, TRUE);
+	column_types_store_populate_enums_flags (store, FALSE);
 	
 	for (i = 0; i < sizeof (types) / sizeof (GType); i++)
 	{
-		gtk_list_store_append (store, &iter);
-		gtk_list_store_set (store, &iter,
+		gtk_tree_store_append (store, &iter, NULL);
+		gtk_tree_store_set (store, &iter,
 				    COLUMN_NAME, g_type_name (types[i]),
 				    COLUMN_GTYPE, types[i],
 				    -1);
@@ -196,8 +249,12 @@
 
 		accel_type = g_param_type_register_static
 			("GladeParamSpecColumnTypes", &pspec_info);
-		types_model = GTK_TREE_MODEL (column_types_store_new ());
-		column_types_store_populate (GTK_LIST_STORE (types_model));
+		types_model = (GtkTreeModel *)gtk_tree_store_new (N_COLUMNS,
+								  G_TYPE_STRING,
+								  G_TYPE_GTYPE,
+								  G_TYPE_STRING);
+
+		column_types_store_populate (GTK_TREE_STORE (types_model));
 	}
 	return accel_type;
 }
@@ -646,7 +703,11 @@
 	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
 	gtk_box_pack_start (GTK_BOX (vbox), swin, TRUE, TRUE, 0);
 	
-	eprop_types->store = column_types_store_new ();
+	eprop_types->store = gtk_list_store_new (N_COLUMNS,
+						 G_TYPE_STRING,
+						 G_TYPE_GTYPE,
+						 G_TYPE_STRING);
+
 	g_signal_connect (eprop_types->store, "row-deleted",
 			  G_CALLBACK (eprop_treeview_row_deleted),
 			  eprop);

Modified: trunk/plugins/gtk+/glade-model-data.c
==============================================================================
--- trunk/plugins/gtk+/glade-model-data.c	(original)
+++ trunk/plugins/gtk+/glade-model-data.c	Sat Oct 18 09:52:19 2008
@@ -646,9 +646,15 @@
 		g_value_set_uint64 (&data->value, g_ascii_strtoull (new_text, NULL, 10));
 	else if (G_VALUE_TYPE (&data->value) == G_TYPE_FLOAT)
 		g_value_set_float (&data->value, (float) g_ascii_strtod (new_text, NULL));
-	else /* if (G_VALUE_TYPE (&data->value) == G_TYPE_DOUBLE) */
+	else if (G_VALUE_TYPE (&data->value) == G_TYPE_DOUBLE)
 		g_value_set_double (&data->value, g_ascii_strtod (new_text, NULL));
-
+	else if (G_TYPE_IS_ENUM (G_VALUE_TYPE (&data->value)))
+		g_value_set_enum (&data->value, 
+				  glade_utils_enum_value_from_string (G_VALUE_TYPE (&data->value), new_text));
+	else if (G_TYPE_IS_FLAGS (G_VALUE_TYPE (&data->value)))
+		g_value_set_enum (&data->value, 
+				  glade_utils_flags_value_from_string (G_VALUE_TYPE (&data->value), new_text));
+	
 	if (eprop_data->pending_data_tree)
 		glade_model_data_tree_free (eprop_data->pending_data_tree);
 



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