[nautilus/wip/antoniof/flowbox-to-gridview: 8/16] view-model: Implement GtkSelectionModel interface
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/flowbox-to-gridview: 8/16] view-model: Implement GtkSelectionModel interface
- Date: Mon, 7 Feb 2022 00:04:47 +0000 (UTC)
commit 456f6932430cadeb0e862b91959094fe46184669
Author: António Fernandes <antoniof gnome org>
Date: Mon Jan 31 10:27:49 2022 +0000
view-model: Implement GtkSelectionModel interface
This is a requirement for GtkGridView.
src/nautilus-view-model.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 58 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-view-model.c b/src/nautilus-view-model.c
index b5a704e0d..925e6208c 100644
--- a/src/nautilus-view-model.c
+++ b/src/nautilus-view-model.c
@@ -8,6 +8,7 @@ struct _NautilusViewModel
GHashTable *map_files_to_model;
GListStore *internal_model;
+ GtkMultiSelection *selection_model;
NautilusViewModelSortData *sort_data;
};
@@ -52,9 +53,53 @@ nautilus_view_model_list_model_init (GListModelInterface *iface)
iface->get_item = nautilus_view_model_get_item;
}
+
+static gboolean
+nautilus_view_model_is_selected (GtkSelectionModel *model,
+ guint position)
+{
+ NautilusViewModel *self = NAUTILUS_VIEW_MODEL (model);
+ GtkSelectionModel *selection_model = GTK_SELECTION_MODEL (self->selection_model);
+
+ return gtk_selection_model_is_selected (selection_model, position);
+}
+
+static GtkBitset *
+nautilus_view_model_get_selection_in_range (GtkSelectionModel *model,
+ guint pos,
+ guint n_items)
+{
+ NautilusViewModel *self = NAUTILUS_VIEW_MODEL (model);
+ GtkSelectionModel *selection_model = GTK_SELECTION_MODEL (self->selection_model);
+
+ return gtk_selection_model_get_selection_in_range (selection_model, pos, n_items);
+}
+
+static gboolean
+nautilus_view_model_set_selection (GtkSelectionModel *model,
+ GtkBitset *selected,
+ GtkBitset *mask)
+{
+ NautilusViewModel *self = NAUTILUS_VIEW_MODEL (model);
+ GtkSelectionModel *selection_model = GTK_SELECTION_MODEL (self->selection_model);
+
+ return gtk_selection_model_set_selection (selection_model, selected, mask);
+}
+
+
+static void
+nautilus_view_model_selection_model_init (GtkSelectionModelInterface *iface)
+{
+ iface->is_selected = nautilus_view_model_is_selected;
+ iface->get_selection_in_range = nautilus_view_model_get_selection_in_range;
+ iface->set_selection = nautilus_view_model_set_selection;
+}
+
G_DEFINE_TYPE_WITH_CODE (NautilusViewModel, nautilus_view_model, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL,
- nautilus_view_model_list_model_init))
+ nautilus_view_model_list_model_init)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_SELECTION_MODEL,
+ nautilus_view_model_selection_model_init))
enum
{
@@ -68,6 +113,15 @@ dispose (GObject *object)
{
NautilusViewModel *self = NAUTILUS_VIEW_MODEL (object);
+ if (self->selection_model != NULL)
+ {
+ g_signal_handlers_disconnect_by_func (self->selection_model,
+ gtk_selection_model_selection_changed,
+ self);
+ g_object_unref (self->selection_model);
+ self->selection_model = NULL;
+ }
+
if (self->internal_model != NULL)
{
g_signal_handlers_disconnect_by_func (self->internal_model,
@@ -148,10 +202,13 @@ constructed (GObject *object)
G_OBJECT_CLASS (nautilus_view_model_parent_class)->constructed (object);
self->internal_model = g_list_store_new (NAUTILUS_TYPE_VIEW_ITEM_MODEL);
+ self->selection_model = gtk_multi_selection_new (G_LIST_MODEL (self->internal_model));
self->map_files_to_model = g_hash_table_new (NULL, NULL);
g_signal_connect_swapped (self->internal_model, "items-changed",
G_CALLBACK (g_list_model_items_changed), self);
+ g_signal_connect_swapped (self->selection_model, "selection-changed",
+ G_CALLBACK (gtk_selection_model_selection_changed), self);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]