Commit 7c0ea19f authored by Tristan Van Berkom's avatar Tristan Van Berkom

Now support editing enum types


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


svn path=/trunk/; revision=1979
parent 7f8c517a
2008-10-17 Tristan Van Berkom <tvb@gnome.org>
2008-10-18 Tristan Van Berkom <tvb@gnome.org>
* 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.
2008-10-18 Tristan Van Berkom <tvb@gnome.org>
* gladeui/glade-command.c: Fixed property commands to not unify across separate groups,
and also to unify when they are not lists.
......
......@@ -1967,6 +1967,36 @@ glade_utils_enum_string_from_value (GType enum_type, gint value)
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 @@ glade_utils_liststore_from_enum_type (GType enum_type,
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++)
{
......
......@@ -133,9 +133,10 @@ gchar *glade_util_filename_to_icon_name (const gchar *value);
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,
......
......@@ -1572,6 +1572,30 @@ gwa_derive_adaptor_for_type (GType object_type, GWADerivedClassData *data)
/*******************************************************************************
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:
......
......@@ -679,6 +679,7 @@ GType glade_widget_adaptor_get_type (void) G_GNUC_CONST;
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,
......
......@@ -39,19 +39,70 @@ enum
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 @@ column_types_store_populate (GtkListStore *store)
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 @@ glade_param_column_types_get_type (void)
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 @@ glade_eprop_column_types_create_input (GladeEditorProperty *eprop)
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);
......
......@@ -646,9 +646,15 @@ value_text_edited (GtkCellRendererText *cell,
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);
......
Markdown is supported
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