From 5aeaa1db9e3773a9bbcc0bb38cb82f86ba468d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 8 May 2018 16:02:44 +0200 Subject: [PATCH] appended tree view --- glade/main.glade | 34 ++++------------------- main.c | 72 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 72 insertions(+), 34 deletions(-) diff --git a/glade/main.glade b/glade/main.glade index 8faea93..ac561d3 100644 --- a/glade/main.glade +++ b/glade/main.glade @@ -34,39 +34,15 @@ True False - + True - False - vertical - - - True - True - edit-find-symbolic - False - False - - - False - True - 0 - - - - - True - False - browse - - - True - True - 1 - + True + + - False + True True 0 diff --git a/main.c b/main.c index fbbe1ee..78e6fca 100644 --- a/main.c +++ b/main.c @@ -2,6 +2,14 @@ #include "gdsparse.h" #include +struct open_button_data { + GList **list_ptr; + GtkTreeStore *cell_store; +}; + + + + gboolean on_window_close(gpointer window, gpointer user) { gtk_widget_destroy(GTK_WIDGET(window)); @@ -9,13 +17,39 @@ gboolean on_window_close(gpointer window, gpointer user) return TRUE; } +static void list_add_label(const char *text, GtkListBox *box) +{ + +} + void on_load_gds(gpointer button, gpointer user) { - GList **list_ptr = (GList **)user; + GList *cell; + GtkTreeIter libiter; + GtkTreeIter celliter; + GList *lib; + struct gds_library *gds_lib; + struct gds_cell *gds_c; + struct open_button_data *ptr = (struct open_button_data *)user; + GtkTreeStore *store = ptr->cell_store; + + gtk_tree_store_clear(store); + + clear_lib_list(ptr->list_ptr); + parse_gds_from_file("/home/mari/Desktop/test.gds", ptr->list_ptr); + + for (lib = *(ptr->list_ptr); lib != NULL; lib = lib->next) { + gds_lib = (struct gds_library *)lib->data; + /* Create top level iter */ + gtk_tree_store_append (store, &libiter, NULL); + gtk_tree_store_set (store, &libiter, 0, gds_lib->name, -1); + for (cell = gds_lib->cells; cell != NULL; cell = cell->next) { + gds_c = (struct gds_cell *)cell->data; + gtk_tree_store_append (store, &celliter, &libiter); + gtk_tree_store_set (store, &celliter, 0, gds_c->name, -1); + } + } - // TODO: File dialog - clear_lib_list(list_ptr); - parse_gds_from_file("/home/mari/Desktop/test.gds", list_ptr); } void on_convert_clicked(gpointer button, gpointer user) @@ -23,18 +57,46 @@ void on_convert_clicked(gpointer button, gpointer user) printf("convert\n"); } +static GtkTreeStore * setup_cell_selector(GtkTreeView* view) +{ + GtkTreeStore *cell_store; + + GtkCellRenderer *render; + GtkTreeViewColumn *column; + + cell_store = gtk_tree_store_new(1, G_TYPE_STRING); + gtk_tree_view_set_model(view, GTK_TREE_MODEL(cell_store)); + + render = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Cell Selection", render, "text", 0, NULL); + gtk_tree_view_append_column(view, column); + + return cell_store; +} + int main(int argc, char **argv) { GtkBuilder *main_builder; GList *gds_libs = NULL; + GtkTreeView *cell_tree; + GtkTreeStore *cell_store; + struct open_button_data open_data; gtk_init(&argc, &argv); main_builder = gtk_builder_new_from_file("glade/main.glade"); gtk_builder_connect_signals(main_builder, NULL); + + + cell_tree = (GtkTreeView *)gtk_builder_get_object(main_builder, "cell-tree"); + cell_store = setup_cell_selector(cell_tree); + + + open_data.cell_store = cell_store; + open_data.list_ptr = &gds_libs; g_signal_connect(GTK_WIDGET(gtk_builder_get_object(main_builder, "button-load-gds")), - "clicked", G_CALLBACK(on_load_gds), (gpointer)&gds_libs); + "clicked", G_CALLBACK(on_load_gds), (gpointer)&open_data); gtk_main();