Merge branch 'listview-constructors' into 'master'

list widgets: Simplify the constructors

See merge request GNOME/gtk!2515
This commit is contained in:
Benjamin Otte 2020-09-01 16:42:09 +00:00
commit 133a9a6784
16 changed files with 27 additions and 89 deletions

View File

@ -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.

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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))));

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -1179,50 +1179,22 @@ 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,
gtk_grid_view_new (GtkSelectionModel *model,
GtkListItemFactory *factory)
{
GtkWidget *result;

View File

@ -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

View File

@ -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,50 +934,22 @@ 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,
gtk_list_view_new (GtkSelectionModel *model,
GtkListItemFactory *factory)
{
GtkWidget *result;

View File

@ -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

View File

@ -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);

View File

@ -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 ();

View File

@ -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);

View File

@ -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)