[gtk/listview-constructors] list widgets: Simplify the constructors




commit b628338db3e0bb4c906424294e4e988d45ed26f3
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Sep 1 12:24:06 2020 -0400

    list widgets: Simplify the constructors
    
    Now that both arguments to the _new_with_factory() constructors
    are nullable, there's no good reason to keep a separate _new()
    around. Just make gtk_list_view_new() and gtk_grid_view_new()
    take both a model and a factory.

 demos/gtk-demo/listview_applauncher.c |  2 +-
 demos/gtk-demo/listview_clocks.c      |  2 +-
 demos/gtk-demo/listview_colors.c      |  4 ++--
 demos/gtk-demo/listview_weather.c     |  2 +-
 demos/gtk-demo/listview_words.c       |  2 +-
 docs/reference/gtk/gtk4-sections.txt  |  2 --
 gtk/gtkcolumnview.c                   |  2 +-
 gtk/gtkcustompaperunixdialog.c        |  2 +-
 gtk/gtkgridview.c                     | 38 +++++----------------------------
 gtk/gtkgridview.h                     |  4 +---
 gtk/gtklistview.c                     | 40 ++++++-----------------------------
 gtk/gtklistview.h                     |  4 +---
 tests/testcolumnview.c                |  2 +-
 tests/testlistdnd.c                   |  6 +++---
 tests/testlistview-animating.c        |  2 +-
 tests/testlistview.c                  |  2 +-
 16 files changed, 27 insertions(+), 89 deletions(-)
---
diff --git a/demos/gtk-demo/listview_applauncher.c b/demos/gtk-demo/listview_applauncher.c
index c52a224e2e..3dcdbca055 100644
--- a/demos/gtk-demo/listview_applauncher.c
+++ b/demos/gtk-demo/listview_applauncher.c
@@ -176,7 +176,7 @@ do_listview_applauncher (GtkWidget *do_widget)
 
       /* Create the list widget here.
        */
-      list = gtk_list_view_new_with_factory (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), 
factory);
+      list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
 
       /* We connect the activate signal here. It's the function we defined
        * above for launching the selected application.
diff --git a/demos/gtk-demo/listview_clocks.c b/demos/gtk-demo/listview_clocks.c
index 07332da259..9dbdc0d5e7 100644
--- a/demos/gtk-demo/listview_clocks.c
+++ b/demos/gtk-demo/listview_clocks.c
@@ -485,7 +485,7 @@ do_listview_clocks (GtkWidget *do_widget)
       g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
 
       model = GTK_SELECTION_MODEL (gtk_no_selection_new (create_clocks_model ()));
-      gridview = gtk_grid_view_new_with_factory (model, factory);
+      gridview = gtk_grid_view_new (model, factory);
       gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
       gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
 
diff --git a/demos/gtk-demo/listview_colors.c b/demos/gtk-demo/listview_colors.c
index 64fb6e0cb5..e46e7d8b3c 100644
--- a/demos/gtk-demo/listview_colors.c
+++ b/demos/gtk-demo/listview_colors.c
@@ -663,7 +663,7 @@ create_color_grid (void)
   GtkWidget *gridview;
   GtkListItemFactory *factory;
 
-  gridview = gtk_grid_view_new (NULL);
+  gridview = gtk_grid_view_new (NULL, NULL);
   gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
   gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
 
@@ -950,7 +950,7 @@ do_listview_colors (GtkWidget *do_widget)
 
       factory = gtk_signal_list_item_factory_new ();
       g_signal_connect (factory, "setup", G_CALLBACK (setup_selection_listitem_cb), NULL);
-      selection_view = gtk_grid_view_new_with_factory (NULL, factory);
+      selection_view = gtk_grid_view_new (NULL, factory);
       gtk_widget_add_css_class (selection_view, "compact");
       gtk_grid_view_set_max_columns (GTK_GRID_VIEW (selection_view), 200);
       gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), selection_view);
diff --git a/demos/gtk-demo/listview_weather.c b/demos/gtk-demo/listview_weather.c
index 6f0f17f0a6..488fd24ead 100644
--- a/demos/gtk-demo/listview_weather.c
+++ b/demos/gtk-demo/listview_weather.c
@@ -288,7 +288,7 @@ create_weather_view (void)
   g_signal_connect (factory, "setup", G_CALLBACK (setup_widget), NULL);
   g_signal_connect (factory, "bind", G_CALLBACK (bind_widget), NULL);
   model = GTK_SELECTION_MODEL (gtk_no_selection_new (create_weather_model ()));
-  listview = gtk_list_view_new_with_factory (model, factory);
+  listview = gtk_list_view_new (model, factory);
   gtk_orientable_set_orientation (GTK_ORIENTABLE (listview), GTK_ORIENTATION_HORIZONTAL);
   gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE);
 
diff --git a/demos/gtk-demo/listview_words.c b/demos/gtk-demo/listview_words.c
index 8b41be795b..4932d3f9d7 100644
--- a/demos/gtk-demo/listview_words.c
+++ b/demos/gtk-demo/listview_words.c
@@ -217,7 +217,7 @@ do_listview_words (GtkWidget *do_widget)
       gtk_widget_set_vexpand (sw, TRUE);
       gtk_overlay_set_child (GTK_OVERLAY (overlay), sw);
 
-      listview = gtk_list_view_new_with_factory (
+      listview = gtk_list_view_new (
           GTK_SELECTION_MODEL (gtk_no_selection_new (G_LIST_MODEL (filter_model))),
           gtk_builder_list_item_factory_new_from_bytes (NULL,
               g_bytes_new_static (factory_text, strlen (factory_text))));
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 1ec07553d8..2565d38c43 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -520,7 +520,6 @@ gtk_signal_list_item_factory_get_type
 <TITLE>GtkListView</TITLE>
 GtkListView
 gtk_list_view_new
-gtk_list_view_new_with_factory
 gtk_list_view_set_factory
 gtk_list_view_get_factory
 gtk_list_view_set_model
@@ -616,7 +615,6 @@ gtk_column_view_column_get_type
 <TITLE>GtkGridView</TITLE>
 GtkGridView
 gtk_grid_view_new
-gtk_grid_view_new_with_factory
 gtk_grid_view_set_model
 gtk_grid_view_get_model
 gtk_grid_view_set_max_columns
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index 48a87ea6e3..c3cb62839e 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -1165,7 +1165,7 @@ gtk_column_view_init (GtkColumnView *self)
 
   self->sorter = gtk_column_view_sorter_new ();
   self->factory = gtk_column_list_item_factory_new (self);
-  self->listview = GTK_LIST_VIEW (gtk_list_view_new_with_factory (NULL,
+  self->listview = GTK_LIST_VIEW (gtk_list_view_new (NULL,
         GTK_LIST_ITEM_FACTORY (g_object_ref (self->factory))));
   gtk_widget_set_hexpand (GTK_WIDGET (self->listview), TRUE);
   gtk_widget_set_vexpand (GTK_WIDGET (self->listview), TRUE);
diff --git a/gtk/gtkcustompaperunixdialog.c b/gtk/gtkcustompaperunixdialog.c
index 927c14f80c..ce282f8c32 100644
--- a/gtk/gtkcustompaperunixdialog.c
+++ b/gtk/gtkcustompaperunixdialog.c
@@ -901,7 +901,7 @@ populate_dialog (GtkCustomPaperUnixDialog *dialog)
   g_signal_connect (factory, "bind", G_CALLBACK (bind_item), NULL);
   g_signal_connect (factory, "unbind", G_CALLBACK (unbind_item), NULL);
 
-  listview = gtk_list_view_new_with_factory (model, factory);
+  listview = gtk_list_view_new (model, factory);
   gtk_widget_set_size_request (listview, 140, -1);
 
   dialog->listview = listview;
diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c
index c80c60108b..5e3af58f5b 100644
--- a/gtk/gtkgridview.c
+++ b/gtk/gtkgridview.c
@@ -1179,51 +1179,23 @@ gtk_grid_view_init (GtkGridView *self)
 /**
  * gtk_grid_view_new:
  * @model: (allow-none) (transfer full): the model to use, or %NULL
- *
- * Creates a new #GtkGridView.
- *
- * You most likely want to call gtk_grid_view_set_factory() to
- * set up a way to map its items to widgets next.
- *
- * Returns: a new #GtkGridView
- **/
-GtkWidget *
-gtk_grid_view_new (GtkSelectionModel *model)
-{
-  GtkWidget *result;
-
-  g_return_val_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model), NULL);
-
-  result = g_object_new (GTK_TYPE_GRID_VIEW,
-                         "model", model,
-                         NULL);
-
-  /* consume the reference */
-  g_clear_object (&model);
-
-  return result;
-}
-
-/**
- * gtk_grid_view_new_with_factory:
- * @model: (allow-none) (transfer full): the model to use, or %NULL
  * @factory: (allow-none) (transfer full): The factory to populate items with, or %NULL
  *
  * Creates a new #GtkGridView that uses the given @factory for
  * mapping items to widgets.
  *
  * The function takes ownership of the
- * argument, so you can write code like
+ * arguments, so you can write code like
  * ```
- *   grid_view = gtk_grid_view_new_with_factory (create_model (),
+ *   grid_view = gtk_grid_view_new (create_model (),
  *     gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
  * ```
  *
- * Returns: a new #GtkGridView using the given @factory
+ * Returns: a new #GtkGridView using the given @model and @factory
  **/
 GtkWidget *
-gtk_grid_view_new_with_factory (GtkSelectionModel  *model,
-                                GtkListItemFactory *factory)
+gtk_grid_view_new (GtkSelectionModel  *model,
+                   GtkListItemFactory *factory)
 {
   GtkWidget *result;
 
diff --git a/gtk/gtkgridview.h b/gtk/gtkgridview.h
index 4dd6b067bd..629a8db7ff 100644
--- a/gtk/gtkgridview.h
+++ b/gtk/gtkgridview.h
@@ -48,9 +48,7 @@ GDK_AVAILABLE_IN_ALL
 GType           gtk_grid_view_get_type                          (void) G_GNUC_CONST;
 
 GDK_AVAILABLE_IN_ALL
-GtkWidget *     gtk_grid_view_new                               (GtkSelectionModel      *model);
-GDK_AVAILABLE_IN_ALL
-GtkWidget *     gtk_grid_view_new_with_factory                  (GtkSelectionModel      *model,
+GtkWidget *     gtk_grid_view_new                               (GtkSelectionModel      *model,
                                                                  GtkListItemFactory     *factory);
 
 GDK_AVAILABLE_IN_ALL
diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c
index 514e595383..e7f2cf18bb 100644
--- a/gtk/gtklistview.c
+++ b/gtk/gtklistview.c
@@ -108,7 +108,7 @@
  *   g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
  *   g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
  *
- *   list = gtk_list_view_new_with_factory (model, factory);
+ *   list = gtk_list_view_new (model, factory);
  *
  *   g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
  *
@@ -934,51 +934,23 @@ gtk_list_view_init (GtkListView *self)
 /**
  * gtk_list_view_new:
  * @model: (allow-none) (transfer full): the model to use, or %NULL
- *
- * Creates a new #GtkListView.
- *
- * You most likely want to call gtk_list_view_set_factory()
- * to set up a way to map its items to widgets.
- *
- * Returns: a new #GtkListView
- **/
-GtkWidget *
-gtk_list_view_new (GtkSelectionModel *model)
-{
-  GtkWidget *result;
-
-  g_return_val_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model), NULL);
-
-  result = g_object_new (GTK_TYPE_LIST_VIEW,
-                         "model", model,
-                         NULL);
-
-  /* consume the reference */
-  g_clear_object (&model);
-
-  return result;
-}
-
-/**
- * gtk_list_view_new_with_factory:
- * @model: (allow-none) (transfer full): the model to use, or %NULL
  * @factory: (allow-none) (transfer full): The factory to populate items with, or %NULL
  *
  * Creates a new #GtkListView that uses the given @factory for
  * mapping items to widgets.
  *
  * The function takes ownership of the
- * argument, so you can write code like
+ * arguments, so you can write code like
  * ```
- *   list_view = gtk_list_view_new_with_factory (create_model (),
+ *   list_view = gtk_list_view_new (create_model (),
  *     gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
  * ```
  *
- * Returns: a new #GtkListView using the given @factory
+ * Returns: a new #GtkListView using the given @model and @factory
  **/
 GtkWidget *
-gtk_list_view_new_with_factory (GtkSelectionModel  *model,
-                                GtkListItemFactory *factory)
+gtk_list_view_new (GtkSelectionModel  *model,
+                   GtkListItemFactory *factory)
 {
   GtkWidget *result;
 
diff --git a/gtk/gtklistview.h b/gtk/gtklistview.h
index 43c29b0ddc..9a258de1da 100644
--- a/gtk/gtklistview.h
+++ b/gtk/gtklistview.h
@@ -47,9 +47,7 @@ GDK_AVAILABLE_IN_ALL
 GType           gtk_list_view_get_type                          (void) G_GNUC_CONST;
 
 GDK_AVAILABLE_IN_ALL
-GtkWidget *     gtk_list_view_new                               (GtkSelectionModel      *model);
-GDK_AVAILABLE_IN_ALL
-GtkWidget *     gtk_list_view_new_with_factory                  (GtkSelectionModel      *model,
+GtkWidget *     gtk_list_view_new                               (GtkSelectionModel      *model,
                                                                  GtkListItemFactory     *factory);
 
 GDK_AVAILABLE_IN_ALL
diff --git a/tests/testcolumnview.c b/tests/testcolumnview.c
index 725ce67b7a..d38e83ce6d 100644
--- a/tests/testcolumnview.c
+++ b/tests/testcolumnview.c
@@ -773,7 +773,7 @@ main (int argc, char *argv[])
 
   g_object_unref (filter);
 
-  list = gtk_list_view_new_with_factory (
+  list = gtk_list_view_new (
              GTK_SELECTION_MODEL (gtk_single_selection_new (g_object_ref (gtk_column_view_get_columns 
(GTK_COLUMN_VIEW (view))))),
              gtk_builder_list_item_factory_new_from_bytes (scope, g_bytes_new_static (factory_ui, strlen 
(factory_ui))));
   gtk_box_append (GTK_BOX (hbox), list);
diff --git a/tests/testlistdnd.c b/tests/testlistdnd.c
index 899ed1edc1..803ff2164d 100644
--- a/tests/testlistdnd.c
+++ b/tests/testlistdnd.c
@@ -348,7 +348,7 @@ main (int argc, char *argv[])
   g_signal_connect (factory, "bind", G_CALLBACK (bind_item), NULL);
   g_signal_connect (factory, "unbind", G_CALLBACK (unbind_item), NULL);
 
-  grid = gtk_grid_view_new_with_factory (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
+  grid = gtk_grid_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
   gtk_grid_view_set_min_columns (GTK_GRID_VIEW (grid), 20);
   gtk_grid_view_set_max_columns (GTK_GRID_VIEW (grid), 20);
 
@@ -359,7 +359,7 @@ main (int argc, char *argv[])
   gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
   gtk_stack_add_titled (GTK_STACK (stack), sw, "list", "GtkListView");
 
-  list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_model (0, 400, 1, 
FALSE))));
+  list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_model (0, 400, 1, 
FALSE))), NULL);
   gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
 
   factory = gtk_signal_list_item_factory_new ();
@@ -401,7 +401,7 @@ main (int argc, char *argv[])
   gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
   gtk_stack_add_titled (GTK_STACK (stack), sw, "tree", "Tree");
 
-  list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_tree_model (20, 20))));
+  list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_tree_model (20, 20))), 
NULL);
   gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
 
   factory = gtk_signal_list_item_factory_new ();
diff --git a/tests/testlistview-animating.c b/tests/testlistview-animating.c
index 70aa4a1de6..33c69e3565 100644
--- a/tests/testlistview-animating.c
+++ b/tests/testlistview-animating.c
@@ -149,7 +149,7 @@ main (int   argc,
   factory = gtk_signal_list_item_factory_new ();
   g_signal_connect (factory, "setup", G_CALLBACK (setup_list_item), NULL);
   g_signal_connect (factory, "bind", G_CALLBACK (bind_list_item), NULL);
-  listview = gtk_list_view_new_with_factory (NULL, factory);
+  listview = gtk_list_view_new (NULL, factory);
 
   gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
 
diff --git a/tests/testlistview.c b/tests/testlistview.c
index fcbac01e3c..53234078b5 100644
--- a/tests/testlistview.c
+++ b/tests/testlistview.c
@@ -615,7 +615,7 @@ main (int argc, char *argv[])
 
   factory = gtk_signal_list_item_factory_new ();
   g_signal_connect (factory, "setup", G_CALLBACK (setup_widget), NULL);
-  listview = gtk_list_view_new_with_factory (NULL, factory);
+  listview = gtk_list_view_new (NULL, factory);
   gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
 
   if (argc > 1)


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