[nautilus/wip/antoniof/new-list-view-continuation: 137/141] view-model: Expose row objects to the view
- From: Corey Berla <coreyberla src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/new-list-view-continuation: 137/141] view-model: Expose row objects to the view
- Date: Fri, 5 Aug 2022 16:45:25 +0000 (UTC)
commit f35c49194bf574d2e0b975f142117f83e42fbc87
Author: António Fernandes <antoniof gnome org>
Date: Wed Apr 6 01:22:53 2022 +0100
view-model: Expose row objects to the view
This is going to allow us to reuse the model for a GtkColumnView-based
list view with expanding trees support.
As documented, GtkTreeViewRow:item may be NULL when the item it held
is destroyed. So, we must take care to handle the NULL case when
expected and also warn and return when not expected.
src/nautilus-grid-view.c | 11 ++++++++---
src/nautilus-list-base-private.h | 3 +++
src/nautilus-list-base.c | 13 +++++++++----
src/nautilus-list-view.c | 8 +++-----
src/nautilus-view-model.c | 8 +++-----
5 files changed, 26 insertions(+), 17 deletions(-)
---
diff --git a/src/nautilus-grid-view.c b/src/nautilus-grid-view.c
index 1e8e54569..09261a8c2 100644
--- a/src/nautilus-grid-view.c
+++ b/src/nautilus-grid-view.c
@@ -349,7 +349,8 @@ bind_cell (GtkSignalListItemFactory *factory,
NautilusViewItem *item;
cell = gtk_list_item_get_child (listitem);
- item = NAUTILUS_VIEW_ITEM (gtk_list_item_get_item (listitem));
+ item = listitem_get_view_item (listitem);
+ g_return_if_fail (item != NULL);
nautilus_view_item_set_item_ui (item, cell);
@@ -375,9 +376,13 @@ unbind_cell (GtkSignalListItemFactory *factory,
{
NautilusViewItem *item;
- item = NAUTILUS_VIEW_ITEM (gtk_list_item_get_item (listitem));
+ item = listitem_get_view_item (listitem);
- nautilus_view_item_set_item_ui (item, NULL);
+ /* item may be NULL when row has just been destroyed. */
+ if (item != NULL)
+ {
+ nautilus_view_item_set_item_ui (item, NULL);
+ }
}
static void
diff --git a/src/nautilus-list-base-private.h b/src/nautilus-list-base-private.h
index 96944d52e..c5d2ebbce 100644
--- a/src/nautilus-list-base-private.h
+++ b/src/nautilus-list-base-private.h
@@ -30,4 +30,7 @@ const NautilusFileSortType get_sorts_type_from_metadata_text (const char *m
void setup_cell_common (GtkListItem *listitem,
NautilusViewCell *cell);
+#define listitem_get_view_item(li) \
+(NAUTILUS_VIEW_ITEM (gtk_tree_list_row_get_item (GTK_TREE_LIST_ROW (gtk_list_item_get_item (li)))))
+
G_END_DECLS
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c
index 4bd754b8e..5c1bbdb0a 100644
--- a/src/nautilus-list-base.c
+++ b/src/nautilus-list-base.c
@@ -105,7 +105,10 @@ static inline NautilusViewItem *
get_view_item (GListModel *model,
guint position)
{
- return NAUTILUS_VIEW_ITEM (g_list_model_get_item (model, position));
+ g_autoptr (GtkTreeListRow) row = g_list_model_get_item (model, position);
+
+ g_return_val_if_fail (GTK_IS_TREE_LIST_ROW (row), NULL);
+ return NAUTILUS_VIEW_ITEM (gtk_tree_list_row_get_item (GTK_TREE_LIST_ROW (row)));
}
static const SortConstants *
@@ -843,12 +846,14 @@ void
setup_cell_common (GtkListItem *listitem,
NautilusViewCell *cell)
{
+ GtkExpression *expression;
GtkEventController *controller;
GtkDropTarget *drop_target;
- g_object_bind_property (listitem, "item",
- cell, "item",
- G_BINDING_SYNC_CREATE);
+ expression = gtk_property_expression_new (GTK_TYPE_LIST_ITEM, NULL, "item");
+ expression = gtk_property_expression_new (GTK_TYPE_TREE_LIST_ROW, expression, "item");
+ gtk_expression_bind (expression, cell, "item", listitem);
+
gtk_list_item_set_child (listitem, GTK_WIDGET (cell));
controller = GTK_EVENT_CONTROLLER (gtk_gesture_click_new ());
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index fb14569ec..dea71fea9 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -840,9 +840,7 @@ real_sort_directories_first_changed (NautilusFilesView *files_view)
self->directories_first = nautilus_files_view_should_sort_directories_first (NAUTILUS_FILES_VIEW (self));
- /* Reset the sorter to trigger ressorting */
- model = nautilus_list_base_get_model (NAUTILUS_LIST_BASE (self));
- nautilus_view_model_set_sorter (model, nautilus_view_model_get_sorter (model));
+ nautilus_view_model_sort (nautilus_list_base_get_model (NAUTILUS_LIST_BASE (self)));
}
static void
@@ -948,7 +946,7 @@ bind_name_cell (GtkSignalListItemFactory *factory,
{
NautilusViewItem *item;
- item = NAUTILUS_VIEW_ITEM (gtk_list_item_get_item (listitem));
+ item = listitem_get_view_item (listitem);
nautilus_view_item_set_item_ui (item, gtk_list_item_get_child (listitem));
}
@@ -960,7 +958,7 @@ unbind_name_cell (GtkSignalListItemFactory *factory,
{
NautilusViewItem *item;
- item = NAUTILUS_VIEW_ITEM (gtk_list_item_get_item (listitem));
+ item = listitem_get_view_item (listitem);
g_return_if_fail (NAUTILUS_IS_VIEW_ITEM (item));
nautilus_view_item_set_item_ui (item, NULL);
diff --git a/src/nautilus-view-model.c b/src/nautilus-view-model.c
index 53aae16ca..82692ccdd 100644
--- a/src/nautilus-view-model.c
+++ b/src/nautilus-view-model.c
@@ -49,7 +49,7 @@ get_child_row (NautilusViewModel *self,
static GType
nautilus_view_model_get_item_type (GListModel *list)
{
- return NAUTILUS_TYPE_VIEW_ITEM;
+ return GTK_TYPE_TREE_LIST_ROW;
}
static guint
@@ -70,15 +70,13 @@ nautilus_view_model_get_item (GListModel *list,
guint position)
{
NautilusViewModel *self = NAUTILUS_VIEW_MODEL (list);
- g_autoptr (GtkTreeListRow) row = NULL;
if (self->sort_model == NULL)
{
return NULL;
}
- row = g_list_model_get_item (G_LIST_MODEL (self->sort_model), position);
- return gtk_tree_list_row_get_item (row);
+ return g_list_model_get_item (G_LIST_MODEL (self->sort_model), position);
}
static void
@@ -332,7 +330,7 @@ nautilus_view_model_get_sorter (NautilusViewModel *self)
row_sorter = GTK_TREE_LIST_ROW_SORTER (gtk_sort_list_model_get_sorter (self->sort_model));
- return gtk_tree_list_row_sorter_get_sorter (row_sorter);
+ return row_sorter != NULL ? gtk_tree_list_row_sorter_get_sorter (row_sorter) : NULL;
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]