appended tree view

This commit is contained in:
Mario Hüttel 2018-05-08 16:02:44 +02:00
parent 7d3b7f96eb
commit 5aeaa1db9e
2 changed files with 72 additions and 34 deletions

View File

@ -34,40 +34,16 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkSearchEntry">
<object class="GtkTreeView" id="cell-tree">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkListBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">browse</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>

72
main.c
View File

@ -2,6 +2,14 @@
#include "gdsparse.h"
#include <gtk/gtk.h>
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();