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



Author: tvb
Date: Fri Oct 24 15:42:05 2008
New Revision: 1993
URL: http://svn.gnome.org/viewvc/glade3?rev=1993&view=rev

Log:

	* gladeui/glade-property-class.c: string_from_enum, now returns the nick and not the
	name (generally all around nicer menus when no displayable values and also smaller
	nicer glade files). Displayable values are now consequently indexed by nick and not name.

	* gladeui/glade-displayable-values.[ch]: Added reverse lookup glade_get_value_from_displayable()

	* gladeui/glade-utils.[ch]: When doing glade_utils_enum/flag_value_from_string(), allow
	displayable values (also added glade_utils_enum/flag_string_from_value_displayable()).

	* plugins/gtk+/glade-icon-sources.c: Use all around displayable values for items
	in the treeview.



Modified:
   trunk/ChangeLog
   trunk/gladeui/glade-displayable-values.c
   trunk/gladeui/glade-displayable-values.h
   trunk/gladeui/glade-editor-property.c
   trunk/gladeui/glade-property-class.c
   trunk/gladeui/glade-utils.c
   trunk/gladeui/glade-utils.h
   trunk/plugins/gtk+/glade-gtk.c
   trunk/plugins/gtk+/glade-icon-sources.c
   trunk/plugins/gtk+/glade-model-data.c

Modified: trunk/gladeui/glade-displayable-values.c
==============================================================================
--- trunk/gladeui/glade-displayable-values.c	(original)
+++ trunk/gladeui/glade-displayable-values.c	Fri Oct 24 15:42:05 2008
@@ -41,12 +41,20 @@
 
 static GHashTable *values_hash = NULL;
 
+
 static gint
-find_value (ValueTab *a, const gchar *b)
+find_by_value (ValueTab *a, const gchar *b)
 {
 	return strcmp (a->value, b);
 }
 
+
+static gint
+find_by_displayable (ValueTab *a, const gchar *b)
+{
+	return strcmp (a->string, b);
+}
+
 void
 glade_register_displayable_value (GType          type, 
 				  const gchar   *value, 
@@ -70,12 +78,12 @@
 	if ((values = 
 	     g_hash_table_lookup (values_hash, klass)) != NULL)
 	{
-		if (!g_list_find_custom (values, tab->value, (GCompareFunc)find_value))
+		if (!g_list_find_custom (values, tab->value, (GCompareFunc)find_by_value))
 			values = g_list_append (values, tab);
 		else
 		{
-			g_warning ("Already registered a displayable value for %s (type %s)", 
-				   tab->value, g_type_name (type));
+			g_warning ("Already registered displayable value %s for %s (type %s)", 
+				   tab->string, tab->value, g_type_name (type));
 			g_free (tab->string);
 			g_free (tab->value);
 			g_free (tab);
@@ -119,7 +127,7 @@
 	g_return_val_if_fail  (klass != NULL, NULL);
 
 	if ((values   = g_hash_table_lookup (values_hash, klass)) != NULL &&
-	    (tab_iter = g_list_find_custom  (values, value, (GCompareFunc)find_value)) != NULL)
+	    (tab_iter = g_list_find_custom  (values, value, (GCompareFunc)find_by_value)) != NULL)
 	{
 		tab = tab_iter->data;
 		displayable = tab->string;
@@ -128,3 +136,31 @@
 
 	return displayable;
 }
+
+
+G_CONST_RETURN gchar *
+glade_get_value_from_displayable (GType          type, 
+				  const gchar   *displayable)
+{
+	ValueTab  *tab;
+	gpointer   klass;
+	GList     *values, *tab_iter;
+	gchar     *value = NULL;
+
+	if (!values_hash)
+		return NULL;
+
+	klass = g_type_class_ref (type);
+
+	g_return_val_if_fail  (klass != NULL, NULL);
+
+	if ((values   = g_hash_table_lookup (values_hash, klass)) != NULL &&
+	    (tab_iter = g_list_find_custom  (values, displayable, (GCompareFunc)find_by_displayable)) != NULL)
+	{
+		tab = tab_iter->data;
+		value = tab->value;
+	}
+	g_type_class_unref (klass);
+
+	return value;
+}

Modified: trunk/gladeui/glade-displayable-values.h
==============================================================================
--- trunk/gladeui/glade-displayable-values.h	(original)
+++ trunk/gladeui/glade-displayable-values.h	Fri Oct 24 15:42:05 2008
@@ -18,6 +18,9 @@
 gchar      *glade_get_displayable_value           (GType          type, 
 						   const gchar   *value);
 
+G_CONST_RETURN 
+gchar *glade_get_value_from_displayable           (GType          type, 
+						   const gchar   *displayabe);
 
 G_END_DECLS
 

Modified: trunk/gladeui/glade-editor-property.c
==============================================================================
--- trunk/gladeui/glade-editor-property.c	(original)
+++ trunk/gladeui/glade-editor-property.c	Fri Oct 24 15:42:05 2008
@@ -880,8 +880,8 @@
 	{
 		const gchar *value_name = 
 			glade_get_displayable_value (klass->pspec->value_type,
-						     eclass->values[i].value_name);
-		if (value_name == NULL) value_name = eclass->values[i].value_name;
+						     eclass->values[i].value_nick);
+		if (value_name == NULL) value_name = eclass->values[i].value_nick;
 		
 		if (stock && strcmp (eclass->values[i].value_nick, "glade-none"))
 			menu_item = glade_editor_create_input_stock_item
@@ -964,7 +964,7 @@
 			setting = ((value & mask) == mask) ? TRUE : FALSE;
 			
 			value_name = glade_get_displayable_value
-				(eprop->klass->pspec->value_type, klass->values[flag_num].value_name);
+				(eprop->klass->pspec->value_type, klass->values[flag_num].value_nick);
 
 			if (value_name == NULL) value_name = klass->values[flag_num].value_name;
 			

Modified: trunk/gladeui/glade-property-class.c
==============================================================================
--- trunk/gladeui/glade-property-class.c	(original)
+++ trunk/gladeui/glade-property-class.c	Fri Oct 24 15:42:05 2008
@@ -214,7 +214,7 @@
 	{
 		if (eval == eclass->values[i].value)
 		{
-			string = g_strdup (eclass->values[i].value_name);
+			string = g_strdup (eclass->values[i].value_nick);
 			break;
 		}
 	}
@@ -1154,14 +1154,14 @@
 				{
 					enum_val = &enum_values[i];
 					glade_register_displayable_value (klass->pspec->value_type,
-									  enum_val->value_name, 
+									  enum_val->value_nick, 
 									  domain, name);
 				}
 				else
 				{
 					flags_val = &flags_values[i];
 					glade_register_displayable_value (klass->pspec->value_type,
-									  flags_val->value_name, 
+									  flags_val->value_nick, 
 									  domain, name);
 
 				}

Modified: trunk/gladeui/glade-utils.c
==============================================================================
--- trunk/gladeui/glade-utils.c	(original)
+++ trunk/gladeui/glade-utils.c	Fri Oct 24 15:42:05 2008
@@ -1940,10 +1940,13 @@
 gint
 glade_utils_enum_value_from_string (GType enum_type, const gchar *strval)
 {
-	gint    value = 0;
-	GValue *gvalue;
-
-	if ((gvalue = glade_utils_value_from_string (enum_type, strval, NULL, NULL)) != NULL)
+	gint          value = 0;
+	const gchar  *displayable;
+	GValue       *gvalue;
+
+	if (((displayable = glade_get_value_from_displayable (enum_type, strval)) != NULL &&
+	     (gvalue = glade_utils_value_from_string (enum_type, displayable, NULL, NULL)) != NULL) ||
+	    (gvalue = glade_utils_value_from_string (enum_type, strval, NULL, NULL)) != NULL)
 	{
 		value = g_value_get_enum (gvalue);
 		g_value_unset (gvalue);
@@ -1952,8 +1955,8 @@
 	return value;
 }
 
-gchar *
-glade_utils_enum_string_from_value (GType enum_type, gint value)
+static gchar *
+glade_utils_enum_string_from_value_real (GType enum_type, gint value, gboolean displayable)
 {
 	GValue gvalue = { 0, };
 	gchar *string;
@@ -1964,16 +1967,42 @@
 	string = glade_utils_string_from_value (&gvalue, GLADE_PROJECT_FORMAT_GTKBUILDER);
 	g_value_unset (&gvalue);
 
+	if (displayable && string)
+	{
+		const gchar *dstring = glade_get_displayable_value (enum_type, string);
+		if (dstring)
+		{
+			g_free (string);
+			return g_strdup (dstring);
+		}
+	}
+
 	return string;
 }
 
+gchar *
+glade_utils_enum_string_from_value (GType enum_type, gint value)
+{
+	return glade_utils_enum_string_from_value_real (enum_type, value, FALSE);
+}
+
+gchar *
+glade_utils_enum_string_from_value_displayable (GType enum_type, gint value)
+{
+	return glade_utils_enum_string_from_value_real (enum_type, value, TRUE);
+}
+
+
 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)
+	gint          value = 0;
+	const gchar  *displayable;
+	GValue       *gvalue;
+
+	if (((displayable = glade_get_value_from_displayable (flags_type, strval)) != NULL &&
+	     (gvalue = glade_utils_value_from_string (flags_type, displayable, NULL, NULL)) != NULL) ||
+	    (gvalue = glade_utils_value_from_string (flags_type, strval, NULL, NULL)) != NULL)
 	{
 		value = g_value_get_flags (gvalue);
 		g_value_unset (gvalue);
@@ -1982,8 +2011,8 @@
 	return value;
 }
 
-gchar *
-glade_utils_flags_string_from_value (GType flags_type, gint value)
+static gchar *
+glade_utils_flags_string_from_value_real (GType flags_type, gint value, gboolean displayable)
 {
 	GValue gvalue = { 0, };
 	gchar *string;
@@ -1994,9 +2023,33 @@
 	string = glade_utils_string_from_value (&gvalue, GLADE_PROJECT_FORMAT_GTKBUILDER);
 	g_value_unset (&gvalue);
 
+	if (displayable && string)
+	{
+		const gchar *dstring = glade_get_displayable_value (flags_type, string);
+		if (dstring)
+		{
+			g_free (string);
+			return g_strdup (dstring);
+		}
+	}
+
 	return string;
 }
 
+gchar *
+glade_utils_flags_string_from_value (GType flags_type, gint value)
+{
+	return glade_utils_flags_string_from_value_real (flags_type, value, FALSE);
+
+}
+
+
+gchar *
+glade_utils_flags_string_from_value_displayable (GType flags_type, gint value)
+{
+	return glade_utils_flags_string_from_value_real (flags_type, value, TRUE);
+}
+
 
 /* A hash table of generically created property classes for
  * fundamental types, so we can easily use glade's conversion
@@ -2181,9 +2234,11 @@
 	
 	for (i = 0; i < eclass->n_values; i++)
 	{
+		const gchar *displayable = glade_get_displayable_value (enum_type, eclass->values[i].value_nick);
+
 		gtk_list_store_append (store, &iter);
-		gtk_list_store_set (store, &iter,
-				    0, eclass->values[i].value_nick, 
+		gtk_list_store_set (store, &iter, 
+				    0, displayable ? displayable : eclass->values[i].value_nick,
 				    -1);
 	}
 

Modified: trunk/gladeui/glade-utils.h
==============================================================================
--- trunk/gladeui/glade-utils.h	(original)
+++ trunk/gladeui/glade-utils.h	Fri Oct 24 15:42:05 2008
@@ -137,6 +137,9 @@
 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);
+gchar            *glade_utils_flags_string_from_value_displayable (GType flags_type, gint value);
+gchar            *glade_utils_enum_string_from_value_displayable (GType flags_type, gint value);
+
 
 GValue           *glade_utils_value_from_string   (GType               type,
 						   const gchar        *string,

Modified: trunk/plugins/gtk+/glade-gtk.c
==============================================================================
--- trunk/plugins/gtk+/glade-gtk.c	(original)
+++ trunk/plugins/gtk+/glade-gtk.c	Fri Oct 24 15:42:05 2008
@@ -9436,7 +9436,7 @@
 		{
 			GtkTextDirection direction = gtk_icon_source_get_direction (source);
 			str = glade_utils_enum_string_from_value (GTK_TYPE_TEXT_DIRECTION, direction);
-			g_string_append_printf (string, "%s ", str);
+			g_string_append_printf (string, "dir-%s ", str);
 			g_free (str);
 		}
 
@@ -9444,7 +9444,7 @@
 		{
 			GtkIconSize size = gtk_icon_source_get_size (source);
 			str = glade_utils_enum_string_from_value (GTK_TYPE_ICON_SIZE, size);
-			g_string_append_printf (string, "%s ", str);
+			g_string_append_printf (string, "size-%s ", str);
 			g_free (str);
 		}
 
@@ -9452,7 +9452,7 @@
 		{
 			GtkStateType state = gtk_icon_source_get_size (source);
 			str = glade_utils_enum_string_from_value (GTK_TYPE_STATE_TYPE, state);
-			g_string_append_printf (string, "%s ", str);
+			g_string_append_printf (string, "state-%s ", str);
 			g_free (str);
 		}
 		

Modified: trunk/plugins/gtk+/glade-icon-sources.c
==============================================================================
--- trunk/plugins/gtk+/glade-icon-sources.c	(original)
+++ trunk/plugins/gtk+/glade-icon-sources.c	Fri Oct 24 15:42:05 2008
@@ -256,7 +256,7 @@
 		if (!gtk_icon_source_get_direction_wildcarded (source))
 		{
 			GtkTextDirection direction = gtk_icon_source_get_direction (source);
-			str = glade_utils_enum_string_from_value (GTK_TYPE_TEXT_DIRECTION, direction);
+			str = glade_utils_enum_string_from_value_displayable (GTK_TYPE_TEXT_DIRECTION, direction);
 			gtk_tree_store_set (eprop_sources->store, &iter, 
 					    COLUMN_DIRECTION_ACTIVE, TRUE,
 					    COLUMN_DIRECTION, str,
@@ -267,7 +267,7 @@
 		if (!gtk_icon_source_get_size_wildcarded (source))
 		{
 			GtkIconSize size = gtk_icon_source_get_size (source);
-			str = glade_utils_enum_string_from_value (GTK_TYPE_ICON_SIZE, size);
+			str = glade_utils_enum_string_from_value_displayable (GTK_TYPE_ICON_SIZE, size);
 			gtk_tree_store_set (eprop_sources->store, &iter, 
 					    COLUMN_SIZE_ACTIVE, TRUE,
 					    COLUMN_SIZE, str,
@@ -278,7 +278,7 @@
 		if (!gtk_icon_source_get_state_wildcarded (source))
 		{
 			GtkStateType state = gtk_icon_source_get_size (source);
-			str = glade_utils_enum_string_from_value (GTK_TYPE_STATE_TYPE, state);
+			str = glade_utils_enum_string_from_value_displayable (GTK_TYPE_STATE_TYPE, state);
 			gtk_tree_store_set (eprop_sources->store, &iter, 
 					    COLUMN_STATE_ACTIVE, TRUE,
 					    COLUMN_STATE, str,

Modified: trunk/plugins/gtk+/glade-model-data.c
==============================================================================
--- trunk/plugins/gtk+/glade-model-data.c	(original)
+++ trunk/plugins/gtk+/glade-model-data.c	Fri Oct 24 15:42:05 2008
@@ -946,7 +946,7 @@
 	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (eprop_data->view), TRUE);
 	gtk_container_add (GTK_CONTAINER (swin), GTK_WIDGET (eprop_data->view));
 
-	g_object_set (G_OBJECT (vbox), "height-request", 200, NULL);
+	g_object_set (G_OBJECT (vbox), "height-request", 190, NULL);
 	
 	gtk_widget_show_all (vbox);
 	return vbox;



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