Revision: 1129 http://svn.sourceforge.net/geany/?rev=1129&view=rev Author: ntrel Date: 2006-12-20 02:47:01 -0800 (Wed, 20 Dec 2006)
Log Message: ----------- Fix tag treeview not being freed (because of g_object_ref). Separate recreate_tag_list() from ui_update_tag_list().
Modified Paths: -------------- trunk/ChangeLog trunk/src/treeviews.c trunk/src/ui_utils.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-12-20 10:42:12 UTC (rev 1128) +++ trunk/ChangeLog 2006-12-20 10:47:01 UTC (rev 1129) @@ -2,6 +2,9 @@
* src/keyfile.c: Fix strv leak in configuration_open_files(). + * src/treeviews.c, src/ui_utils.c: + Fix tag treeview not being freed (because of g_object_ref). + Separate recreate_tag_list() from ui_update_tag_list().
2006-12-18 Enrico Tröger enrico.troeger@uvena.de
Modified: trunk/src/treeviews.c =================================================================== --- trunk/src/treeviews.c 2006-12-20 10:42:12 UTC (rev 1128) +++ trunk/src/treeviews.c 2006-12-20 10:47:01 UTC (rev 1129) @@ -372,6 +372,12 @@ if (GTK_IS_WIDGET(doc_list[idx].tag_tree)) { gtk_widget_destroy(doc_list[idx].tag_tree); + if (GTK_IS_TREE_VIEW(doc_list[idx].tag_tree)) + { + // Because it was ref'd in ui_update_tag_list, it needs unref'ing + g_object_unref((gpointer)doc_list[idx].tag_tree); + } + doc_list[idx].tag_tree = NULL; } }
Modified: trunk/src/ui_utils.c =================================================================== --- trunk/src/ui_utils.c 2006-12-20 10:42:12 UTC (rev 1128) +++ trunk/src/ui_utils.c 2006-12-20 10:47:01 UTC (rev 1129) @@ -198,12 +198,104 @@ }
-// update = rescan the tags for document[idx].filename -void ui_update_tag_list(gint idx, gboolean update) +static gboolean recreate_tag_list(gint idx) { GList *tmp; const GList *tags; + GtkTreeIter iter; + GtkTreeModel *model;
+ tags = symbols_get_tag_list(idx, tm_tag_max_t); + if (doc_list[idx].tm_file == NULL || tags == NULL) return FALSE; + + doc_list[idx].has_tags = TRUE; + gtk_tree_store_clear(doc_list[idx].tag_store); + // unref the store to speed up the filling(from TreeView Tutorial) + model = gtk_tree_view_get_model(GTK_TREE_VIEW(doc_list[idx].tag_tree)); + g_object_ref(model); // Make sure the model stays with us after the tree view unrefs it + gtk_tree_view_set_model(GTK_TREE_VIEW(doc_list[idx].tag_tree), NULL); // Detach model from view + + treeviews_init_tag_list(idx); + for (tmp = (GList*)tags; tmp; tmp = g_list_next(tmp)) + { + switch (((GeanySymbol*)tmp->data)->type) + { + case tm_tag_prototype_t: + case tm_tag_method_t: + case tm_tag_function_t: + { + if (tv.tag_function.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_function)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + case tm_tag_macro_t: + case tm_tag_macro_with_arg_t: + { + if (tv.tag_macro.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_macro)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + case tm_tag_class_t: + { + if (tv.tag_class.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_class)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + case tm_tag_member_t: + case tm_tag_field_t: + { + if (tv.tag_member.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_member)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + case tm_tag_typedef_t: + case tm_tag_enum_t: + case tm_tag_union_t: + case tm_tag_struct_t: + case tm_tag_interface_t: + { + if (tv.tag_struct.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_struct)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + case tm_tag_variable_t: + { + if (tv.tag_variable.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_variable)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + case tm_tag_namespace_t: + case tm_tag_package_t: + { + if (tv.tag_namespace.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_namespace)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + default: + { + if (tv.tag_other.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_other)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + } + } + } + gtk_tree_view_set_model(GTK_TREE_VIEW(doc_list[idx].tag_tree), model); // Re-attach model to view + g_object_unref(model); + gtk_tree_view_expand_all(GTK_TREE_VIEW(doc_list[idx].tag_tree)); + return TRUE; +} + + +// update = rescan the tags for document[idx].filename +void ui_update_tag_list(gint idx, gboolean update) +{ if (gtk_bin_get_child(GTK_BIN(app->tagbar))) gtk_container_remove(GTK_CONTAINER(app->tagbar), gtk_bin_get_child(GTK_BIN(app->tagbar)));
@@ -238,101 +330,13 @@ g_object_ref((gpointer)doc_list[idx].tag_tree); // to hold it after removing }
- tags = symbols_get_tag_list(idx, tm_tag_max_t); - if (doc_list[idx].tm_file != NULL && tags != NULL) + if (recreate_tag_list(idx)) { - GtkTreeIter iter; - GtkTreeModel *model; - - doc_list[idx].has_tags = TRUE; - gtk_tree_store_clear(doc_list[idx].tag_store); - // unref the store to speed up the filling(from TreeView Tutorial) - model = gtk_tree_view_get_model(GTK_TREE_VIEW(doc_list[idx].tag_tree)); - g_object_ref(model); // Make sure the model stays with us after the tree view unrefs it - gtk_tree_view_set_model(GTK_TREE_VIEW(doc_list[idx].tag_tree), NULL); // Detach model from view - - treeviews_init_tag_list(idx); - for (tmp = (GList*)tags; tmp; tmp = g_list_next(tmp)) - { - switch (((GeanySymbol*)tmp->data)->type) - { - case tm_tag_prototype_t: - case tm_tag_method_t: - case tm_tag_function_t: - { - if (tv.tag_function.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_function)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - case tm_tag_macro_t: - case tm_tag_macro_with_arg_t: - { - if (tv.tag_macro.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_macro)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - case tm_tag_class_t: - { - if (tv.tag_class.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_class)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - case tm_tag_member_t: - case tm_tag_field_t: - { - if (tv.tag_member.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_member)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - case tm_tag_typedef_t: - case tm_tag_enum_t: - case tm_tag_union_t: - case tm_tag_struct_t: - case tm_tag_interface_t: - { - if (tv.tag_struct.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_struct)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - case tm_tag_variable_t: - { - if (tv.tag_variable.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_variable)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - case tm_tag_namespace_t: - case tm_tag_package_t: - { - if (tv.tag_namespace.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_namespace)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - default: - { - if (tv.tag_other.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_other)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - } - } - } - gtk_tree_view_set_model(GTK_TREE_VIEW(doc_list[idx].tag_tree), model); // Re-attach model to view - g_object_unref(model); - gtk_tree_view_expand_all(GTK_TREE_VIEW(doc_list[idx].tag_tree)); - gtk_widget_set_sensitive(app->tagbar, TRUE); gtk_container_add(GTK_CONTAINER(app->tagbar), doc_list[idx].tag_tree); - /// TODO why I have to do this here? - g_object_ref((gpointer)doc_list[idx].tag_tree); } else - { // tags == NULL + { // no tags gtk_widget_set_sensitive(app->tagbar, FALSE); gtk_container_add(GTK_CONTAINER(app->tagbar), app->default_tag_tree); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.