From c3b7ca6dcb93c16c998153a7bca2459d00bc18ef Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Wed, 29 Sep 2021 14:26:49 -0700 Subject: [PATCH 1/2] gtklistbox: Add remove_all() Adds a function to remove all children from a GtkListBox. This way app developers don't need to implement this themselves. --- gtk/gtklistbox.c | 22 ++++++++++++++++++---- gtk/gtklistbox.h | 3 +++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c index 95120f8cef2..5013f2210cb 100644 --- a/gtk/gtklistbox.c +++ b/gtk/gtklistbox.c @@ -431,10 +431,7 @@ gtk_list_box_set_property (GObject *obj, static void gtk_list_box_dispose (GObject *object) { - GtkWidget *child; - - while ((child = gtk_widget_get_first_child (GTK_WIDGET (object)))) - gtk_list_box_remove (GTK_LIST_BOX (object), child); + gtk_list_box_remove_all (GTK_LIST_BOX (object)); G_OBJECT_CLASS (gtk_list_box_parent_class)->dispose (object); } @@ -2428,6 +2425,23 @@ gtk_list_box_remove (GtkListBox *box, } } +/** + * gtk_list_box_remove_all: + * @box: a `GtkListBox` + * + * Removes all rows from @box. + */ +void +gtk_list_box_remove_all (GtkListBox *box) +{ + GtkWidget *child; + + g_return_if_fail (GTK_IS_LIST_BOX (box)); + + while ((child = gtk_widget_get_first_child (GTK_WIDGET (box)))) + gtk_list_box_remove (box, child); +} + static void gtk_list_box_compute_expand (GtkWidget *widget, gboolean *hexpand_p, diff --git a/gtk/gtklistbox.h b/gtk/gtklistbox.h index 0e41498bda1..f14a30fbe3c 100644 --- a/gtk/gtklistbox.h +++ b/gtk/gtklistbox.h @@ -178,6 +178,9 @@ void gtk_list_box_insert (GtkListBox GDK_AVAILABLE_IN_ALL void gtk_list_box_remove (GtkListBox *box, GtkWidget *child); +GDK_AVAILABLE_IN_ALL +void gtk_list_box_remove_all (GtkListBox *box); + GDK_AVAILABLE_IN_ALL GtkListBoxRow* gtk_list_box_get_selected_row (GtkListBox *box); GDK_AVAILABLE_IN_ALL -- GitLab From 022491762c726180407e97447fdec4d0dd66143b Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Wed, 29 Sep 2021 15:20:37 -0700 Subject: [PATCH 2/2] gtkflowbox: Add remove_all() Removing all items from containers is a common use case. Without this applications needed to implement this manually. It makes senses to handle it here. --- gtk/gtkflowbox.c | 17 +++++++++++++++++ gtk/gtkflowbox.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/gtk/gtkflowbox.c b/gtk/gtkflowbox.c index 188b76c5622..8b281b860cf 100644 --- a/gtk/gtkflowbox.c +++ b/gtk/gtkflowbox.c @@ -3085,6 +3085,23 @@ gtk_flow_box_remove (GtkFlowBox *box, g_signal_emit (box, signals[SELECTED_CHILDREN_CHANGED], 0); } +/** + * gtk_flow_box_remove_all: + * @box: a `GtkFlowBox` + * + * Removes all children from @box. + */ +void +gtk_flow_box_remove_all (GtkFlowBox *box) +{ + GtkWidget *child; + + g_return_if_fail (GTK_IS_FLOW_BOX (box)); + + while ((child = gtk_widget_get_first_child (GTK_WIDGET (box)))) + gtk_flow_box_remove (box, child); +} + /* Keynav {{{2 */ static gboolean diff --git a/gtk/gtkflowbox.h b/gtk/gtkflowbox.h index 3625d18ddf2..2283138206c 100644 --- a/gtk/gtkflowbox.h +++ b/gtk/gtkflowbox.h @@ -154,6 +154,9 @@ void gtk_flow_box_insert (GtkFlowBox GDK_AVAILABLE_IN_ALL void gtk_flow_box_remove (GtkFlowBox *box, GtkWidget *widget); +GDK_AVAILABLE_IN_ALL +void gtk_flow_box_remove_all (GtkFlowBox *box); + GDK_AVAILABLE_IN_ALL GtkFlowBoxChild *gtk_flow_box_get_child_at_index (GtkFlowBox *box, int idx); -- GitLab