diff options
-rw-r--r-- | src/notebook.c | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/src/notebook.c b/src/notebook.c index d5503c5..8ef5733 100644 --- a/src/notebook.c +++ b/src/notebook.c @@ -133,8 +133,7 @@ new_tab_clicked_cb(GtkWidget G_GNUC_UNUSED *button, MqNotebook *notebook) } static void -create_tab_tree_model_recurse(MqNotebook *notebook, GtkTreeStore *tree_store, - GtkTreeSelection *tree_selection, MqTabTree *node, +create_tab_tree_model_recurse(MqTabTree *node, GtkTreeStore *tree_store, GtkTreeIter *parent_tree_iter) { GtkTreeIter tree_iter; @@ -145,24 +144,22 @@ create_tab_tree_model_recurse(MqNotebook *notebook, GtkTreeStore *tree_store, 0, mq_tree_position(node), 1, mq_tab_page_get_title(node->page), -1); - 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); + create_tab_tree_model_recurse( + MQ_TAB_TREE(mq_tree_first_child(node)), + tree_store, &tree_iter); } } static GtkTreeModel * -create_tab_tree_model(MqNotebook *notebook, GtkTreeStore *tree_store, - GtkTreeSelection *tree_selection) +create_tab_tree_model(MqNotebook *notebook) { - create_tab_tree_model_recurse(notebook, tree_store, tree_selection, - MQ_TAB_TREE(mq_tree_first_child(notebook->tree)), NULL); + 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); return GTK_TREE_MODEL(tree_store); } @@ -190,34 +187,33 @@ tab_tree_row_activated_cb(GtkTreeView G_GNUC_UNUSED *tree_view, static GtkWidget * create_tab_tree_view(MqNotebook *notebook) { - GtkTreeView *tree_view; + GtkTreeModel *tree_model; + GtkWidget *tree_view; GtkTreeSelection *tree_selection; - GtkTreeStore *tree_store; GtkCellRenderer *cell_renderer; - 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); + 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)); gtk_tree_selection_set_mode(tree_selection, GTK_SELECTION_BROWSE); - - 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); + 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); 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(tree_view, + gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree_view), -1, NULL, cell_renderer, "text", 1, NULL); - return GTK_WIDGET(tree_view); + return tree_view; } static void |