From ae9ce78d40933189d6c2e8f16ee77902294f866f Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Mon, 8 Jan 2024 12:14:35 +0100 Subject: [PATCH] WIP: cleaning & commenting --- src/ui/tree.c | 35 +++-------------------------------- src/ui/window.c | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 46 deletions(-) diff --git a/src/ui/tree.c b/src/ui/tree.c index 1404a4a..ce5fb8e 100644 --- a/src/ui/tree.c +++ b/src/ui/tree.c @@ -60,7 +60,7 @@ /******************************************************************************/ -/* +/* Old links ( deprec ? ) To check. https://blog.gtk.org/2020/06/08/more-on-lists-in-gtk-4/ https://docs.gtk.org/gtk4/section-list-widget.html https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Tree_Models @@ -195,36 +195,6 @@ https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Columns_and_Renderer *............................................................................*/ -/* M A N I F E S T <<< J'AI TOUT VIRÉ SAUF "make" */ -/* ;; */ -/* ;; Dépendances sous GNU Guix */ -/* ;; */ - - -/* (specifications->manifest */ -/* (list */ -/* "bash" */ -/* "coreutils" */ -/* "gcc-toolchain" */ -/* "pkg-config" */ -/* "valgrind" */ -/* "findutils" */ -/* "gdb" */ -/* "make" <<<<<<<<<<<< */ -/* "gtk" */ -/* "libxml2" */ -/* "glew" */ -/* "glfw" */ -/* "libepoxy" */ -/* "pango@1.90.0" */ -/* "xorgproto" */ -/* "glib" */ -/* "mesa-headers" */ -/* "mesa" */ -/* "libadwaita" */ -/* ) */ -/* ) */ - #include #include #include @@ -328,7 +298,8 @@ How to enable the 'tree.c' code (line 318) to create widgets in the main window - The currently displayed tree code is at the end of file : window.c -\n\ (In the meanwhile, you can click the 'new button' at the bottom of the GtkBox.)\n\n\ NB The speed makefile bug has been fixed in branch [devel]\n\ - but not here, in branch [origin/dev/ui-simple-tree]\n"); + but not here, in branch [origin/dev/ui-simple-tree]\n\n\ +/home/jean/01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo\n"); return button; } diff --git a/src/ui/window.c b/src/ui/window.c index 639558d..a240a0e 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -129,7 +129,7 @@ static void gem_graph_client_window_init(GemGraphClientWindow *self) } /* - Est-ce que c'est encore utile ? + Is this useful ? (Does it FREE something ?) if (!gtk_widget_get_visible (my_window)) gtk_widget_set_visible (my_window, TRUE); @@ -139,9 +139,12 @@ static void gem_graph_client_window_init(GemGraphClientWindow *self) /* -------------------------------------------------------------------------- */ -static void create_my_list_model(); +static GtkWidget *create_my_list_model(); GtkWidget *create_a_button_in_(GemGraphClientWindow *my_window); +GtkWidget *my_tree = NULL; +GtkWidget *my_button = NULL; + void ui_set_stack(const char *mode) { @@ -157,9 +160,11 @@ void ui_set_stack(const char *mode) break; case 'r': gtk_menu_button_set_icon_name(window->main_button_mode, "system-run-symbolic"); - create_my_list_model(window); - create_a_button_in_(window); - create_a_button(window); // <<< This function is in tree.c + if (! my_tree) my_tree = create_my_list_model(window); + if (! my_button) { + my_button = create_a_button_in_(window); // <<< The active function is in this file + create_a_button(window); // <<< This function is in tree.c and still sterile !!! TODO + } break; case 'p': gtk_menu_button_set_icon_name(window->main_button_mode, "x-office-presentation-symbolic"); @@ -328,16 +333,12 @@ static GListStore *create_node_recursive (GListModel *model, // GListStore* g_ GtkTreeIter *iter_parent, int depth) { - if (model == NULL) - printf("tree.c > print test() in : create_node_recursive()\n"); - GtkTreeIter iter; if (model == NULL) model = gtk_tree_store_new (NUM_COLUMNS, G_TYPE_STRING); while (current_item->label) { - if (1) printf("[%d]-%s, ", depth, current_item->label); gtk_tree_store_append (model, &iter, iter_parent); gtk_tree_store_set (model, &iter, STRING_COLUMN, current_item->label, -1); @@ -350,22 +351,20 @@ static GListStore *create_node_recursive (GListModel *model, // GListStore* g_ } if (depth == 0) - return G_LIST_MODEL(model); // can cast to GListModel or to GtkTreeStore ? + return G_LIST_MODEL(model); // Should we cast to GtkTreeStore ? else return NULL; } -static void create_my_list_model(GemGraphClientWindow *my_window) +static GtkWidget *create_my_list_model(GemGraphClientWindow *my_window) { GtkWidget *my_tree_box; GtkWidget *my_scrolled_window; GListStore *my_list_model = NULL; - GtkWidget *my_tree_view; + GtkWidget *my_tree_view = NULL; GtkCellRenderer *renderer; my_list_model = create_node_recursive (my_list_model, O, NULL, 0); - printf(" << tree successfully created !\n"); - my_tree_view = gtk_tree_view_new_with_model (my_list_model); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (my_tree_view), FALSE); gtk_tree_view_set_enable_tree_lines (GTK_TREE_VIEW (my_tree_view), TRUE); @@ -392,5 +391,7 @@ static void create_my_list_model(GemGraphClientWindow *my_window) /* expand all rows after the my_tree_view widget has been realized */ g_signal_connect (my_tree_view, "realize", G_CALLBACK (gtk_tree_view_expand_all), NULL); + + return my_tree_view; }