[nautilus/wip/antoniof/flowbox-to-gridview: 12/24] view-icon-controller: Get children by index from model
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/flowbox-to-gridview: 12/24] view-icon-controller: Get children by index from model
- Date: Wed, 9 Feb 2022 18:11:42 +0000 (UTC)
commit 0fb98f3c322d2723425eb2443b4ca0185096b260
Author: António Fernandes <antoniof gnome org>
Date: Mon Jan 24 10:56:13 2022 +0000
view-icon-controller: Get children by index from model
GtkGridView is going to rely more heavily on item index instead of
pointer to widget which might be recycled for another item.
src/nautilus-view-icon-controller.c | 17 +++++++++++------
src/nautilus-view-model.c | 13 +++++++++++++
src/nautilus-view-model.h | 2 ++
3 files changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index b087333b5..00539219e 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -372,10 +372,12 @@ real_set_selection (NautilusFilesView *files_view,
gtk_flow_box_unselect_all (self->view_ui);
for (GList *l = g_queue_peek_head_link (selection_item_models); l != NULL ; l = l->next)
{
- GtkWidget *item_ui;
+ guint i;
+ GtkFlowBoxChild *child;
- item_ui = nautilus_view_item_model_get_item_ui (NAUTILUS_VIEW_ITEM_MODEL (l->data));
- gtk_flow_box_select_child (self->view_ui, GTK_FLOW_BOX_CHILD (item_ui));
+ i = nautilus_view_model_get_index (self->model, l->data);
+ child = gtk_flow_box_get_child_at_index (self->view_ui, i);
+ gtk_flow_box_select_child (self->view_ui, child);
}
nautilus_files_view_notify_selection_changed (files_view);
@@ -410,6 +412,7 @@ get_first_selected_item_ui (NautilusViewIconController *self)
g_autolist (NautilusFile) selection = NULL;
NautilusFile *file;
NautilusViewItemModel *item_model;
+ guint i;
selection = nautilus_view_get_selection (NAUTILUS_VIEW (self));
if (selection == NULL)
@@ -419,8 +422,8 @@ get_first_selected_item_ui (NautilusViewIconController *self)
file = NAUTILUS_FILE (selection->data);
item_model = nautilus_view_model_get_item_from_file (self->model, file);
-
- return nautilus_view_item_model_get_item_ui (item_model);
+ i = nautilus_view_model_get_index (self->model, item_model);
+ return GTK_WIDGET (gtk_flow_box_get_child_at_index (self->view_ui, i));
}
static void
@@ -998,12 +1001,14 @@ scroll_to_file_on_idle (ScrollToFileData *data)
NautilusViewIconController *self = data->view;
g_autoptr (NautilusFile) file = NULL;
NautilusViewItemModel *item;
+ guint i;
GtkWidget *item_ui;
gdouble item_y;
file = nautilus_file_get_existing_by_uri (data->uri);
item = nautilus_view_model_get_item_from_file (self->model, file);
- item_ui = nautilus_view_item_model_get_item_ui (item);
+ i = nautilus_view_model_get_index (self->model, item);
+ item_ui = GTK_WIDGET (gtk_flow_box_get_child_at_index (self->view_ui, i));
gtk_widget_translate_coordinates (item_ui, GTK_WIDGET (self->view_ui),
0, 0,
NULL, &item_y);
diff --git a/src/nautilus-view-model.c b/src/nautilus-view-model.c
index 84c40302d..b5a704e0d 100644
--- a/src/nautilus-view-model.c
+++ b/src/nautilus-view-model.c
@@ -321,3 +321,16 @@ nautilus_view_model_add_items (NautilusViewModel *self,
g_list_store_sort (self->internal_model, compare_data_func, self);
}
+
+guint
+nautilus_view_model_get_index (NautilusViewModel *self,
+ NautilusViewItemModel *item)
+{
+ guint i = G_MAXUINT;
+ gboolean found;
+
+ found = g_list_store_find (self->internal_model, item, &i);
+ g_warn_if_fail (found);
+
+ return i;
+}
diff --git a/src/nautilus-view-model.h b/src/nautilus-view-model.h
index 11c5a0545..c32e2656e 100644
--- a/src/nautilus-view-model.h
+++ b/src/nautilus-view-model.h
@@ -35,5 +35,7 @@ void nautilus_view_model_add_item (NautilusViewModel *self,
NautilusViewItemModel *item);
void nautilus_view_model_add_items (NautilusViewModel *self,
GQueue *items);
+guint nautilus_view_model_get_index (NautilusViewModel *self,
+ NautilusViewItemModel *item);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]