[tepl] utils: add list_box_clear()



commit 4b5280e2b87105991850c6b2f42fabda486fab06
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Nov 3 00:02:46 2020 +0100

    utils: add list_box_clear()

 docs/reference/tepl-sections.txt        |  1 +
 tepl/tepl-style-scheme-chooser-widget.c | 18 ++----------------
 tepl/tepl-utils.c                       | 25 +++++++++++++++++++++++++
 tepl/tepl-utils.h                       |  3 +++
 4 files changed, 31 insertions(+), 16 deletions(-)
---
diff --git a/docs/reference/tepl-sections.txt b/docs/reference/tepl-sections.txt
index d4d04ba..508affc 100644
--- a/docs/reference/tepl-sections.txt
+++ b/docs/reference/tepl-sections.txt
@@ -513,6 +513,7 @@ tepl_utils_file_query_exists_async
 tepl_utils_file_query_exists_finish
 tepl_utils_create_close_button
 tepl_utils_show_warning_dialog
+tepl_utils_list_box_clear
 tepl_utils_binding_transform_func_smart_bool
 </SECTION>
 
diff --git a/tepl/tepl-style-scheme-chooser-widget.c b/tepl/tepl-style-scheme-chooser-widget.c
index b7b9eb3..2f58608 100644
--- a/tepl/tepl-style-scheme-chooser-widget.c
+++ b/tepl/tepl-style-scheme-chooser-widget.c
@@ -4,6 +4,7 @@
 
 #include "tepl-style-scheme-chooser-widget.h"
 #include <gtksourceview/gtksource.h>
+#include "tepl-utils.h"
 
 /**
  * SECTION:style-scheme-chooser-widget
@@ -45,21 +46,6 @@ G_DEFINE_TYPE_WITH_CODE (TeplStyleSchemeChooserWidget,
                         G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER,
                                                gtk_source_style_scheme_chooser_interface_init))
 
-static void
-clear_list_box_foreach_cb (GtkWidget *child,
-                          gpointer   user_data)
-{
-       gtk_widget_destroy (child);
-}
-
-static void
-clear_list_box (GtkListBox *list_box)
-{
-       gtk_container_foreach (GTK_CONTAINER (list_box),
-                              clear_list_box_foreach_cb,
-                              NULL);
-}
-
 static void
 list_box_row_set_style_scheme (GtkListBoxRow        *list_box_row,
                               GtkSourceStyleScheme *style_scheme)
@@ -372,7 +358,7 @@ style_scheme_manager_notify_scheme_ids_cb (GtkSourceStyleSchemeManager  *manager
 
        style_scheme_id = tepl_style_scheme_chooser_widget_get_style_scheme_id (chooser);
 
-       clear_list_box (chooser->priv->list_box);
+       tepl_utils_list_box_clear (chooser->priv->list_box);
        populate_list_box (chooser);
 
        /* Note that the style_scheme_id may no longer exist, in which case no
diff --git a/tepl/tepl-utils.c b/tepl/tepl-utils.c
index d49c42f..4f15a93 100644
--- a/tepl/tepl-utils.c
+++ b/tepl/tepl-utils.c
@@ -798,6 +798,31 @@ tepl_utils_show_warning_dialog (GtkWindow   *parent,
        gtk_widget_show (dialog);
 }
 
+static void
+list_box_clear_foreach_cb (GtkWidget *child,
+                          gpointer   user_data)
+{
+       gtk_widget_destroy (child);
+}
+
+/**
+ * tepl_utils_list_box_clear:
+ * @list_box: a #GtkListBox.
+ *
+ * Removes all rows of @list_box, to obtain an empty #GtkListBox.
+ *
+ * Since: 5.2
+ */
+void
+tepl_utils_list_box_clear (GtkListBox *list_box)
+{
+       g_return_if_fail (GTK_IS_LIST_BOX (list_box));
+
+       gtk_container_foreach (GTK_CONTAINER (list_box),
+                              list_box_clear_foreach_cb,
+                              NULL);
+}
+
 /**
  * tepl_utils_binding_transform_func_smart_bool:
  * @binding: a #GBinding.
diff --git a/tepl/tepl-utils.h b/tepl/tepl-utils.h
index 88369f8..1699046 100644
--- a/tepl/tepl-utils.h
+++ b/tepl/tepl-utils.h
@@ -83,6 +83,9 @@ void          tepl_utils_show_warning_dialog                  (GtkWindow   *parent,
                                                                 const gchar *format,
                                                                 ...) G_GNUC_PRINTF(2, 3);
 
+_TEPL_EXTERN
+void           tepl_utils_list_box_clear                       (GtkListBox *list_box);
+
 /* Other */
 
 _TEPL_EXTERN


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