From c38622be0575998457f7c9c61efac8581541144b Mon Sep 17 00:00:00 2001 From: AkriliksKotya Date: Mon, 8 Dec 2025 22:35:00 +0500 Subject: [PATCH] delete grid witn buttons in button click --- main.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 83d41cd..956c111 100644 --- a/main.c +++ b/main.c @@ -2,11 +2,22 @@ #include #include +static void buttons (GtkApplication *app, gpointer *user_data, char *directory); -static void on_button_clicked(GtkWidget *widget, gpointer user_data){ - g_print("Button clicked\n"); +// action on clicked button +static void on_button_clicked(GtkButton *btn, gpointer user_data){ + const char *label = gtk_button_get_label(btn); + g_print("Button %s clicked\n",label); + char dir = *label; + + GtkWidget *child = gtk_widget_get_first_child(GTK_WIDGET(user_data)); + while (child != NULL) { + GtkWidget *next_child = gtk_widget_get_next_sibling(child); + gtk_grid_remove(user_data, child); + child = next_child; + } } - +// gets number of items and return value in arrays int *check_dir(int *arr, DIR *d, char *directory){ int i = 0; int j = 0; @@ -32,15 +43,15 @@ int *check_dir(int *arr, DIR *d, char *directory){ return 0; } -static void app_activate (GtkApplication *app, gpointer *user_data){ +// present buttons +static void buttons (GtkApplication *app, gpointer *user_data,char *directory){ int p[2]; int g; int i = 0; int j = 0; DIR *d; struct dirent *dir; - char directory[100]; - scanf("%100[^\n]", &directory); + // char directory[100]; d = opendir(directory); GtkWidget *window = gtk_application_window_new (GTK_APPLICATION(app)); gtk_window_set_title (GTK_WINDOW (window), "File Manager"); @@ -71,7 +82,7 @@ static void app_activate (GtkApplication *app, gpointer *user_data){ gtk_grid_attach (GTK_GRID(grid), btn, j, i, 1,1); gtk_widget_set_halign(btn, GTK_ALIGN_CENTER); gtk_widget_set_valign(btn, GTK_ALIGN_CENTER); - g_signal_connect(btn, "clicked",G_CALLBACK(on_button_clicked),NULL); + g_signal_connect(btn, "clicked",G_CALLBACK(on_button_clicked),grid); j++; if (j >= 10){ j = 0; @@ -84,6 +95,12 @@ static void app_activate (GtkApplication *app, gpointer *user_data){ printf("set child and present window\n"); gtk_window_set_child(GTK_WINDOW(window),grid); gtk_window_present(GTK_WINDOW(window)); +} + +static void app_activate (GtkApplication *app, gpointer *user_data){ + char directory[100]; + scanf("%100[^\n]", &directory); + buttons(app,user_data,directory); g_print("Started\n"); }