[nautilus/wip/csoriano/flow] f
- From: Carlos Soriano <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/csoriano/flow] f
- Date: Wed, 18 Jan 2017 15:30:42 +0000 (UTC)
commit bfd0912401bdfd679b271dc635f813fec789c665
Author: Carlos Soriano <csoriano gnome org>
Date: Wed Jan 18 16:30:25 2017 +0100
f
src/nautilus-view-icon-controller.c | 19 ++++++++-
src/nautilus-view-item-model.c | 2 +-
src/nautilus-view-model.c | 76 ++++++++++++++++++++++++++++++++---
src/nautilus-view-model.h | 15 ++++---
4 files changed, 97 insertions(+), 15 deletions(-)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index 87e4368..56e6a79 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -253,11 +253,23 @@ real_clear (NautilusFilesView *files_view)
}
+/* FIXME: ideally this should go into the model so there is not need to
+ * recreate the model with the new data */
static void
real_file_changed (NautilusFilesView *files_view,
NautilusFile *file,
NautilusDirectory *directory)
{
+ NautilusViewIconController *self;
+ NautilusViewItemModel *item_model;
+ NautilusViewItemModel *new_item_model;
+
+ self = NAUTILUS_VIEW_ICON_CONTROLLER (files_view);
+ item_model = nautilus_view_model_get_item_from_file (self->model, file);
+ nautilus_view_model_remove_item (self->model, item_model);
+ new_item_model = nautilus_view_item_model_new (file,
+ get_icon_size_for_zoom_level (self->zoom_level));
+ nautilus_view_model_add_item (self->model, item_model);
}
static GList *
@@ -364,7 +376,7 @@ real_set_selection (NautilusFilesView *files_view,
g_autoptr (GQueue) selection_item_models = NULL;
selection_files = convert_glist_to_queue (selection);
- selection_item_models = nautilus_view_model_get_item_models_from_files (self->model, selection_files);
+ selection_item_models = nautilus_view_model_get_items_from_files (self->model, selection_files);
nautilus_view_model_set_selected (self->model, selection_item_models);
nautilus_files_view_notify_selection_changed (files_view);
}
@@ -575,9 +587,11 @@ on_button_press_event (GtkWidget *widget,
gpointer user_data)
{
NautilusViewIconController *self;
+ GList *selection;
self = NAUTILUS_VIEW_ICON_CONTROLLER (user_data);
+ selection = nautilus_files_view_get_selection (NAUTILUS_FILES_VIEW (self));
nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (self),
(GdkEventButton *) event);
return FALSE;
@@ -779,7 +793,7 @@ constructed (GObject *object)
view_icon_actions,
G_N_ELEMENTS (view_icon_actions),
self);
- self->zoom_level = get_default_zoom_level (self);
+ self->zoom_level = get_default_zoom_level ();
/* Keep the action synced with the actual value, so the toolbar can poll it */
g_action_group_change_action_state (nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (self)),
"zoom-to-level", g_variant_new_int32 (self->zoom_level));
@@ -822,6 +836,7 @@ nautilus_view_icon_controller_class_init (NautilusViewIconControllerClass *klass
files_view_class->select_first = real_select_first;
files_view_class->restore_standard_zoom_level = real_restore_standard_zoom_level;
files_view_class->get_zoom_level_percentage = real_get_zoom_level_percentage;
+ files_view_class->compute_rename_popover_pointing_to = real_compute_rename_popover_pointing_to;
}
static void
diff --git a/src/nautilus-view-item-model.c b/src/nautilus-view-item-model.c
index 632404b..daf9afc 100644
--- a/src/nautilus-view-item-model.c
+++ b/src/nautilus-view-item-model.c
@@ -210,7 +210,7 @@ nautilus_view_item_model_set_file (NautilusViewItemModel *self,
gboolean
nautilus_view_item_model_get_is_selected (NautilusViewItemModel *self)
{
- g_return_val_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self), FALSE);
return self->selected;
}
diff --git a/src/nautilus-view-model.c b/src/nautilus-view-model.c
index d3f2ca3..4df9406 100644
--- a/src/nautilus-view-model.c
+++ b/src/nautilus-view-model.c
@@ -4,10 +4,11 @@
struct _NautilusViewModel
{
- GObject parent_instance;
+ GObject parent_instance;
- GListStore *internal_model;
- NautilusViewModelSortData *sort_data;
+ GHashTable *map_files_to_model;
+ GListStore *internal_model;
+ NautilusViewModelSortData *sort_data;
};
G_DEFINE_TYPE (NautilusViewModel, nautilus_view_model, G_TYPE_OBJECT)
@@ -22,7 +23,16 @@ enum {
static void
finalize (GObject *object)
{
+ NautilusViewModel *self = NAUTILUS_VIEW_MODEL (object);
+
G_OBJECT_CLASS (nautilus_view_model_parent_class)->finalize (object);
+
+ g_hash_table_destroy (self->map_files_to_model);
+ if (self->sort_data)
+ {
+ g_free (self->sort_data);
+ }
+ g_object_unref (self->internal_model);
}
static void
@@ -85,6 +95,7 @@ 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->map_files_to_model = g_hash_table_new (NULL, NULL);
}
static void
@@ -157,8 +168,8 @@ nautilus_view_model_get_g_model (NautilusViewModel *self)
}
GQueue *
-nautilus_view_model_get_item_models_from_files (NautilusViewModel *self,
- GQueue *files)
+nautilus_view_model_get_items_from_files (NautilusViewModel *self,
+ GQueue *files)
{
GList *l;
NautilusViewItemModel *item_model;
@@ -193,6 +204,45 @@ nautilus_view_model_get_item_models_from_files (NautilusViewModel *self,
return item_models;
}
+NautilusViewItemModel *
+nautilus_view_model_get_item_from_file (NautilusViewModel *self,
+ NautilusFile *file)
+{
+ return g_hash_table_lookup (self->map_files_to_model, file);
+}
+
+void
+nautilus_view_model_remove_item (NautilusViewModel *self,
+ NautilusViewItemModel *item)
+{
+ NautilusViewItemModel *item_model;
+ gint i;
+
+ i = 0;
+ item_model = NULL;
+ while ((item_model = g_list_model_get_item (G_LIST_MODEL(self->internal_model), i)))
+ {
+ if (item_model == item)
+ {
+ break;
+ }
+
+ i++;
+ }
+
+ if (item_model != NULL)
+ {
+ g_list_store_remove (self->internal_model, i);
+ }
+}
+
+void
+nautilus_view_model_add_item (NautilusViewModel *self,
+ NautilusViewItemModel *item)
+{
+ g_list_store_insert_sorted (self->internal_model, item, compare_data_func, self);
+}
+
void
nautilus_view_model_set_selected (NautilusViewModel *self,
GQueue *item_models)
@@ -273,8 +323,22 @@ nautilus_view_model_set_items (NautilusViewModel *self,
{
g_autofree gpointer *array = NULL;
+ GList *l;
+ int i = 0;
+
+ array = g_malloc_n (g_queue_get_length (items),
+ sizeof (NautilusViewItemModel *));
+
+ g_hash_table_remove_all (self->map_files_to_model);
+ for (l = g_queue_peek_head_link (items); l != NULL; l = l->next)
+ {
+ array[i] = l->data;
+ g_hash_table_insert (self->map_files_to_model,
+ nautilus_view_item_model_get_file (l->data),
+ l->data);
+ i++;
+ }
- array = convert_gqueue_to_array (self, items);
g_list_store_splice (self->internal_model,
g_list_model_get_n_items (G_LIST_MODEL (self->internal_model)),
0, array, g_queue_get_length (items));
diff --git a/src/nautilus-view-model.h b/src/nautilus-view-model.h
index ed20f04..9734032 100644
--- a/src/nautilus-view-model.h
+++ b/src/nautilus-view-model.h
@@ -3,6 +3,7 @@
#include <glib.h>
#include "nautilus-file.h"
+#include "nautilus-view-item-model.h"
G_BEGIN_DECLS
@@ -22,18 +23,20 @@ NautilusViewModel * nautilus_view_model_new (void);
void nautilus_view_model_set_sort_type (NautilusViewModel *self,
NautilusViewModelSortData *sort_data);
NautilusViewModelSortData * nautilus_view_model_get_sort_type (NautilusViewModel *self);
-
GListStore * nautilus_view_model_get_g_model (NautilusViewModel *self);
-GQueue * nautilus_view_model_get_item_models_from_files (NautilusViewModel *self,
- GQueue *files);
-
+NautilusViewItemModel * nautilus_view_model_get_item_from_file (NautilusViewModel *self,
+ NautilusFile *file);
+GQueue * nautilus_view_model_get_items_from_files (NautilusViewModel *self,
+ GQueue *files);
+void nautilus_view_model_remove_item (NautilusViewModel *self,
+ NautilusViewItemModel *item);
+void nautilus_view_model_add_item (NautilusViewModel *self,
+ NautilusViewItemModel *item);
void nautilus_view_model_set_selected (NautilusViewModel *self,
GQueue *item_models);
GQueue * nautilus_view_model_get_selected (NautilusViewModel *self);
-
void nautilus_view_model_set_items (NautilusViewModel *self,
GQueue *items);
-
G_END_DECLS
#endif /* NAUTILUS_VIEW_MODEL_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]