summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2023-04-03 10:29:13 +0000
committerMatthias Clasen <mclasen@redhat.com>2023-04-03 10:29:13 +0000
commit79b0e594cd21c75209aab973b17ced3788a21bfe (patch)
tree002e1e69d169c1e70d8ce4deb91506e7bd4c2352
parent6ef3d77b9a4a752eb40b6e333685a0ea06c012d0 (diff)
parentb34625363a1a2e20483510d615408418ea626be1 (diff)
downloadgtk+-79b0e594cd21c75209aab973b17ced3788a21bfe.tar.gz
Merge branch 'listbox-remove-all' into 'main'
gtklistbox: Add remove_all() See merge request GNOME/gtk!5779
-rw-r--r--gtk/gtkflowbox.c26
-rw-r--r--gtk/gtkflowbox.h3
-rw-r--r--gtk/gtklistbox.c30
-rw-r--r--gtk/gtklistbox.h3
4 files changed, 58 insertions, 4 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);
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c
index 18dad80889..8d2c0d0a95 100644
--- a/gtk/gtklistbox.c
+++ b/gtk/gtklistbox.c
@@ -433,10 +433,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);
}
@@ -2422,6 +2419,31 @@ gtk_list_box_remove (GtkListBox *box,
}
}
+/**
+ * gtk_list_box_remove_all:
+ * @box: a `GtkListBox`
+ *
+ * Removes all rows from @box.
+ *
+ * This function does nothing if @box is backed by a model.
+ *
+ * Since: 4.12
+ */
+void
+gtk_list_box_remove_all (GtkListBox *box)
+{
+ GtkWidget *widget = GTK_WIDGET (box);
+ GtkWidget *child;
+
+ g_return_if_fail (GTK_IS_LIST_BOX (box));
+
+ if (box->bound_model)
+ return;
+
+ while ((child = gtk_widget_get_first_child (widget)) != NULL)
+ 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 1a2dec8cd9..71d42e1ee2 100644
--- a/gtk/gtklistbox.h
+++ b/gtk/gtklistbox.h
@@ -180,6 +180,9 @@ void gtk_list_box_insert (GtkListBox
GDK_AVAILABLE_IN_ALL
void gtk_list_box_remove (GtkListBox *box,
GtkWidget *child);
+GDK_AVAILABLE_IN_4_12
+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