Compare commits

..

2 Commits

Author SHA1 Message Date
Matthias Clasen
58b34f1990 Add an example using GtkApplicationList 2020-07-26 08:38:32 -04:00
Matthias Clasen
3dce8cda54 Add GtkApplicationList 2020-07-25 19:10:38 -04:00
53 changed files with 494 additions and 145 deletions

View File

@@ -174,25 +174,28 @@ constraint_view_init (ConstraintView *self)
manager = gtk_constraint_layout_new ();
gtk_widget_set_layout_manager (GTK_WIDGET (self), manager);
guides = gtk_constraint_layout_observe_guides (GTK_CONSTRAINT_LAYOUT (manager));
all_children = gtk_widget_observe_children (GTK_WIDGET (self));
all_constraints = gtk_constraint_layout_observe_constraints (GTK_CONSTRAINT_LAYOUT (manager));
guides = gtk_constraint_layout_observe_guides (GTK_CONSTRAINT_LAYOUT (manager));
filter = gtk_custom_filter_new (omit_internal, NULL, NULL);
constraints = (GListModel *)gtk_filter_list_model_new (all_constraints, filter);
all_children = gtk_widget_observe_children (GTK_WIDGET (self));
g_object_unref (filter);
filter = gtk_custom_filter_new (omit_internal, NULL, NULL);
children = (GListModel *)gtk_filter_list_model_new (all_children, filter);
g_object_unref (filter);
list = g_list_store_new (G_TYPE_LIST_MODEL);
g_list_store_append (list, children);
g_list_store_append (list, guides);
g_list_store_append (list, constraints);
self->model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (list)));
g_object_unref (children);
g_object_unref (guides);
g_object_unref (constraints);
g_object_unref (all_children);
g_object_unref (all_constraints);
g_object_unref (list);
self->model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (list)));
controller = (GtkEventController *)gtk_gesture_drag_new ();
g_signal_connect (controller, "drag-begin", G_CALLBACK (drag_begin), self);

View File

@@ -242,11 +242,16 @@ transform_settings_to_keys (GBinding *binding,
g_object_unref (settings);
sort_model = gtk_sort_list_model_new (G_LIST_MODEL (store),
g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (data))));
gtk_column_view_get_sorter (GTK_COLUMN_VIEW (data)));
g_object_unref (store);
filter = gtk_string_filter_new (gtk_property_expression_new (SETTINGS_TYPE_KEY, NULL, "name"));
g_set_object (&current_filter, filter);
filter_model = gtk_filter_list_model_new (G_LIST_MODEL (sort_model), filter);
g_object_unref (sort_model);
g_set_object (&current_filter, filter);
g_object_unref (filter);
selection_model = gtk_no_selection_new (G_LIST_MODEL (filter_model));
g_object_unref (filter_model);
@@ -398,8 +403,8 @@ do_listview_settings (GtkWidget *do_widget)
g_object_unref (actions);
model = create_settings_model (NULL, NULL);
treemodel = gtk_tree_list_model_new (model,
FALSE,
treemodel = gtk_tree_list_model_new (FALSE,
model,
TRUE,
create_settings_model,
NULL,
@@ -414,6 +419,7 @@ do_listview_settings (GtkWidget *do_widget)
gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection));
g_object_unref (selection);
g_object_unref (treemodel);
g_object_unref (model);
name_column = GTK_COLUMN_VIEW_COLUMN (gtk_builder_get_object (builder, "name_column"));
sorter = gtk_string_sorter_new (gtk_property_expression_new (SETTINGS_TYPE_KEY, NULL, "name"));

View File

@@ -1136,8 +1136,8 @@ activate (GApplication *app)
g_signal_connect (search_bar, "notify::search-mode-enabled", G_CALLBACK (clear_search), NULL);
listmodel = create_demo_model ();
treemodel = gtk_tree_list_model_new (G_LIST_MODEL (listmodel),
FALSE,
treemodel = gtk_tree_list_model_new (FALSE,
G_LIST_MODEL (listmodel),
TRUE,
get_child_model,
NULL,
@@ -1145,7 +1145,6 @@ activate (GApplication *app)
filter_model = gtk_filter_list_model_new (G_LIST_MODEL (treemodel), NULL);
filter = gtk_custom_filter_new ((GtkCustomFilterFunc)demo_filter_by_name, filter_model, NULL);
gtk_filter_list_model_set_filter (filter_model, filter);
g_object_unref (filter);
search_entry = GTK_WIDGET (gtk_builder_get_object (builder, "search-entry"));
g_signal_connect (search_entry, "search-changed", G_CALLBACK (demo_search_changed_cb), filter);

View File

@@ -76,6 +76,7 @@
<xi:include href="xml/gtkmultiselection.xml" />
</section>
<xi:include href="xml/gtkselectionfiltermodel.xml" />
<xi:include href="xml/gtkapplicationlist.xml" />
<xi:include href="xml/gtkbookmarklist.xml" />
<xi:include href="xml/gtkdirectorylist.xml" />
<xi:include href="xml/gtkstringlist.xml" />

View File

@@ -7639,3 +7639,10 @@ gtk_selection_filter_model_new_for_type
gtk_selection_filter_model_set_model
gtk_selection_filter_model_get_model
</SECTION>
<SECTION>
<FILE>gtkapplicationlist</FILE>
<TITLE>GtkApplicationList</TITLE>
GtkApplicationList
gtk_application_list_new
</SECTION>

View File

@@ -13,6 +13,7 @@ gtk_app_chooser_button_get_type
gtk_app_chooser_dialog_get_type
gtk_app_chooser_widget_get_type
gtk_application_get_type
gtk_application_list_get_type
gtk_application_window_get_type
gtk_aspect_frame_get_type
gtk_assistant_get_type

View File

@@ -43,6 +43,7 @@
#include <gtk/gtkappchooserwidget.h>
#include <gtk/gtkappchooserbutton.h>
#include <gtk/gtkapplication.h>
#include <gtk/gtkapplicationlist.h>
#include <gtk/gtkapplicationwindow.h>
#include <gtk/gtkaspectframe.h>
#include <gtk/gtkassistant.h>

163
gtk/gtkapplicationlist.c Normal file
View File

@@ -0,0 +1,163 @@
/*
* Copyright © 2020 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Matthias Clasen <mclasen@redhat.com>
*/
#include "config.h"
#include "gtkapplicationlist.h"
#include "gtksettings.h"
#include "gtkintl.h"
#include "gtkprivate.h"
/**
* SECTION:gtkapplicationlist
* @title: GtkApplicationList
* @short_description: A list model for applications
* @see_also: #GListModel, #GAppInfo
*
* #GtkApplicationList is a list model that wraps #GAppInfo.
* It presents a #GListModel and fills it with the #GAppInfos for
* the available applications.
*
* The #GtkApplicationList is monitoring for changes and emits
* #GListModel::items-changed when the list of applications changes.
*/
struct _GtkApplicationList
{
GObject parent_instance;
GAppInfoMonitor *monitor;
GSequence *items;
};
struct _GtkApplicationListClass
{
GObjectClass parent_class;
};
static GType
gtk_application_list_get_item_type (GListModel *list)
{
return G_TYPE_APP_INFO;
}
static guint
gtk_application_list_get_n_items (GListModel *list)
{
GtkApplicationList *self = GTK_APPLICATION_LIST (list);
return g_sequence_get_length (self->items);
}
static gpointer
gtk_application_list_get_item (GListModel *list,
guint position)
{
GtkApplicationList *self = GTK_APPLICATION_LIST (list);
GSequenceIter *iter;
iter = g_sequence_get_iter_at_pos (self->items, position);
if (g_sequence_iter_is_end (iter))
return NULL;
else
return g_object_ref (g_sequence_get (iter));
}
static void
gtk_application_list_model_init (GListModelInterface *iface)
{
iface->get_item_type = gtk_application_list_get_item_type;
iface->get_n_items = gtk_application_list_get_n_items;
iface->get_item = gtk_application_list_get_item;
}
G_DEFINE_TYPE_WITH_CODE (GtkApplicationList, gtk_application_list, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_application_list_model_init))
static void
apps_changed (GAppInfoMonitor *monitor,
GtkApplicationList *self)
{
guint before;
guint after;
GList *apps, *l;
before = g_sequence_get_length (self->items);
if (before > 0)
g_sequence_remove_range (g_sequence_get_begin_iter (self->items),
g_sequence_get_end_iter (self->items));
apps = g_app_info_get_all ();
for (l = apps; l; l = l->next)
{
GAppInfo *info = l->data;
g_sequence_append (self->items, g_object_ref (info));
}
g_list_free_full (apps, g_object_unref);
after = g_sequence_get_length (self->items);
g_list_model_items_changed (G_LIST_MODEL (self), 0, before, after);
}
static void
gtk_application_list_dispose (GObject *object)
{
GtkApplicationList *self = GTK_APPLICATION_LIST (object);
g_clear_pointer (&self->items, g_sequence_free);
g_signal_handlers_disconnect_by_func (self->monitor, G_CALLBACK (apps_changed), self);
g_clear_object (&self->monitor);
G_OBJECT_CLASS (gtk_application_list_parent_class)->dispose (object);
}
static void
gtk_application_list_class_init (GtkApplicationListClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
gobject_class->dispose = gtk_application_list_dispose;
}
static void
gtk_application_list_init (GtkApplicationList *self)
{
self->items = g_sequence_new (g_object_unref);
self->monitor = g_app_info_monitor_get ();
g_signal_connect (self->monitor, "changed", G_CALLBACK (apps_changed), self);
apps_changed (self->monitor, self);
}
/**
* gtk_application_list_new:
*
* Creates a new #GtkApplicationList.
*
* Returns: a new #GtkApplicationList
**/
GtkApplicationList *
gtk_application_list_new (void)
{
return g_object_new (GTK_TYPE_APPLICATION_LIST, NULL);
}

45
gtk/gtkapplicationlist.h Normal file
View File

@@ -0,0 +1,45 @@
/*
* Copyright © 2020 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Matthias Clasen <mclasen@redhat.com>
*/
#ifndef __GTK_APPLICATION_LIST_H__
#define __GTK_APPLICATION_LIST_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gio/gio.h>
/* for GDK_AVAILABLE_IN_ALL */
#include <gdk/gdk.h>
G_BEGIN_DECLS
#define GTK_TYPE_APPLICATION_LIST (gtk_application_list_get_type ())
GDK_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (GtkApplicationList, gtk_application_list, GTK, APPLICATION_LIST, GObject)
GDK_AVAILABLE_IN_ALL
GtkApplicationList * gtk_application_list_new (void);
G_END_DECLS
#endif /* __GTK_APPLICATION_LIST_H__ */

View File

@@ -1500,8 +1500,8 @@ gtk_column_view_get_list_view (GtkColumnView *self)
* |[
* gtk_column_view_column_set_sorter (column, sorter);
* gtk_column_view_append_column (view, column);
* sorter = g_object_ref (gtk_column_view_get_sorter (view)));
* model = gtk_sort_list_model_new (store, sorter);
* model = gtk_sort_list_model_new (store,
* gtk_column_view_get_sorter (view));
* selection = gtk_no_selection_new (model);
* gtk_column_view_set_model (view, selection);
* ]|

View File

@@ -322,9 +322,12 @@ gtk_custom_paper_unix_dialog_init (GtkCustomPaperUnixDialog *dialog)
g_object_unref (printer_list);
full_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (printer_list_list)));
g_object_unref (printer_list_list);
filter = gtk_custom_filter_new (match_func, NULL, NULL);
dialog->printer_list = G_LIST_MODEL (gtk_filter_list_model_new (full_list, filter));
g_object_unref (full_list);
g_object_unref (filter);
dialog->custom_paper_list = g_list_store_new (GTK_TYPE_PAGE_SETUP);
gtk_print_load_custom_papers (dialog->custom_paper_list);

View File

@@ -666,7 +666,7 @@ gtk_drop_down_set_model (GtkDropDown *self,
GListModel *filter_model;
GListModel *selection;
filter_model = G_LIST_MODEL (gtk_filter_list_model_new (g_object_ref (model), NULL));
filter_model = G_LIST_MODEL (gtk_filter_list_model_new (model, NULL));
g_set_object (&self->filter_model, filter_model);
g_object_unref (filter_model);

View File

@@ -614,8 +614,8 @@ gtk_filter_list_model_init (GtkFilterListModel *self)
/**
* gtk_filter_list_model_new:
* @model: (allow-none) (transfer full): the model to sort, or %NULL
* @filter: (allow-none) (transfer full): filter or %NULL to not filter items
* @model: (allow-none): the model to sort
* @filter: (allow-none): filter or %NULL to not filter items
*
* Creates a new #GtkFilterListModel that will filter @model using the given
* @filter.
@@ -636,10 +636,6 @@ gtk_filter_list_model_new (GListModel *model,
"filter", filter,
NULL);
/* consume the references */
g_clear_object (&model);
g_clear_object (&filter);
return result;
}

View File

@@ -425,7 +425,7 @@ gtk_flatten_list_model_init (GtkFlattenListModel *self)
/**
* gtk_flatten_list_model_new:
* @model: (nullable) (transfer full): the model to be flattened
* @model: (nullable) (transfer none): the model to be flattened
*
* Creates a new #GtkFlattenListModel that flattens @list.
*
@@ -442,9 +442,6 @@ gtk_flatten_list_model_new (GListModel *model)
"model", model,
NULL);
/* we consume the reference */
g_clear_object (&model);
return result;
}

View File

@@ -784,7 +784,7 @@ update_fontlist (GtkFontChooserWidget *self)
if ((self->level & GTK_FONT_CHOOSER_LEVEL_STYLE) == 0)
model = g_object_ref (G_LIST_MODEL (fontmap));
else
model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (g_object_ref (fontmap))));
model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (fontmap)));
gtk_filter_list_model_set_model (self->filter_model, model);
g_object_unref (model);
}

View File

@@ -36,6 +36,7 @@ struct _GtkListListModel
{
GObject parent_instance;
GType item_type;
guint n_items;
gpointer (* get_first) (gpointer);
gpointer (* get_next) (gpointer, gpointer);
@@ -54,7 +55,9 @@ struct _GtkListListModelClass
static GType
gtk_list_list_model_get_item_type (GListModel *list)
{
return G_TYPE_OBJECT;
GtkListListModel *self = GTK_LIST_LIST_MODEL (list);
return self->item_type;
}
static guint
@@ -140,7 +143,8 @@ gtk_list_list_model_init (GtkListListModel *self)
}
GtkListListModel *
gtk_list_list_model_new (gpointer (* get_first) (gpointer),
gtk_list_list_model_new (GType item_type,
gpointer (* get_first) (gpointer),
gpointer (* get_next) (gpointer, gpointer),
gpointer (* get_previous) (gpointer, gpointer),
gpointer (* get_last) (gpointer),
@@ -157,7 +161,8 @@ gtk_list_list_model_new (gpointer (* get_first) (gpointer),
item = get_next (item, data))
n_items++;
return gtk_list_list_model_new_with_size (n_items,
return gtk_list_list_model_new_with_size (item_type,
n_items,
get_first,
get_next,
get_previous,
@@ -168,7 +173,8 @@ gtk_list_list_model_new (gpointer (* get_first) (gpointer),
}
GtkListListModel *
gtk_list_list_model_new_with_size (guint n_items,
gtk_list_list_model_new_with_size (GType item_type,
guint n_items,
gpointer (* get_first) (gpointer),
gpointer (* get_next) (gpointer, gpointer),
gpointer (* get_previous) (gpointer, gpointer),
@@ -179,6 +185,7 @@ gtk_list_list_model_new_with_size (guint n_items,
{
GtkListListModel *result;
g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
g_return_val_if_fail (get_first != NULL, NULL);
g_return_val_if_fail (get_next != NULL, NULL);
g_return_val_if_fail (get_previous != NULL, NULL);
@@ -186,6 +193,7 @@ gtk_list_list_model_new_with_size (guint n_items,
result = g_object_new (GTK_TYPE_LIST_LIST_MODEL, NULL);
result->item_type = item_type;
result->n_items = n_items;
result->get_first = get_first;
result->get_next = get_next;

View File

@@ -37,7 +37,8 @@ typedef struct _GtkListListModelClass GtkListListModelClass;
GType gtk_list_list_model_get_type (void) G_GNUC_CONST;
GtkListListModel * gtk_list_list_model_new (gpointer (* get_first) (gpointer),
GtkListListModel * gtk_list_list_model_new (GType item_type,
gpointer (* get_first) (gpointer),
gpointer (* get_next) (gpointer, gpointer),
gpointer (* get_previous) (gpointer, gpointer),
gpointer (* get_last) (gpointer),
@@ -45,7 +46,8 @@ GtkListListModel * gtk_list_list_model_new (gpointer
gpointer data,
GDestroyNotify notify);
GtkListListModel * gtk_list_list_model_new_with_size (guint n_items,
GtkListListModel * gtk_list_list_model_new_with_size (GType item_type,
guint n_items,
gpointer (* get_first) (gpointer),
gpointer (* get_next) (gpointer, gpointer),
gpointer (* get_previous) (gpointer, gpointer),

View File

@@ -412,7 +412,7 @@ gtk_map_list_model_augment (GtkRbTree *map,
/**
* gtk_map_list_model_new:
* @model: (transfer full) (allow-none): The model to map or %NULL for none
* @model: (allow-none): The model to map or %NULL for none
* @map_func: (allow-none): map function or %NULL to not map items
* @user_data: (closure): user data passed to @map_func
* @user_destroy: destroy notifier for @user_data
@@ -435,9 +435,6 @@ gtk_map_list_model_new (GListModel *model,
"model", model,
NULL);
/* consume the reference */
g_clear_object (&model);
if (map_func)
gtk_map_list_model_set_map_func (result, map_func, user_data, user_destroy);

View File

@@ -31,20 +31,6 @@
#include <graphene-gobject.h>
/**
* SECTION:gtkoverlaylayout
* @Title: GtkOverlayLayout
* @Short_description: Layout manager that places widgets as overlays
*
* GtkOverlayLayout is the layout manager used by #GtkOverlay.
* It places widgets as overlays on top of the main child.
*
* This is not a reusable layout manager, since it expects its widget
* to be a #GtkOverlay. It only listed here so that its layout
* properties get documented.
*/
struct _GtkOverlayLayout
{
GtkLayoutManager parent_instance;

View File

@@ -308,6 +308,7 @@ gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog)
g_list_store_append (store, dialog->manage_papers_list);
paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (store)));
gtk_drop_down_set_model (GTK_DROP_DOWN (dialog->paper_size_combo), paper_size_list);
g_object_unref (store);
g_object_unref (paper_size_list);
/* Do this in code, we want the translatable strings without the markup */
@@ -324,6 +325,8 @@ gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog)
filter = gtk_custom_filter_new (match_func, NULL, NULL);
dialog->printer_list = G_LIST_MODEL (gtk_filter_list_model_new (full_list, filter));
g_object_unref (full_list);
g_object_unref (filter);
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_printer_item), dialog);

View File

@@ -807,12 +807,14 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
g_list_store_append (store, dialog->manage_papers_list);
paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (store)));
gtk_drop_down_set_model (GTK_DROP_DOWN (dialog->paper_size_combo), paper_size_list);
g_object_unref (store);
g_object_unref (paper_size_list);
/* Load backends */
model = load_print_backends (dialog);
sorter = gtk_custom_sorter_new (default_printer_list_sort_func, NULL, NULL);
sorted = G_LIST_MODEL (gtk_sort_list_model_new (model, sorter));
g_object_unref (sorter);
filter = gtk_every_filter_new ();
@@ -829,6 +831,7 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
gtk_multi_filter_append (GTK_MULTI_FILTER (filter), filter1);
filtered = G_LIST_MODEL (gtk_filter_list_model_new (sorted, filter));
g_object_unref (filter);
selection = G_LIST_MODEL (gtk_single_selection_new (filtered));
gtk_single_selection_set_autoselect (GTK_SINGLE_SELECTION (selection), FALSE);
@@ -838,6 +841,7 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
g_signal_connect_swapped (selection, "notify::selected", G_CALLBACK (selected_printer_changed), dialog);
g_object_unref (selection);
g_object_unref (filtered);
g_object_unref (model);
gtk_print_load_custom_papers (dialog->custom_paper_list);
@@ -1033,6 +1037,7 @@ load_print_backends (GtkPrintUnixDialog *dialog)
{
GList *node;
GListStore *lists;
GListModel *model;
lists = g_list_store_new (G_TYPE_LIST_MODEL);
@@ -1048,7 +1053,11 @@ load_print_backends (GtkPrintUnixDialog *dialog)
g_list_store_append (lists, gtk_print_backend_get_printers (backend));
}
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (lists)));
model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (lists)));
g_object_unref (lists);
return model;
}
static void

View File

@@ -44,16 +44,21 @@ G_DEFINE_INTERFACE (GtkShortcutManager, gtk_shortcut_manager, G_TYPE_OBJECT)
void
gtk_shortcut_manager_create_controllers (GtkWidget *widget)
{
GListStore *store;
GtkFlattenListModel *model;
GtkEventController *controller;
model = gtk_flatten_list_model_new (G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER)));
store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER);
model = gtk_flatten_list_model_new (G_LIST_MODEL (store));
g_object_unref (store);
g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-bubble", model, g_object_unref);
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
gtk_event_controller_set_name (controller, "gtk-shortcut-manager-bubble");
gtk_widget_add_controller (widget, controller);
model = gtk_flatten_list_model_new (G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER)));
store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER);
model = gtk_flatten_list_model_new (G_LIST_MODEL (store));
g_object_unref (store);
g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-capture", model, g_object_unref);
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
gtk_event_controller_set_name (controller, "gtk-shortcut-manager-capture");

View File

@@ -30,12 +30,11 @@
* @short_description: A list model that presents a slice out of a larger list
* @see_also: #GListModel
*
* #GtkSliceListModel is a list model that takes a list model and presents a
* slice of that model.
* #GtkSliceListModel is a list model that takes a list model and presents a slice of
* that model.
*
* This is useful when implementing paging by setting the size to the number
* of elements per page and updating the offset whenever a different page is
* opened.
* This is useful when implementing paging by setting the size to the number of elements
* per page and updating the offset whenever a different page is opened.
*/
#define DEFAULT_SIZE 10
@@ -301,7 +300,7 @@ gtk_slice_list_model_init (GtkSliceListModel *self)
/**
* gtk_slice_list_model_new:
* @model: (transfer full) (allow-none): The model to use, or %NULL
* @model: (transfer none) (allow-none): The model to use
* @offset: the offset of the slice
* @size: maximum size of the slice
*
@@ -315,20 +314,13 @@ gtk_slice_list_model_new (GListModel *model,
guint offset,
guint size)
{
GtkSliceListModel *self;
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
self = g_object_new (GTK_TYPE_SLICE_LIST_MODEL,
return g_object_new (GTK_TYPE_SLICE_LIST_MODEL,
"model", model,
"offset", offset,
"size", size,
NULL);
/* consume the reference */
g_clear_object (&model);
return self;
}
/**

View File

@@ -828,8 +828,8 @@ gtk_sort_list_model_init (GtkSortListModel *self)
/**
* gtk_sort_list_model_new:
* @model: (allow-none) (transfer full): the model to sort, or %NULL
* @sorter: (allow-none) (transfer full): the #GtkSorter to sort @model with, or %NULL
* @model: (allow-none): the model to sort
* @sorter: (allow-none): the #GtkSorter to sort @model with
*
* Creates a new sort list model that uses the @sorter to sort @model.
*
@@ -849,10 +849,6 @@ gtk_sort_list_model_new (GListModel *model,
"sorter", sorter,
NULL);
/* consume the references */
g_clear_object (&model);
g_clear_object (&sorter);
return result;
}

View File

@@ -734,8 +734,8 @@ gtk_tree_list_model_init (GtkTreeListModel *self)
/**
* gtk_tree_list_model_new:
* @root: (transfer full): The #GListModel to use as root
* @passthrough: %TRUE to pass through items from the models
* @root: The #GListModel to use as root
* @autoexpand: %TRUE to set the autoexpand property and expand the @root model
* @create_func: Function to call to create the #GListModel for the children
* of an item
@@ -743,12 +743,12 @@ gtk_tree_list_model_init (GtkTreeListModel *self)
* @user_destroy: Function to call to free @user_data
*
* Creates a new empty #GtkTreeListModel displaying @root with all rows collapsed.
*
* Returns: a newly created #GtkTreeListModel.
*
* Returns: a newly created #GtkTreeListModel.
**/
GtkTreeListModel *
gtk_tree_list_model_new (GListModel *root,
gboolean passthrough,
gtk_tree_list_model_new (gboolean passthrough,
GListModel *root,
gboolean autoexpand,
GtkTreeListModelCreateModelFunc create_func,
gpointer user_data,
@@ -768,7 +768,7 @@ gtk_tree_list_model_new (GListModel *root,
self->user_data = user_data;
self->user_destroy = user_destroy;
gtk_tree_list_model_init_node (self, &self->root_node, root);
gtk_tree_list_model_init_node (self, &self->root_node, g_object_ref (root));
return self;
}

View File

@@ -58,8 +58,8 @@ G_DECLARE_FINAL_TYPE (GtkTreeListRow, gtk_tree_list_row, GTK, TREE_LIST_ROW, GOb
typedef GListModel * (* GtkTreeListModelCreateModelFunc) (gpointer item, gpointer user_data);
GDK_AVAILABLE_IN_ALL
GtkTreeListModel * gtk_tree_list_model_new (GListModel *root,
gboolean passthrough,
GtkTreeListModel * gtk_tree_list_model_new (gboolean passthrough,
GListModel *root,
gboolean autoexpand,
GtkTreeListModelCreateModelFunc create_func,
gpointer user_data,

View File

@@ -11535,7 +11535,8 @@ gtk_widget_observe_children (GtkWidget *widget)
if (priv->children_observer)
return g_object_ref (G_LIST_MODEL (priv->children_observer));
priv->children_observer = gtk_list_list_model_new ((gpointer) gtk_widget_get_first_child,
priv->children_observer = gtk_list_list_model_new (GTK_TYPE_WIDGET,
(gpointer) gtk_widget_get_first_child,
(gpointer) gtk_widget_get_next_sibling,
(gpointer) gtk_widget_get_prev_sibling,
(gpointer) gtk_widget_get_last_child,
@@ -11621,13 +11622,14 @@ gtk_widget_observe_controllers (GtkWidget *widget)
if (priv->controller_observer)
return g_object_ref (G_LIST_MODEL (priv->controller_observer));
priv->controller_observer = gtk_list_list_model_new (gtk_widget_controller_list_get_first,
gtk_widget_controller_list_get_next,
gtk_widget_controller_list_get_prev,
NULL,
(gpointer) g_object_ref,
widget,
gtk_widget_controller_observer_destroyed);
priv->controller_observer = gtk_list_list_model_new (GTK_TYPE_EVENT_CONTROLLER,
gtk_widget_controller_list_get_first,
gtk_widget_controller_list_get_next,
gtk_widget_controller_list_get_prev,
NULL,
(gpointer) g_object_ref,
widget,
gtk_widget_controller_observer_destroyed);
return G_LIST_MODEL (priv->controller_observer);
}

View File

@@ -46,7 +46,7 @@ struct _GtkInspectorActions
GObject *object;
GListStore *actions;
GListModel *actions;
GtkColumnViewColumn *name;
};
@@ -79,7 +79,7 @@ action_added (GObject *owner,
GtkInspectorActions *sl)
{
ActionHolder *holder = action_holder_new (owner, action_name);
g_list_store_append (sl->actions, holder);
g_list_store_append (G_LIST_STORE (sl->actions), holder);
g_object_unref (holder);
}
@@ -283,7 +283,7 @@ add_muxer (GtkInspectorActions *sl,
static gboolean
reload (GtkInspectorActions *sl)
{
g_list_store_remove_all (sl->actions);
g_list_store_remove_all (G_LIST_STORE (sl->actions));
if (GTK_IS_APPLICATION (sl->object))
{
@@ -395,9 +395,9 @@ constructed (GObject *object)
gtk_column_view_column_set_sorter (sl->name, sorter);
g_object_unref (sorter);
sl->actions = g_list_store_new (ACTION_TYPE_HOLDER);
sorted = G_LIST_MODEL (gtk_sort_list_model_new (g_object_ref (G_LIST_MODEL (sl->actions)),
g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (sl->list)))));
sl->actions = G_LIST_MODEL (g_list_store_new (ACTION_TYPE_HOLDER));
sorted = G_LIST_MODEL (gtk_sort_list_model_new (sl->actions,
gtk_column_view_get_sorter (GTK_COLUMN_VIEW (sl->list))));
model = G_LIST_MODEL (gtk_no_selection_new (sorted));
gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->list), model);
g_object_unref (sorted);

View File

@@ -244,11 +244,13 @@ gtk_inspector_controllers_set_object (GtkInspectorControllers *self,
gtk_property_lookup_list_model_set_object (self->model, object);
map_model = gtk_map_list_model_new (G_LIST_MODEL (self->model), map_to_controllers, NULL, NULL);
g_object_unref (self->model);
flatten_model = gtk_flatten_list_model_new (G_LIST_MODEL (map_model));
sorter = gtk_custom_sorter_new (compare_controllers, NULL, NULL);
sort_model = gtk_sort_list_model_new (G_LIST_MODEL (flatten_model), sorter);
g_object_unref (sorter);
gtk_list_box_bind_model (GTK_LIST_BOX (self->listbox),
G_LIST_MODEL (sort_model),
@@ -257,6 +259,8 @@ gtk_inspector_controllers_set_object (GtkInspectorControllers *self,
NULL);
g_object_unref (sort_model);
g_object_unref (flatten_model);
g_object_unref (map_model);
}
static void

View File

@@ -116,6 +116,7 @@ static GListModel *
object_tree_widget_get_children (GObject *object)
{
GtkWidget *widget = GTK_WIDGET (object);
GtkFlattenListModel *flatten;
GListStore *list;
GListModel *sublist;
@@ -129,7 +130,10 @@ object_tree_widget_get_children (GObject *object)
g_list_store_append (list, sublist);
g_object_unref (sublist);
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (list)));
flatten = gtk_flatten_list_model_new (G_LIST_MODEL (list));
g_object_unref (list);
return G_LIST_MODEL (flatten);
}
static GListModel *
@@ -207,6 +211,7 @@ list_model_for_properties (GObject *object,
const char **props)
{
GListStore *concat;
GListModel *result;
guint i;
if (props[1] == NULL)
@@ -220,7 +225,9 @@ list_model_for_properties (GObject *object,
g_object_unref (tmp);
}
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (concat)));
result = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (concat)));
g_object_unref (concat);
return result;
}
static GListModel *
@@ -303,6 +310,7 @@ object_tree_tree_view_get_children (GObject *object)
GtkTreeView *treeview = GTK_TREE_VIEW (object);
GListStore *columns, *selection, *result_list;
GListModel *props;
GtkFlattenListModel *result;
guint i;
props = list_model_for_properties (object, (const char *[2]) { "model", NULL });
@@ -322,8 +330,10 @@ object_tree_tree_view_get_children (GObject *object)
g_object_unref (selection);
g_list_store_append (result_list, columns);
g_object_unref (columns);
result = gtk_flatten_list_model_new (G_LIST_MODEL (result_list));
g_object_unref (result_list);
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list)));
return G_LIST_MODEL (result);
}
static GListModel *
@@ -331,6 +341,7 @@ object_tree_column_view_get_children (GObject *object)
{
GtkColumnView *view = GTK_COLUMN_VIEW (object);
GListStore *result_list;
GtkFlattenListModel *result;
GListModel *columns, *sublist;
result_list = g_list_store_new (G_TYPE_LIST_MODEL);
@@ -342,7 +353,10 @@ object_tree_column_view_get_children (GObject *object)
g_list_store_append (result_list, sublist);
g_object_unref (sublist);
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list)));
result = gtk_flatten_list_model_new (G_LIST_MODEL (result_list));
g_object_unref (result_list);
return G_LIST_MODEL (result);
}
static GListModel *
@@ -588,11 +602,12 @@ static GListModel *
object_get_children (GObject *object)
{
GType object_type;
GListModel *children;
GListModel *result, *children;
GListStore *result_list;
guint i;
object_type = G_OBJECT_TYPE (object);
result = NULL;
result_list = NULL;
for (i = 0; i < G_N_ELEMENTS (object_tree_class_funcs); i++)
@@ -604,17 +619,32 @@ object_get_children (GObject *object)
if (children == NULL)
continue;
if (!result_list)
result_list = g_list_store_new (G_TYPE_LIST_MODEL);
g_list_store_append (result_list, children);
g_object_unref (children);
if (result_list)
{
g_list_store_append (result_list, children);
g_object_unref (children);
}
else if (result == NULL)
{
result = children;
}
else
{
result_list = g_list_store_new (G_TYPE_LIST_MODEL);
g_list_store_append (result_list, result);
g_object_unref (result);
g_list_store_append (result_list, children);
g_object_unref (children);
}
}
if (result_list)
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list)));
else
return NULL;
{
result = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list)));
g_object_unref (result_list);
}
return result;
}
static const char *
@@ -1137,6 +1167,7 @@ create_root_model (GdkDisplay *display)
{
GtkFilter *custom_filter;
GtkFilterListModel *filter;
GtkFlattenListModel *flatten;
GListStore *list, *special;
gpointer item;
@@ -1151,13 +1182,16 @@ create_root_model (GdkDisplay *display)
g_object_unref (special);
filter = gtk_filter_list_model_new (NULL, NULL);
custom_filter = gtk_custom_filter_new (toplevel_filter_func, display, NULL);
custom_filter = gtk_custom_filter_new (toplevel_filter_func,
display, NULL);
gtk_filter_list_model_set_filter (filter, custom_filter);
gtk_filter_list_model_set_model (filter, gtk_window_get_toplevels ());
g_list_store_append (list, filter);
g_object_unref (filter);
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (list)));
flatten = gtk_flatten_list_model_new (G_LIST_MODEL (list));
g_object_unref (list);
return G_LIST_MODEL (flatten);
}
static void
@@ -1298,13 +1332,18 @@ void
gtk_inspector_object_tree_set_display (GtkInspectorObjectTree *wt,
GdkDisplay *display)
{
wt->priv->tree_model = gtk_tree_list_model_new (create_root_model (display),
FALSE,
GListModel *root_model;
root_model = create_root_model (display);
wt->priv->tree_model = gtk_tree_list_model_new (FALSE,
root_model,
FALSE,
create_model_for_object,
NULL,
NULL);
wt->priv->selection = gtk_single_selection_new (G_LIST_MODEL (wt->priv->tree_model));
g_object_unref (root_model);
gtk_column_view_set_model (GTK_COLUMN_VIEW (wt->priv->list),
G_LIST_MODEL (wt->priv->selection));
}

View File

@@ -622,7 +622,7 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
if (GTK_IS_WIDGET (object))
g_signal_connect_object (object, "destroy", G_CALLBACK (cleanup_object), pl, G_CONNECT_SWAPPED);
filtered = G_LIST_MODEL (gtk_filter_list_model_new (G_LIST_MODEL (store), g_object_ref (pl->priv->filter)));
filtered = G_LIST_MODEL (gtk_filter_list_model_new (G_LIST_MODEL (store), pl->priv->filter));
sorted = gtk_sort_list_model_new (filtered, NULL);
list = G_LIST_MODEL (gtk_no_selection_new (G_LIST_MODEL (sorted)));
@@ -634,6 +634,8 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
g_object_unref (list);
g_object_unref (sorted);
g_object_unref (filtered);
g_object_unref (store);
return TRUE;
}

View File

@@ -1234,8 +1234,8 @@ gtk_inspector_recorder_init (GtkInspectorRecorder *recorder)
NULL);
recorder->render_node_root_model = g_list_store_new (GDK_TYPE_PAINTABLE);
recorder->render_node_model = gtk_tree_list_model_new (g_object_ref (G_LIST_MODEL (recorder->render_node_root_model)),
FALSE,
recorder->render_node_model = gtk_tree_list_model_new (FALSE,
G_LIST_MODEL (recorder->render_node_root_model),
TRUE,
create_list_model_for_render_node_paintable,
NULL, NULL);

View File

@@ -692,6 +692,7 @@ static void
constructed (GObject *object)
{
GtkInspectorResourceList *rl = GTK_INSPECTOR_RESOURCE_LIST (object);
GListModel *root_model;
GListModel *sort_model;
GtkSorter *column_sorter;
GtkSorter *sorter;
@@ -701,8 +702,9 @@ constructed (GObject *object)
g_signal_connect (rl->close_details_button, "clicked",
G_CALLBACK (close_details), rl);
rl->tree_model = gtk_tree_list_model_new (load_resources (),
FALSE,
root_model = load_resources ();
rl->tree_model = gtk_tree_list_model_new (FALSE,
root_model,
FALSE,
create_model_for_object,
NULL,
@@ -710,9 +712,11 @@ constructed (GObject *object)
column_sorter = gtk_column_view_get_sorter (GTK_COLUMN_VIEW (rl->list));
sorter = gtk_tree_list_row_sorter_new (g_object_ref (column_sorter));
sort_model = G_LIST_MODEL (gtk_sort_list_model_new (g_object_ref (G_LIST_MODEL (rl->tree_model)), sorter));
sort_model = G_LIST_MODEL (gtk_sort_list_model_new (G_LIST_MODEL (rl->tree_model), sorter));
rl->selection = gtk_single_selection_new (sort_model);
g_object_unref (root_model);
g_object_unref (sort_model);
g_object_unref (sorter);
gtk_column_view_set_model (GTK_COLUMN_VIEW (rl->list), G_LIST_MODEL (rl->selection));

View File

@@ -159,6 +159,7 @@ gtk_public_sources = files([
'gtkappchooserdialog.c',
'gtkappchooserwidget.c',
'gtkapplication.c',
'gtkapplicationlist.c',
'gtkapplicationwindow.c',
'gtkaspectframe.c',
'gtkassistant.c',
@@ -446,6 +447,7 @@ gtk_public_headers = files([
'gtkappchooserdialog.h',
'gtkappchooserwidget.h',
'gtkapplication.h',
'gtkapplicationlist.h',
'gtkapplicationwindow.h',
'gtkaspectframe.h',
'gtkassistant.h',

View File

@@ -746,11 +746,12 @@ main (int argc, char *argv[])
dirmodel = create_list_model_for_directory (root);
g_object_unref (root);
}
tree = gtk_tree_list_model_new (dirmodel,
FALSE,
tree = gtk_tree_list_model_new (FALSE,
dirmodel,
TRUE,
create_list_model_for_file_info,
NULL, NULL);
g_object_unref (dirmodel);
sorter = gtk_tree_list_row_sorter_new (g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (view))));
sort = gtk_sort_list_model_new (G_LIST_MODEL (tree), sorter);
@@ -758,6 +759,7 @@ main (int argc, char *argv[])
custom_filter = gtk_custom_filter_new (match_file, g_object_ref (search_entry), g_object_unref);
filter = gtk_filter_list_model_new (G_LIST_MODEL (sort), custom_filter);
g_signal_connect (search_entry, "search-changed", G_CALLBACK (search_changed_cb), custom_filter);
g_object_unref (custom_filter);
gtk_column_view_set_model (GTK_COLUMN_VIEW (view), G_LIST_MODEL (filter));
@@ -769,6 +771,8 @@ main (int argc, char *argv[])
gtk_box_append (GTK_BOX (vbox), statusbar);
g_object_unref (filter);
g_object_unref (sort);
g_object_unref (tree);
list = gtk_list_view_new_with_factory (
gtk_builder_list_item_factory_new_from_bytes (scope, g_bytes_new_static (factory_ui, strlen (factory_ui))));

View File

@@ -431,6 +431,45 @@ selected_changed2 (GtkDropDown *dropdown,
g_object_unref (pair);
}
static void
setup_app_item (GtkSignalListItemFactory *factory,
GtkListItem *item)
{
GtkWidget *box;
GtkWidget *label;
GtkWidget *icon;
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
icon = gtk_image_new ();
gtk_box_append (GTK_BOX (box), icon);
label = gtk_label_new ("");
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_box_append (GTK_BOX (box), label);
gtk_list_item_set_child (item, box);
}
static void
bind_app_item (GtkSignalListItemFactory *factory,
GtkListItem *item)
{
GAppInfo *info;
GtkWidget *box;
GtkWidget *label;
GtkWidget *icon;
info = gtk_list_item_get_item (item);
box = gtk_list_item_get_child (item);
icon = gtk_widget_get_first_child (box);
label = gtk_widget_get_next_sibling (icon);
gtk_image_set_from_gicon (GTK_IMAGE (icon), g_app_info_get_icon (info));
gtk_label_set_label (GTK_LABEL (label), g_app_info_get_display_name (info));
}
int
main (int argc, char *argv[])
{
@@ -454,6 +493,7 @@ main (int argc, char *argv[])
GtkListItemFactory *factory;
GtkWidget *entry;
GtkWidget *hbox;
GtkApplicationList *apps;
gtk_init ();
@@ -560,6 +600,20 @@ main (int argc, char *argv[])
g_object_unref (store);
button = gtk_drop_down_new ();
apps = gtk_application_list_new ();
gtk_drop_down_set_model (GTK_DROP_DOWN (button), G_LIST_MODEL (apps));
g_object_unref (apps);
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_app_item), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_app_item), NULL);
gtk_drop_down_set_factory (GTK_DROP_DOWN (button), factory);
g_object_unref (factory);
gtk_box_append (GTK_BOX (box), button);
gtk_window_present (GTK_WINDOW (window));
while (!quit)

View File

@@ -191,8 +191,8 @@ create_child_model (gpointer item,
static GListModel *
create_tree_model (guint n, guint m)
{
return G_LIST_MODEL (gtk_tree_list_model_new (create_model (0, n, m, TRUE),
FALSE,
return G_LIST_MODEL (gtk_tree_list_model_new (FALSE,
create_model (0, n, m, TRUE),
FALSE,
create_child_model,
GUINT_TO_POINTER (m), NULL));

View File

@@ -127,6 +127,7 @@ main (int argc,
add (store);
sorter = gtk_numeric_sorter_new (gtk_cclosure_expression_new (G_TYPE_UINT, NULL, 0, NULL, (GCallback)get_number, NULL, NULL));
sort = gtk_sort_list_model_new (G_LIST_MODEL (store), sorter);
g_object_unref (sorter);
win = gtk_window_new ();
gtk_window_set_default_size (GTK_WINDOW (win), 400, 600);
@@ -181,5 +182,7 @@ main (int argc,
while (g_list_model_get_n_items (toplevels))
g_main_context_iteration (NULL, TRUE);
g_object_unref (store);
return 0;
}

View File

@@ -318,6 +318,7 @@ get_file_path (GFileInfo *info)
static GListModel *
create_list_model_for_directory (gpointer file)
{
GtkSortListModel *sort;
GtkDirectoryList *dir;
GtkSorter *sorter;
@@ -326,8 +327,12 @@ create_list_model_for_directory (gpointer file)
dir = create_directory_list (file);
sorter = gtk_string_sorter_new (gtk_cclosure_expression_new (G_TYPE_STRING, NULL, 0, NULL, (GCallback) get_file_path, NULL, NULL));
sort = gtk_sort_list_model_new (G_LIST_MODEL (dir), sorter);
return G_LIST_MODEL (gtk_sort_list_model_new (G_LIST_MODEL (dir), sorter));
g_object_unref (sorter);
g_object_unref (dir);
return G_LIST_MODEL (sort);
}
typedef struct _RowData RowData;
@@ -589,6 +594,7 @@ int
main (int argc, char *argv[])
{
GtkWidget *win, *vbox, *sw, *listview, *search_entry, *statusbar;
GListModel *dirmodel;
GtkTreeListModel *tree;
GtkFilterListModel *filter;
GtkFilter *custom_filter;
@@ -622,16 +628,19 @@ main (int argc, char *argv[])
root = g_file_new_for_commandline_arg (argv[1]);
else
root = g_file_new_for_path (g_get_current_dir ());
tree = gtk_tree_list_model_new (create_list_model_for_directory (root),
FALSE,
dirmodel = create_list_model_for_directory (root);
tree = gtk_tree_list_model_new (FALSE,
dirmodel,
TRUE,
create_list_model_for_file_info,
NULL, NULL);
g_object_unref (dirmodel);
g_object_unref (root);
custom_filter = gtk_custom_filter_new (match_file, search_entry, NULL);
filter = gtk_filter_list_model_new (G_LIST_MODEL (tree), custom_filter);
g_signal_connect (search_entry, "search-changed", G_CALLBACK (search_changed_cb), custom_filter);
g_object_unref (custom_filter);
selectionmodel = file_info_selection_new (G_LIST_MODEL (filter));
g_object_unref (filter);
@@ -645,6 +654,7 @@ main (int argc, char *argv[])
update_statusbar (GTK_STATUSBAR (statusbar));
gtk_box_append (GTK_BOX (vbox), statusbar);
g_object_unref (tree);
g_object_unref (selectionmodel);
gtk_widget_show (win);

View File

@@ -262,6 +262,8 @@ test_nested (void)
g_assert_cmpint (counter, ==, 0);
g_object_unref (filtered);
g_object_unref (list);
g_object_unref (filter);
gtk_expression_unref (expr);
}

View File

@@ -189,7 +189,7 @@ new_model (guint size,
{
GtkFilterListModel *result;
result = gtk_filter_list_model_new (g_object_ref (G_LIST_MODEL (new_store (1, size, 1))), g_object_ref (filter));
result = gtk_filter_list_model_new (G_LIST_MODEL (new_store (1, size, 1)), filter);
return result;
}

View File

@@ -135,10 +135,6 @@ filter_list_model_new (GListModel *source,
GListStore *check;
guint i;
if (source)
g_object_ref (source);
if (filter)
g_object_ref (filter);
model = gtk_filter_list_model_new (source, filter);
check = g_list_store_new (G_TYPE_OBJECT);
for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (model)); i++)
@@ -447,6 +443,8 @@ test_model_changes (gconstpointer model_id)
g_object_unref (model2);
g_object_unref (flatten2);
g_object_unref (flatten1);
g_object_unref (store2);
g_object_unref (store1);
g_object_unref (multi);
}

View File

@@ -167,7 +167,8 @@ new_model (guint size,
filter = gtk_custom_filter_new (filter_func, data, NULL);
else
filter = NULL;
result = gtk_filter_list_model_new (g_object_ref (G_LIST_MODEL (new_store (1, size, 1))), filter);
result = gtk_filter_list_model_new (G_LIST_MODEL (new_store (1, size, 1)), filter);
g_clear_object (&filter);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);

View File

@@ -210,7 +210,7 @@ new_model (GListStore *store)
GtkFlattenListModel *result;
GString *changes;
result = gtk_flatten_list_model_new (g_object_ref (G_LIST_MODEL (store)));
result = gtk_flatten_list_model_new (G_LIST_MODEL (store));
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);

View File

@@ -196,7 +196,7 @@ new_model (GListStore *store)
GtkMapListModel *result;
GString *changes;
result = gtk_map_list_model_new (g_object_ref (G_LIST_MODEL (store)), map_multiply, GUINT_TO_POINTER (2), NULL);
result = gtk_map_list_model_new (G_LIST_MODEL (store), map_multiply, GUINT_TO_POINTER (2), NULL);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);

View File

@@ -627,7 +627,7 @@ test_set_model (void)
store = new_store (1, 5, 1);
m1 = G_LIST_MODEL (store);
m2 = G_LIST_MODEL (gtk_slice_list_model_new (g_object_ref (m1), 0, 3));
m2 = G_LIST_MODEL (gtk_slice_list_model_new (m1, 0, 3));
selection = new_model (store);
assert_selection (selection, "");
assert_selection_changes (selection, "");

View File

@@ -653,7 +653,7 @@ test_set_model (void)
store = new_store (1, 5, 1);
m1 = G_LIST_MODEL (store);
m2 = G_LIST_MODEL (gtk_slice_list_model_new (g_object_ref (m1), 0, 3));
m2 = G_LIST_MODEL (gtk_slice_list_model_new (m1, 0, 3));
selection = new_model (store, TRUE, TRUE);
assert_selection (selection, "1");
assert_selection_changes (selection, "");

View File

@@ -191,7 +191,7 @@ new_model (GListStore *store, guint offset, guint size)
GtkSliceListModel *result;
GString *changes;
result = gtk_slice_list_model_new (g_object_ref (G_LIST_MODEL (store)), offset, size);
result = gtk_slice_list_model_new (G_LIST_MODEL (store), offset, size);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);

View File

@@ -247,7 +247,7 @@ new_model (guint size,
{
GtkSortListModel *result;
result = gtk_sort_list_model_new (G_LIST_MODEL (fisher_yates_shuffle (new_store (1, size, 1))), g_object_ref (sorter));
result = gtk_sort_list_model_new (G_LIST_MODEL (fisher_yates_shuffle (new_store (1, size, 1))), sorter);
return result;
}
@@ -630,8 +630,8 @@ test_stable (void)
gtk_multi_sorter_append (GTK_MULTI_SORTER (multi), b);
model1 = new_model (20, multi);
g_object_unref (multi);
model2b = gtk_sort_list_model_new (g_object_ref (gtk_sort_list_model_get_model (model1)), b);
model2 = gtk_sort_list_model_new (g_object_ref (G_LIST_MODEL (model2b)), a);
model2b = gtk_sort_list_model_new (gtk_sort_list_model_get_model (model1), b);
model2 = gtk_sort_list_model_new (G_LIST_MODEL (model2b), a);
assert_model_equal (model1, model2);
modify_sorter (a);

View File

@@ -200,9 +200,9 @@ create_sort_list_model (gconstpointer model_id,
guint id = GPOINTER_TO_UINT (model_id);
if (track_changes)
model = sort_list_model_new (id & 1 ? NULL : g_object_ref (source), id & 2 ? NULL : g_object_ref (sorter));
model = sort_list_model_new (id & 1 ? NULL : source, id & 2 ? NULL : sorter);
else
model = gtk_sort_list_model_new (id & 1 ? NULL : g_object_ref (source), id & 2 ? NULL : g_object_ref (sorter));
model = gtk_sort_list_model_new (id & 1 ? NULL : source, id & 2 ? NULL : sorter);
switch (id >> 2)
{
@@ -433,6 +433,7 @@ test_stability (gconstpointer model_id)
g_object_unref (sort2);
g_object_unref (sort1);
g_object_unref (flatten);
g_object_unref (store);
}
static void

View File

@@ -220,7 +220,8 @@ new_model (gpointer model)
GtkSorter *sorter;
sorter = gtk_custom_sorter_new (compare, NULL, NULL);
result = gtk_sort_list_model_new (g_object_ref (model), sorter);
result = gtk_sort_list_model_new (model, sorter);
g_object_unref (sorter);
}
else
result = gtk_sort_list_model_new (NULL, NULL);

View File

@@ -170,7 +170,7 @@ new_model (guint size,
GtkTreeListModel *tree;
GString *changes;
tree = gtk_tree_list_model_new (G_LIST_MODEL (new_store (size, size, size)), TRUE, expanded, create_sub_model_cb, NULL, NULL);
tree = gtk_tree_list_model_new (TRUE, G_LIST_MODEL (new_store (size, size, size)), expanded, create_sub_model_cb, NULL, NULL);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(tree), changes_quark, changes, free_changes);
g_signal_connect (tree, "items-changed", G_CALLBACK (items_changed), changes);

View File

@@ -158,8 +158,8 @@ new_child_model (gpointer item,
static GListModel *
new_model (guint size)
{
return G_LIST_MODEL (gtk_tree_list_model_new (G_LIST_MODEL (new_store (1, size, 1)),
FALSE,
return G_LIST_MODEL (gtk_tree_list_model_new (FALSE,
G_LIST_MODEL (new_store (1, size, 1)),
TRUE,
new_child_model,
NULL, NULL));
@@ -179,7 +179,9 @@ test_simple (void)
sort = gtk_sort_list_model_new (model, sorter);
assert_model (sort, "1 2 21 3 31 32 321");
g_object_unref (sorter);
g_object_unref (sort);
g_object_unref (model);
}
static GtkSorter *