static void value_text_edited (GtkCellRendererText * cell, const gchar * path, const gchar * new_text, GladeEditorProperty * eprop) { GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop); GtkTreeIter iter; gint colnum = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column-number")); gint row; GNode *data_tree = NULL; GladeModelData *data; GValue *value; GladeProperty *property = glade_editor_property_get_property (eprop); if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (eprop_data->store), &iter, path)) return; gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter, COLUMN_ROW, &row, -1); glade_property_get (property, &data_tree); /* if we are editing, then there is data in the datatree */ g_assert (data_tree); data_tree = glade_model_data_tree_copy (data_tree); data = glade_model_data_tree_get_data (data_tree, row, colnum); /* Untranslate string and update value in tree. */ if (G_VALUE_HOLDS_ENUM (&data->value) || G_VALUE_HOLDS_FLAGS (&data->value)) value = glade_utils_value_from_string (G_VALUE_TYPE (&data->value), glade_get_value_from_displayable (G_VALUE_TYPE (&data->value), new_text), glade_widget_get_project (glade_property_get_widget (property))); else value = glade_utils_value_from_string (G_VALUE_TYPE (&data->value), new_text, glade_widget_get_project (glade_property_get_widget (property))); g_value_copy (value, &data->value); g_value_unset (value); g_free (value); eprop_data->editing_row = row; eprop_data->editing_column = colnum; if (eprop_data->pending_data_tree) glade_model_data_tree_free (eprop_data->pending_data_tree); eprop_data->pending_data_tree = data_tree; g_idle_add ((GSourceFunc) update_and_focus_data_tree_idle, eprop); }
static void glade_gtk_icon_factory_read_sources (GladeWidget *widget, GladeXmlNode *node) { GladeIconSources *sources; GtkIconSource *source; GladeXmlNode *sources_node, *source_node; GValue *value; GList *list; gchar *current_icon_name = NULL; GdkPixbuf *pixbuf; if ((sources_node = glade_xml_search_child (node, GLADE_TAG_SOURCES)) == NULL) return; sources = glade_icon_sources_new (); /* Here we expect all icon sets to remain together in the list. */ for (source_node = glade_xml_node_get_children (sources_node); source_node; source_node = glade_xml_node_next (source_node)) { gchar *icon_name; gchar *str; if (!glade_xml_node_verify (source_node, GLADE_TAG_SOURCE)) continue; if (!(icon_name = glade_xml_get_property_string_required (source_node, GLADE_TAG_STOCK_ID, NULL))) continue; if (! (str = glade_xml_get_property_string_required (source_node, GLADE_TAG_FILENAME, NULL))) { g_free (icon_name); continue; } if (!current_icon_name || strcmp (current_icon_name, icon_name) != 0) current_icon_name = (g_free (current_icon_name), g_strdup (icon_name)); G_GNUC_BEGIN_IGNORE_DEPRECATIONS source = gtk_icon_source_new (); G_GNUC_END_IGNORE_DEPRECATIONS /* Deal with the filename... */ value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, str, glade_widget_get_project (widget)); pixbuf = g_value_dup_object (value); g_value_unset (value); g_free (value); G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_icon_source_set_pixbuf (source, pixbuf); G_GNUC_END_IGNORE_DEPRECATIONS g_object_unref (G_OBJECT (pixbuf)); g_free (str); /* Now the attributes... */ if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_DIRECTION)) != NULL) { GtkTextDirection direction = glade_utils_enum_value_from_string (GTK_TYPE_TEXT_DIRECTION, str); G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_icon_source_set_direction_wildcarded (source, FALSE); gtk_icon_source_set_direction (source, direction); G_GNUC_END_IGNORE_DEPRECATIONS g_free (str); } if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_SIZE)) != NULL) { GtkIconSize size = glade_utils_enum_value_from_string (GTK_TYPE_ICON_SIZE, str); G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_icon_source_set_size_wildcarded (source, FALSE); gtk_icon_source_set_size (source, size); G_GNUC_END_IGNORE_DEPRECATIONS g_free (str); } if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_STATE)) != NULL) { GtkStateType state = glade_utils_enum_value_from_string (GTK_TYPE_STATE_TYPE, str); G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_icon_source_set_state_wildcarded (source, FALSE); gtk_icon_source_set_state (source, state); G_GNUC_END_IGNORE_DEPRECATIONS g_free (str); } if ((list = g_hash_table_lookup (sources->sources, g_strdup (current_icon_name))) != NULL) { GList *new_list = g_list_append (list, source); /* Warning: if we use g_list_prepend() the returned pointer will be different * so we would have to replace the list pointer in the hash table. * But before doing that we have to steal the old list pointer otherwise * we would have to make a copy then add the new icon to finally replace the hash table * value. * Anyways if we choose to prepend we would have to reverse the list outside this loop * so its better to append. */ if (new_list != list) { /* current g_list_append() returns the same pointer so this is not needed */ g_hash_table_steal (sources->sources, current_icon_name); g_hash_table_insert (sources->sources, g_strdup (current_icon_name), new_list); } } else { list = g_list_append (NULL, source); g_hash_table_insert (sources->sources, g_strdup (current_icon_name), list); } } if (g_hash_table_size (sources->sources) > 0) glade_widget_property_set (widget, "sources", sources); glade_icon_sources_free (sources); }
static void value_filename_edited (GtkCellRendererText * cell, const gchar * path, const gchar * new_text, GladeEditorProperty * eprop) { GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop); GladeProperty *property = glade_editor_property_get_property (eprop); GtkTreeIter iter; GladeIconSources *icon_sources = NULL; GtkIconSource *source; gchar *icon_name; gint index = -1; GValue *value; GdkPixbuf *pixbuf; GList *source_list; if (!new_text || !new_text[0]) { g_idle_add ((GSourceFunc) reload_icon_sources_idle, eprop); return; } if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (eprop_sources->store), &iter, path)) return; gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter, COLUMN_ICON_NAME, &icon_name, COLUMN_LIST_INDEX, &index, -1); /* get new pixbuf value... */ value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, new_text, glade_widget_get_project (glade_property_get_widget (property))); pixbuf = g_value_get_object (value); glade_property_get (property, &icon_sources); if (icon_sources) { icon_sources = glade_icon_sources_copy (icon_sources); if (index >= 0 && (source = get_icon_source (icon_sources, icon_name, index)) != NULL) gtk_icon_source_set_pixbuf (source, pixbuf); else { source = gtk_icon_source_new (); gtk_icon_source_set_pixbuf (source, pixbuf); if ((source_list = g_hash_table_lookup (icon_sources->sources, icon_name)) != NULL) { source_list = g_list_append (source_list, source); } else { source_list = g_list_prepend (NULL, source); g_hash_table_insert (icon_sources->sources, g_strdup (icon_name), source_list); } } } else { icon_sources = glade_icon_sources_new (); source = gtk_icon_source_new (); gtk_icon_source_set_pixbuf (source, pixbuf); source_list = g_list_prepend (NULL, source); g_hash_table_insert (icon_sources->sources, g_strdup (icon_name), source_list); } g_value_unset (value); g_free (value); update_icon_sources (eprop, icon_sources); }