diff --git a/ChangeLog b/ChangeLog index 2564338d..5a2e6348 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ * src/treeviews.c: Prevent right click in Symbol list from selecting a tag. + * src/ui_utils.h, src/treeviews.c, src/callbacks.c, src/treeviews.h, + src/document.c, src/main.c, src/ui_utils.c: + Move ui_update_tag_list() to treeviews.c. + Make treeviews_prepare_taglist() static. 2007-02-03 Nick Treleaven diff --git a/src/callbacks.c b/src/callbacks.c index ebbea330..57880bb5 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -244,7 +244,7 @@ on_save_all1_activate (GtkMenuItem *menuitem, else document_save_file(idx, FALSE); } - ui_update_tag_list(cur_idx, TRUE); + treeviews_update_tag_list(cur_idx, TRUE); ui_set_window_title(cur_idx); } @@ -728,7 +728,7 @@ on_notebook1_switch_page (GtkNotebook *notebook, build_menu_update(idx); ui_update_statusbar(idx, -1); ui_set_window_title(idx); - ui_update_tag_list(idx, FALSE); + treeviews_update_tag_list(idx, FALSE); } } diff --git a/src/document.c b/src/document.c index 1b3aafc2..8204df86 100644 --- a/src/document.c +++ b/src/document.c @@ -365,7 +365,7 @@ gboolean document_remove(guint page_num) document_undo_clear(idx); if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) == 0) { - ui_update_tag_list(-1, FALSE); + treeviews_update_tag_list(-1, FALSE); //on_notebook1_switch_page(GTK_NOTEBOOK(app->notebook), NULL, 0, NULL); ui_set_window_title(-1); ui_save_buttons_toggle(FALSE); @@ -1345,7 +1345,7 @@ void document_update_tag_list(gint idx, gboolean update) ! doc_list[idx].file_type->has_tags || ! doc_list[idx].file_name) { // set the default (empty) tag list - ui_update_tag_list(idx, FALSE); + treeviews_update_tag_list(idx, FALSE); return; } @@ -1359,13 +1359,13 @@ void document_update_tag_list(gint idx, gboolean update) tm_workspace_add_object(doc_list[idx].tm_file); if (update) tm_source_file_update(doc_list[idx].tm_file, TRUE, FALSE, TRUE); - ui_update_tag_list(idx, TRUE); + treeviews_update_tag_list(idx, TRUE); } else { if (tm_source_file_update(doc_list[idx].tm_file, TRUE, FALSE, TRUE)) { - ui_update_tag_list(idx, TRUE); + treeviews_update_tag_list(idx, TRUE); } else { diff --git a/src/main.c b/src/main.c index c369c47b..d6b44717 100644 --- a/src/main.c +++ b/src/main.c @@ -648,7 +648,7 @@ gint main(gint argc, gchar **argv) gtk_widget_grab_focus(GTK_WIDGET(doc_list[idx].sci)); gtk_tree_model_foreach(GTK_TREE_MODEL(tv.store_openfiles), treeviews_find_node, GINT_TO_POINTER(idx)); build_menu_update(idx); - ui_update_tag_list(idx, FALSE); + treeviews_update_tag_list(idx, FALSE); #ifdef G_OS_WIN32 // hide "Build" menu item, at least until it is available for Windows diff --git a/src/treeviews.c b/src/treeviews.c index b2e999d6..78fe2a5a 100644 --- a/src/treeviews.c +++ b/src/treeviews.c @@ -30,6 +30,7 @@ #include "document.h" #include "utils.h" #include "ui_utils.h" +#include "symbols.h" enum @@ -60,8 +61,8 @@ static gboolean on_treeviews_button_press_event(GtkWidget *widget, GdkEventButto -/* the following two functions are document-related, but I think they fit better here than in document.c */ -void treeviews_prepare_taglist(GtkWidget *tree, GtkTreeStore *store) +/* the prepare_* functions are document-related, but I think they fit better here than in document.c */ +static void prepare_taglist(GtkWidget *tree, GtkTreeStore *store) { GtkCellRenderer *renderer; GtkTreeViewColumn *column; @@ -91,6 +92,60 @@ void treeviews_prepare_taglist(GtkWidget *tree, GtkTreeStore *store) } +// update = rescan the tags for document[idx].filename +void treeviews_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))); + + if (app->default_tag_tree == NULL) + { + GtkTreeIter iter; + GtkTreeStore *store = gtk_tree_store_new(1, G_TYPE_STRING); + + app->default_tag_tree = gtk_tree_view_new(); + prepare_taglist(app->default_tag_tree, store); + gtk_tree_store_append(store, &iter, NULL); + gtk_tree_store_set(store, &iter, 0, _("No tags found"), -1); + gtk_widget_show(app->default_tag_tree); + g_object_ref((gpointer)app->default_tag_tree); // to hold it after removing + } + + // make all inactive, because there is no more tab left, or something strange occured + if (idx == -1 || doc_list[idx].file_type == NULL || ! doc_list[idx].file_type->has_tags) + { + gtk_widget_set_sensitive(app->tagbar, FALSE); + gtk_container_add(GTK_CONTAINER(app->tagbar), app->default_tag_tree); + return; + } + + if (update) + { // updating the tag list in the left tag window + if (doc_list[idx].tag_tree == NULL) + { + doc_list[idx].tag_store = gtk_tree_store_new(1, G_TYPE_STRING); + doc_list[idx].tag_tree = gtk_tree_view_new(); + prepare_taglist(doc_list[idx].tag_tree, doc_list[idx].tag_store); + gtk_widget_show(doc_list[idx].tag_tree); + g_object_ref((gpointer)doc_list[idx].tag_tree); // to hold it after removing + } + + doc_list[idx].has_tags = symbols_recreate_tag_list(idx); + } + + if (doc_list[idx].has_tags) + { + gtk_widget_set_sensitive(app->tagbar, TRUE); + gtk_container_add(GTK_CONTAINER(app->tagbar), doc_list[idx].tag_tree); + } + else + { + gtk_widget_set_sensitive(app->tagbar, FALSE); + gtk_container_add(GTK_CONTAINER(app->tagbar), app->default_tag_tree); + } +} + + /* does some preparing things to the open files list widget */ void treeviews_prepare_openfiles() { @@ -188,7 +243,7 @@ void treeviews_remove_document(gint idx) 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 + // Because it was ref'd in treeviews_update_tag_list, it needs unref'ing g_object_unref((gpointer)doc_list[idx].tag_tree); } doc_list[idx].tag_tree = NULL; diff --git a/src/treeviews.h b/src/treeviews.h index 00513f62..5994213c 100644 --- a/src/treeviews.h +++ b/src/treeviews.h @@ -36,7 +36,7 @@ struct SidebarTreeviews } tv; -void treeviews_prepare_taglist(GtkWidget *tree, GtkTreeStore *store); +void treeviews_update_tag_list(gint idx, gboolean update); void treeviews_prepare_openfiles(); diff --git a/src/ui_utils.c b/src/ui_utils.c index abbc1e1e..ead05df3 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -36,7 +36,6 @@ #include "encodings.h" #include "images.c" #include "treeviews.h" -#include "symbols.h" static gchar *menu_item_get_text(GtkMenuItem *menu_item); @@ -213,60 +212,6 @@ void ui_set_fullscreen() } -// 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))); - - if (app->default_tag_tree == NULL) - { - GtkTreeIter iter; - GtkTreeStore *store = gtk_tree_store_new(1, G_TYPE_STRING); - - app->default_tag_tree = gtk_tree_view_new(); - treeviews_prepare_taglist(app->default_tag_tree, store); - gtk_tree_store_append(store, &iter, NULL); - gtk_tree_store_set(store, &iter, 0, _("No tags found"), -1); - gtk_widget_show(app->default_tag_tree); - g_object_ref((gpointer)app->default_tag_tree); // to hold it after removing - } - - // make all inactive, because there is no more tab left, or something strange occured - if (idx == -1 || doc_list[idx].file_type == NULL || ! doc_list[idx].file_type->has_tags) - { - gtk_widget_set_sensitive(app->tagbar, FALSE); - gtk_container_add(GTK_CONTAINER(app->tagbar), app->default_tag_tree); - return; - } - - if (update) - { // updating the tag list in the left tag window - if (doc_list[idx].tag_tree == NULL) - { - doc_list[idx].tag_store = gtk_tree_store_new(1, G_TYPE_STRING); - doc_list[idx].tag_tree = gtk_tree_view_new(); - treeviews_prepare_taglist(doc_list[idx].tag_tree, doc_list[idx].tag_store); - gtk_widget_show(doc_list[idx].tag_tree); - g_object_ref((gpointer)doc_list[idx].tag_tree); // to hold it after removing - } - - doc_list[idx].has_tags = symbols_recreate_tag_list(idx); - } - - if (doc_list[idx].has_tags) - { - gtk_widget_set_sensitive(app->tagbar, TRUE); - gtk_container_add(GTK_CONTAINER(app->tagbar), doc_list[idx].tag_tree); - } - else - { - gtk_widget_set_sensitive(app->tagbar, FALSE); - gtk_container_add(GTK_CONTAINER(app->tagbar), app->default_tag_tree); - } -} - - void ui_update_popup_reundo_items(gint index) { gboolean enable_undo; diff --git a/src/ui_utils.h b/src/ui_utils.h index 57a2c501..512c7fa8 100644 --- a/src/ui_utils.h +++ b/src/ui_utils.h @@ -38,9 +38,6 @@ void ui_set_editor_font(const gchar *font_name); void ui_set_fullscreen(); -void ui_update_tag_list(gint idx, gboolean update); - - void ui_update_popup_reundo_items(gint idx); void ui_update_popup_copy_items(gint idx);