summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Davis <christopherdavis@gnome.org>2021-09-29 15:20:37 -0700
committerMatthias Clasen <mclasen@redhat.com>2023-04-02 20:17:46 -0400
commitb34625363a1a2e20483510d615408418ea626be1 (patch)
tree51693f8ccfa667a47912c7e8d2725c26972aed71
parent49e56fc7b322196b3dc42f09f436596085672cb9 (diff)
downloadgtk+-b34625363a1a2e20483510d615408418ea626be1.tar.gz
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.
-rw-r--r--gtk/gtkflowbox.c26
-rw-r--r--gtk/gtkflowbox.h3
2 files changed, 29 insertions, 0 deletions
diff --git a/gtk/gtkflowbox.c b/gtk/gtkflowbox.c
index 8650c5a51e..1b8dacc69c 100644
--- a/gtk/gtkflowbox.c
+++ b/gtk/gtkflowbox.c
@@ -3098,6 +3098,32 @@ 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.
+ *
+ * This function does nothing if @box is backed by a model.
+ *
+ * Since: 4.12
+ */
+void
+gtk_flow_box_remove_all (GtkFlowBox *box)
+{
+ GtkFlowBoxPrivate *priv = BOX_PRIV (box);
+ GtkWidget *widget = GTK_WIDGET (box);
+ GtkWidget *child;
+
+ g_return_if_fail (GTK_IS_FLOW_BOX (box));
+
+ if (priv->bound_model)
+ return;
+
+ while ((child = gtk_widget_get_first_child (widget)) != NULL)
+ gtk_flow_box_remove (box, child);
+}
+
/* Keynav {{{2 */
static gboolean
diff --git a/gtk/gtkflowbox.h b/gtk/gtkflowbox.h
index 80c9f2939d..26bc71ab80 100644
--- a/gtk/gtkflowbox.h
+++ b/gtk/gtkflowbox.h
@@ -159,6 +159,9 @@ void gtk_flow_box_insert (GtkFlowBox
GDK_AVAILABLE_IN_ALL
void gtk_flow_box_remove (GtkFlowBox *box,
GtkWidget *widget);
+GDK_AVAILABLE_IN_4_12
+void gtk_flow_box_remove_all (GtkFlowBox *box);
+
GDK_AVAILABLE_IN_ALL
GtkFlowBoxChild *gtk_flow_box_get_child_at_index (GtkFlowBox *box,
int idx);