summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-09-28 13:00:31 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-09-28 13:00:31 (EDT)
commit3844195417b51c9bff6ee73ef5140a2bec84e492 (patch)
treeb609b8aa45c596418a7fbf830a9199d3e7206686
parenta4621ae605a2ccefdb8e0b2d51178f6802cd8794 (diff)
downloadmarquee-3844195417b51c9bff6ee73ef5140a2bec84e492.zip
marquee-3844195417b51c9bff6ee73ef5140a2bec84e492.tar.gz
marquee-3844195417b51c9bff6ee73ef5140a2bec84e492.tar.bz2
MqTab: Implement tab list
-rw-r--r--src/tab.c57
1 files changed, 54 insertions, 3 deletions
diff --git a/src/tab.c b/src/tab.c
index a38f5c4..0452106 100644
--- a/src/tab.c
+++ b/src/tab.c
@@ -169,10 +169,61 @@ tab_list_button_toggled_cb(GtkToggleButton *toggle_button, GtkWidget *tab_list)
#define CLICKED_CB(Y, X, CB) \
g_signal_connect(buttons[Y * BUTTON_COLS + X], "clicked", CB, tab)
+static void
+create_tree_model_recurse(MqTab *node, GtkTreeStore *tree_store,
+ GtkTreeIter *parent_tree_iter)
+{
+ GtkTreeIter tree_iter;
+
+ for (; node; node = node->next) {
+ gtk_tree_store_append(tree_store, &tree_iter, parent_tree_iter);
+ gtk_tree_store_set(tree_store, &tree_iter, 0, node->title, -1);
+ create_tree_model_recurse(node->first_child, tree_store,
+ &tree_iter);
+ }
+}
+
+static GtkTreeModel *
+create_tree_model(MqTab *tab)
+{
+ GtkTreeStore *tree_store;
+
+ tree_store = gtk_tree_store_new(1, G_TYPE_STRING);
+
+ create_tree_model_recurse(tab->root->first_child, tree_store, NULL);
+
+ return GTK_TREE_MODEL(tree_store);
+}
+
static GtkWidget *
-create_tab_list(void)
+create_tab_list(MqTab *tab)
{
- return gtk_label_new("Tab list");
+ GtkWidget *tree_view;
+ GtkCellRenderer *cell_renderer;
+ GtkWidget *scrolled_window;
+
+ tree_view = gtk_tree_view_new_with_model(create_tree_model(tab));
+ gtk_tree_selection_set_mode(gtk_tree_view_get_selection(
+ GTK_TREE_VIEW(tree_view)), GTK_SELECTION_BROWSE);
+ 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);
+
+ cell_renderer = gtk_cell_renderer_text_new();
+ gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree_view),
+ -1, NULL, cell_renderer, "text", 0, NULL);
+
+ scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_min_content_width(
+ GTK_SCROLLED_WINDOW(scrolled_window), 400);
+ gtk_scrolled_window_set_min_content_height(
+ GTK_SCROLLED_WINDOW(scrolled_window), 200);
+ gtk_container_add(GTK_CONTAINER(scrolled_window), tree_view);
+
+ return scrolled_window;
}
static void
@@ -203,7 +254,7 @@ create_tab_popover(GtkWidget *widget, MqTab *tab)
CLICKED_CB(1, 1, G_CALLBACK(new_window_clicked_cb));
/* Set up the tab list. */
- tab_list = create_tab_list();
+ tab_list = create_tab_list(tab);
/* Set up the tab list scrolled window.
*