gtkflowbox: Add remove_all()
authorChristopher Davis <christopherdavis@gnome.org>
Wed, 29 Sep 2021 22:20:37 +0000 (15:20 -0700)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 3 Apr 2023 00:17:46 +0000 (20:17 -0400)
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
gtk/gtkflowbox.h

index 8650c5a51edf33f77b9166e86adbdab9af957d78..1b8dacc69c1497c87459fc3479d33028544b452c 100644 (file)
@@ -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
index 80c9f2939d965d468949bfe9ec4f0eec877844b7..26bc71ab802d0a51052fe75987d16cf40c91e1c5 100644 (file)
@@ -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);