[gtk/wip/cdavis/remove-all-funcs: 1/2] gtklistbox: Add remove_all()




commit c3b7ca6dcb93c16c998153a7bca2459d00bc18ef
Author: Christopher Davis <christopherdavis gnome org>
Date:   Wed Sep 29 14:26:49 2021 -0700

    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 95120f8cef..5013f2210c 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 0e41498bda..f14a30fbe3 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]