Commit 101b8add authored by Tristan Van Berkom's avatar Tristan Van Berkom
Browse files

string_from_enum, now returns the nick and not the name (generally all


	* 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.


svn path=/trunk/; revision=1993
parent 23d26f57
......@@ -6,6 +6,18 @@
* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: Completely reworked GtkButton,
much cleaner and less code now.
* 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.
2008-10-23 Tristan Van Berkom <tvb@gnome.org>
* gladeui/Makefile.am, gladeui/glade-editable.[ch], gladeui/glade-editor-table.[ch]:
......
......@@ -41,12 +41,20 @@ typedef struct {
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 @@ glade_register_displayable_value (GType type,
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 @@ glade_get_displayable_value (GType 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, 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 @@ glade_get_displayable_value (GType type,
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;
}
......@@ -18,6 +18,9 @@ G_CONST_RETURN
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
......
......@@ -880,8 +880,8 @@ glade_eprop_enum_create_input (GladeEditorProperty *eprop)
{
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 @@ glade_eprop_flags_load (GladeEditorProperty *eprop, GladeProperty *property)
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;
......
......@@ -214,7 +214,7 @@ glade_property_class_make_string_from_enum (GType etype, gint eval)
{
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 @@ gpc_read_displayable_values_from_node (GladeXmlNode *node,
{
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);
}
......
......@@ -1940,10 +1940,13 @@ glade_util_icon_name_to_filename (const gchar *value)
gint
glade_utils_enum_value_from_string (GType enum_type, const gchar *strval)
{
gint value = 0;
GValue *gvalue;
gint value = 0;
const gchar *displayable;
GValue *gvalue;
if ((gvalue = glade_utils_value_from_string (enum_type, strval, NULL, NULL)) != NULL)
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 @@ glade_utils_enum_value_from_string (GType enum_type, const gchar *strval)
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 @@ glade_utils_enum_string_from_value (GType enum_type, gint value)
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;
gint value = 0;
const gchar *displayable;
GValue *gvalue;
if ((gvalue = glade_utils_value_from_string (flags_type, strval, NULL, NULL)) != NULL)
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 @@ glade_utils_flags_value_from_string (GType flags_type, const gchar *strval)
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 @@ glade_utils_flags_string_from_value (GType flags_type, gint value)
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 @@ glade_utils_liststore_from_enum_type (GType enum_type,
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);
}
......
......@@ -137,6 +137,9 @@ gint glade_utils_enum_value_from_string (GType enum_type, const gc
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,
......
......@@ -9436,7 +9436,7 @@ serialize_icon_sources (gchar *icon_name,
{
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 @@ serialize_icon_sources (gchar *icon_name,
{
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 @@ serialize_icon_sources (gchar *icon_name,
{
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);
}
......
......@@ -256,7 +256,7 @@ populate_store_foreach (const gchar *icon_name,
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 @@ populate_store_foreach (const gchar *icon_name,
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 @@ populate_store_foreach (const gchar *icon_name,
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,
......
......@@ -946,7 +946,7 @@ glade_eprop_model_data_create_input (GladeEditorProperty *eprop)
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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment