diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-10-24 04:14:22 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-10-24 04:14:22 (EDT) |
commit | 505f7bd3f82bffe555f27d5dba4f71d845b8a9b4 (patch) | |
tree | f03c7dd435cad924a860e11e10d141c17cc4cfb3 | |
parent | 876ad44ae0e5f89952e92783e2993c7233feff07 (diff) | |
download | marquee-505f7bd3f82bffe555f27d5dba4f71d845b8a9b4.zip marquee-505f7bd3f82bffe555f27d5dba4f71d845b8a9b4.tar.gz marquee-505f7bd3f82bffe555f27d5dba4f71d845b8a9b4.tar.bz2 |
MqNotebook: Try to use gtk_tree_selection_select_iter()
-rw-r--r-- | src/notebook.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/src/notebook.c b/src/notebook.c index 8ef5733..d5503c5 100644 --- a/src/notebook.c +++ b/src/notebook.c @@ -133,7 +133,8 @@ new_tab_clicked_cb(GtkWidget G_GNUC_UNUSED *button, MqNotebook *notebook) } static void -create_tab_tree_model_recurse(MqTabTree *node, GtkTreeStore *tree_store, +create_tab_tree_model_recurse(MqNotebook *notebook, GtkTreeStore *tree_store, + GtkTreeSelection *tree_selection, MqTabTree *node, GtkTreeIter *parent_tree_iter) { GtkTreeIter tree_iter; @@ -144,22 +145,24 @@ create_tab_tree_model_recurse(MqTabTree *node, GtkTreeStore *tree_store, 0, mq_tree_position(node), 1, mq_tab_page_get_title(node->page), -1); - create_tab_tree_model_recurse( - MQ_TAB_TREE(mq_tree_first_child(node)), - tree_store, &tree_iter); + if (node->page == notebook->current_page) { + g_print("Selecting page \"%s\"\n", + mq_tab_page_get_title(node->page)); + gtk_tree_selection_select_iter(tree_selection, + &tree_iter); + } + create_tab_tree_model_recurse(notebook, tree_store, + tree_selection, MQ_TAB_TREE(mq_tree_first_child(node)), + &tree_iter); } } static GtkTreeModel * -create_tab_tree_model(MqNotebook *notebook) +create_tab_tree_model(MqNotebook *notebook, GtkTreeStore *tree_store, + GtkTreeSelection *tree_selection) { - GtkTreeStore *tree_store; - - tree_store = gtk_tree_store_new(2, G_TYPE_INT, G_TYPE_STRING); - - create_tab_tree_model_recurse( - MQ_TAB_TREE(mq_tree_first_child(notebook->tree)), - tree_store, NULL); + create_tab_tree_model_recurse(notebook, tree_store, tree_selection, + MQ_TAB_TREE(mq_tree_first_child(notebook->tree)), NULL); return GTK_TREE_MODEL(tree_store); } @@ -187,33 +190,34 @@ tab_tree_row_activated_cb(GtkTreeView G_GNUC_UNUSED *tree_view, static GtkWidget * create_tab_tree_view(MqNotebook *notebook) { - GtkTreeModel *tree_model; - GtkWidget *tree_view; + GtkTreeView *tree_view; GtkTreeSelection *tree_selection; + GtkTreeStore *tree_store; GtkCellRenderer *cell_renderer; - tree_model = create_tab_tree_model(notebook); - tree_view = gtk_tree_view_new_with_model(tree_model); - tree_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); + tree_store = gtk_tree_store_new(2, G_TYPE_INT, G_TYPE_STRING); + + tree_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model( + GTK_TREE_MODEL(tree_store))); + + tree_selection = gtk_tree_view_get_selection(tree_view); gtk_tree_selection_set_mode(tree_selection, GTK_SELECTION_BROWSE); - gtk_tree_selection_select_path(tree_selection, - gtk_tree_path_new_from_indices( - gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)), - -1)); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), FALSE); - gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(tree_view), - TRUE); - gtk_tree_view_expand_all(GTK_TREE_VIEW(tree_view)); - gtk_tree_view_set_reorderable(GTK_TREE_VIEW(tree_view), TRUE); - gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW(tree_view), TRUE); + + create_tab_tree_model(notebook, tree_store, tree_selection); + + gtk_tree_view_set_headers_visible(tree_view, FALSE); + gtk_tree_view_set_activate_on_single_click(tree_view, TRUE); + gtk_tree_view_expand_all(tree_view); + gtk_tree_view_set_reorderable(tree_view, TRUE); + gtk_tree_view_set_enable_tree_lines(tree_view, TRUE); g_signal_connect(tree_view, "row-activated", G_CALLBACK(tab_tree_row_activated_cb), notebook); cell_renderer = gtk_cell_renderer_text_new(); - gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree_view), + gtk_tree_view_insert_column_with_attributes(tree_view, -1, NULL, cell_renderer, "text", 1, NULL); - return tree_view; + return GTK_WIDGET(tree_view); } static void |