[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: Thu, 15 Dec 2016 16:47:22 +0000 (UTC)
commit ff6be74f8cd8107d1356e32bd32dc511571420b7
Author: Carlos Soriano <csoriano gnome org>
Date: Thu Dec 15 17:46:53 2016 +0100
f
src/nautilus-view-icon-controller.c | 22 ++++-----
src/nautilus-view-icon-item-ui.c | 45 +++++++++--------
src/nautilus-view-icon-ui.c | 35 ++++++++-----
src/nautilus-view-icon-ui.h | 3 -
src/nautilus-view-item-model.c | 93 +++++++++++++++++++++++++++++++++--
src/nautilus-view-item-model.h | 16 +++++-
src/nautilus-view-model.c | 51 +++++++++++++++++++
src/nautilus-view-model.h | 4 ++
8 files changed, 212 insertions(+), 57 deletions(-)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index 5d996c4..b5f1393 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -331,26 +331,25 @@ convert_glist_to_queue (GList *list)
static void
real_set_selection (NautilusFilesView *files_view,
- GList *selection_files)
+ GList *selection)
{
- GQueue *selection_queue;
+ NautilusViewIconController *self = NAUTILUS_VIEW_ICON_CONTROLLER (files_view);
+ g_autoptr (GQueue) selection_files;
+ g_autoptr (GQueue) selection_item_models;
NautilusFile *file;
+ GList *l;
+ guint i = 0;
- for (l = selection_files; l != NULL; l = l->next)
- {
- file = NAUTILUS_FILE (l->data);
-
- gtk_flow_box_select_child (l->data);
- }
- nautilus_view_icon_ui_select_children (self->view_ui, selection_models);
+ selection_files = convert_glist_to_queue (selection);
+ selection_item_models = nautilus_view_model_get_item_models_from_files (self->model, selection_files);
+ nautilus_view_model_set_selected (self->model, selection_item_models);
nautilus_files_view_notify_selection_changed (files_view);
-
- g_queue_free (selection_queue);
}
static void
real_select_all (NautilusFilesView *files_view)
{
+ NautilusViewIconController *self = NAUTILUS_VIEW_ICON_CONTROLLER (files_view);
gtk_flow_box_select_all (GTK_FLOW_BOX (self->view_ui));
}
@@ -616,7 +615,6 @@ action_sort_order_changed (GSimpleAction *action,
const SortConstants *sorts_constants;
NautilusViewModelSortData sort_data;
NautilusViewIconController *self;
- NautilusFile *file;
// Don't resort if the action is in the same state as before
if (g_strcmp0 (g_variant_get_string (value, NULL), g_variant_get_string (g_action_get_state (G_ACTION
(action)), NULL)) == 0)
diff --git a/src/nautilus-view-icon-item-ui.c b/src/nautilus-view-icon-item-ui.c
index 13af172..dab5ac1 100644
--- a/src/nautilus-view-icon-item-ui.c
+++ b/src/nautilus-view-icon-item-ui.c
@@ -61,7 +61,7 @@ create_icon (NautilusViewIconItemUi *self)
gtk_style_context_add_class (style_context, "icon-background");
}
- gtk_box_pack_start (fixed_height_box, icon, FALSE, FALSE, 0);
+ gtk_box_pack_start (fixed_height_box, GTK_WIDGET (icon), FALSE, FALSE, 0);
return fixed_height_box;
}
@@ -70,7 +70,6 @@ static void
update_icon (NautilusViewIconItemUi *self)
{
GtkWidget *box;
- NautilusFile *file;
guint icon_size;
icon_size = nautilus_view_item_model_get_icon_size (self->model);
@@ -79,11 +78,11 @@ update_icon (NautilusViewIconItemUi *self)
box = gtk_bin_get_child (GTK_BIN (self->item_container));
if (self->icon)
{
- gtk_container_remove (GTK_CONTAINER (box), self->icon);
+ gtk_container_remove (GTK_CONTAINER (box), GTK_WIDGET (self->icon));
}
self->icon = create_icon (self);
- gtk_widget_show_all (self->icon);
- gtk_box_pack_start (box, self->icon, FALSE, FALSE, 0);
+ gtk_widget_show_all (GTK_WIDGET (self->icon));
+ gtk_box_pack_start (box, GTK_WIDGET (self->icon), FALSE, FALSE, 0);
}
static void
@@ -129,7 +128,7 @@ constructed (GObject *object)
GtkLabel *label;
GtkStyleContext *style_context;
NautilusFile *file;
- guint *icon_size;
+ guint icon_size;
G_OBJECT_CLASS (nautilus_view_icon_item_ui_parent_class)->constructed (object);
@@ -139,43 +138,45 @@ constructed (GObject *object)
self->item_container = nautilus_container_max_width_new ();
self->icon = create_icon (self);
- gtk_box_pack_start (container, self->icon, FALSE, FALSE, 0);
+ gtk_box_pack_start (container, GTK_WIDGET (self->icon), FALSE, FALSE, 0);
label = gtk_label_new (nautilus_file_get_display_name (file));
- gtk_widget_show (label);
+ gtk_widget_show (GTK_WIDGET (label));
gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
gtk_label_set_line_wrap (label, TRUE);
gtk_label_set_line_wrap_mode (label, PANGO_WRAP_WORD_CHAR);
gtk_label_set_lines (label, 4);
gtk_label_set_justify (label, GTK_JUSTIFY_CENTER);
gtk_widget_set_valign (GTK_WIDGET (label), GTK_ALIGN_START);
- gtk_box_pack_end (container, label, TRUE, TRUE, 0);
+ gtk_box_pack_end (container, GTK_WIDGET (label), TRUE, TRUE, 0);
- style_context = gtk_widget_get_style_context (container);
+ style_context = gtk_widget_get_style_context (GTK_WIDGET (container));
gtk_style_context_add_class (style_context, "icon-item-background");
- gtk_widget_set_valign (container, GTK_ALIGN_START);
- gtk_widget_set_halign (container, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (GTK_WIDGET (container), GTK_ALIGN_START);
+ gtk_widget_set_halign (GTK_WIDGET (container), GTK_ALIGN_CENTER);
- gtk_container_add (self->item_container, container);
+ gtk_container_add (GTK_CONTAINER (self->item_container),
+ GTK_WIDGET (container));
nautilus_container_max_width_set_max_width (NAUTILUS_CONTAINER_MAX_WIDTH (self->item_container),
icon_size);
- gtk_container_add (GTK_CONTAINER (self), self->item_container);
- gtk_widget_show_all (self->item_container);
+ gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->item_container));
+ gtk_widget_show_all (GTK_WIDGET (self->item_container));
g_signal_connect (self->model, "notify::icon-size",
- on_view_item_size_changed, self);
+ (GCallback) on_view_item_size_changed, self);
g_signal_connect (self->model, "notify::file",
- on_view_item_file_changed, self);
+ (GCallback) on_view_item_file_changed, self);
}
static void
finalize (GObject *object)
{
- NautilusViewIconItemUi *self = (NautilusViewIconItemUi *)object;
+ NautilusViewIconItemUi *self = (NautilusViewIconItemUi *)object;
- G_OBJECT_CLASS (nautilus_view_icon_item_ui_parent_class)->finalize (object);
+ g_signal_handlers_disconnect_by_data (self->model, self);
+ G_OBJECT_CLASS (nautilus_view_icon_item_ui_parent_class)->finalize (object);
}
static void
@@ -207,9 +208,9 @@ set_model (NautilusViewIconItemUi *self,
static void
set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
NautilusViewIconItemUi *self = NAUTILUS_VIEW_ICON_ITEM_UI (object);
diff --git a/src/nautilus-view-icon-ui.c b/src/nautilus-view-icon-ui.c
index e3255ec..fa4960b 100644
--- a/src/nautilus-view-icon-ui.c
+++ b/src/nautilus-view-icon-ui.c
@@ -97,16 +97,38 @@ set_property (GObject *object,
}
}
+static void
+on_view_item_model_selected_changed (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ NautilusViewIconItemUi *self = NAUTILUS_VIEW_ICON_ITEM_UI (user_data);
+ NautilusViewItemModel *item_model;
+ GtkFlowBoxChild *item_ui;
+
+ g_print ("selected changed\n", self->selected, !!selected);
+
+ item_model = NAUTILUS_VIEW_ITEM_MODEL (object);
+ item_ui = GTK_FLOW_BOX_CHILD (nautilus_view_item_model_get_item_ui (item_model));
+ gtk_flow_box_select_child (GTK_FLOW_BOX (self), item_ui);
+}
+
+
static GtkWidget *
create_widget_func (gpointer item,
gpointer user_data)
{
+ NautilusViewIconUi *self = NAUTILUS_VIEW_ICON_UI (user_data);
NautilusViewItemModel *item_model = NAUTILUS_VIEW_ITEM_MODEL (item);
NautilusViewIconItemUi *child;
child = nautilus_view_icon_item_ui_new (item_model);
+ nautilus_view_item_model_set_item_ui (item_model, child);
gtk_widget_show (GTK_WIDGET (child));
+ g_signal_connect (item_model, "notify::selected",
+ (GCallback) on_view_item_model_selected_changed, self);
+
return GTK_WIDGET (child);
}
@@ -193,16 +215,3 @@ nautilus_view_icon_ui_new (NautilusViewIconController *controller)
NULL);
}
-void
-nautilus_view_icon_ui_select_children (NautilusViewIconUi *self,
- GQueue *files)
-{
- GList *l;
- NautilusFile *file;
-
- for (l = g_queue_peek_head_link (files); l != NULL; l = l->next)
- {
- file = NAUTILUS_FILE (l->data);
- gtk_flow_box_select_child (l->data);
- }
-}
diff --git a/src/nautilus-view-icon-ui.h b/src/nautilus-view-icon-ui.h
index be87b84..5361acc 100644
--- a/src/nautilus-view-icon-ui.h
+++ b/src/nautilus-view-icon-ui.h
@@ -31,9 +31,6 @@ G_DECLARE_FINAL_TYPE (NautilusViewIconUi, nautilus_view_icon_ui, NAUTILUS, VIEW_
NautilusViewIconUi * nautilus_view_icon_ui_new (NautilusViewIconController *controller);
-void nautilus_view_icon_ui_select_children (NautilusViewIconUi *self,
- GQueue *queue);
-
G_END_DECLS
#endif /* NAUTILUS_VIEW_ICON_UI_H */
diff --git a/src/nautilus-view-item-model.c b/src/nautilus-view-item-model.c
index 22f3b80..08664aa 100644
--- a/src/nautilus-view-item-model.c
+++ b/src/nautilus-view-item-model.c
@@ -7,6 +7,8 @@ struct _NautilusViewItemModel
guint icon_size;
NautilusFile *file;
GtkLabel *label;
+ gboolean selected;
+ GtkWidget *item_ui;
};
G_DEFINE_TYPE (NautilusViewItemModel, nautilus_view_item_model, G_TYPE_OBJECT)
@@ -16,6 +18,8 @@ enum
PROP_0,
PROP_FILE,
PROP_ICON_SIZE,
+ PROP_SELECTED,
+ PROP_ITEM_UI,
N_PROPS
};
@@ -27,9 +31,9 @@ nautilus_view_item_model_finalize (GObject *object)
static void
nautilus_view_item_model_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
NautilusViewItemModel *self = NAUTILUS_VIEW_ITEM_MODEL (object);
@@ -47,6 +51,18 @@ nautilus_view_item_model_get_property (GObject *object,
}
break;
+ case PROP_SELECTED:
+ {
+ g_value_set_boolean (value, self->selected);
+ }
+ break;
+
+ case PROP_ITEM_UI:
+ {
+ g_value_set_object (value, self->item_ui);
+ }
+ break;
+
default:
{
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -76,6 +92,18 @@ nautilus_view_item_model_set_property (GObject *object,
}
break;
+ case PROP_SELECTED:
+ {
+ nautilus_view_item_model_set_selected (self, g_value_get_boolean (value));
+ }
+ break;
+
+ case PROP_ITEM_UI:
+ {
+ nautilus_view_item_model_set_item_ui (self, g_value_get_object (value));
+ }
+ break;
+
default:
{
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -113,11 +141,26 @@ nautilus_view_item_model_class_init (NautilusViewItemModelClass *klass)
"The file the icon item represents",
NAUTILUS_TYPE_FILE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_object_class_install_property (object_class,
+ PROP_SELECTED,
+ g_param_spec_boolean ("selected",
+ "Selected",
+ "Sets the item as selected",
+ FALSE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_ITEM_UI,
+ g_param_spec_object ("item-ui",
+ "Item ui",
+ "The UI that reprensents the item model",
+ GTK_TYPE_WIDGET,
+ G_PARAM_READWRITE));
}
NautilusViewItemModel *
nautilus_view_item_model_new (NautilusFile *file,
- guint icon_size)
+ guint icon_size)
{
return g_object_new (NAUTILUS_TYPE_VIEW_ITEM_MODEL,
"file", file,
@@ -163,3 +206,45 @@ nautilus_view_item_model_set_file (NautilusViewItemModel *self,
g_object_notify (G_OBJECT (self), "file");
}
+
+gboolean
+nautilus_view_item_model_get_is_selected (NautilusViewItemModel *self)
+{
+ g_return_val_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self), NULL);
+
+ return self->selected;
+}
+
+void
+nautilus_view_item_model_set_selected (NautilusViewItemModel *self,
+ gboolean selected)
+{
+ g_return_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self));
+
+ g_print ("item model set selected %d %d\n", self->selected, !!selected);
+ if (self->selected != !!selected)
+ {
+ self->selected = !!selected;
+ g_object_notify (G_OBJECT (self), "selected");
+ }
+}
+
+GtkWidget *
+nautilus_view_item_model_get_item_ui (NautilusViewItemModel *self)
+{
+ g_return_val_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self), NULL);
+
+ return self->item_ui;
+}
+
+void
+nautilus_view_item_model_set_item_ui (NautilusViewItemModel *self,
+ GtkWidget *item_ui)
+{
+ g_return_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self));
+
+ g_clear_object (&self->item_ui);
+ self->item_ui = g_object_ref (item_ui);
+
+ g_object_notify (G_OBJECT (self), "item-ui");
+}
diff --git a/src/nautilus-view-item-model.h b/src/nautilus-view-item-model.h
index 71558a5..39a8bc0 100644
--- a/src/nautilus-view-item-model.h
+++ b/src/nautilus-view-item-model.h
@@ -15,15 +15,25 @@ G_DECLARE_FINAL_TYPE (NautilusViewItemModel, nautilus_view_item_model, NAUTILUS,
NautilusViewItemModel * nautilus_view_item_model_new (NautilusFile *file,
guint icon_size);
-void nautilus_view_item_model_set_icon_size (NautilusViewItemModel *item,
+void nautilus_view_item_model_set_icon_size (NautilusViewItemModel *self,
guint icon_size);
guint nautilus_view_item_model_get_icon_size (NautilusViewItemModel *self);
-void nautilus_view_item_model_set_file (NautilusViewItemModel *item,
+void nautilus_view_item_model_set_file (NautilusViewItemModel *self,
NautilusFile *file);
-NautilusFile * nautilus_view_item_model_get_file (NautilusViewItemModel *item);
+NautilusFile * nautilus_view_item_model_get_file (NautilusViewItemModel *self);
+
+void nautilus_view_item_model_set_selected (NautilusViewItemModel *self,
+ gboolean selected);
+
+gboolean nautilus_view_item_model_get_is_selected (NautilusViewItemModel *self);
+
+void nautilus_view_item_model_set_item_ui (NautilusViewItemModel *self,
+ GtkWidget *item_ui);
+
+GtkWidget * nautilus_view_item_model_get_item_ui (NautilusViewItemModel *self);
G_END_DECLS
diff --git a/src/nautilus-view-model.c b/src/nautilus-view-model.c
index ec0d8f7..7d7afd6 100644
--- a/src/nautilus-view-model.c
+++ b/src/nautilus-view-model.c
@@ -149,3 +149,54 @@ nautilus_view_model_get_g_model (NautilusViewModel *self)
{
return self->internal_model;
}
+
+GQueue *
+nautilus_view_model_get_item_models_from_files (NautilusViewModel *self,
+ GQueue *files)
+{
+ GList *l;
+ gint *i;
+ NautilusViewItemModel *item_model;
+ GQueue *item_models;
+
+ item_models = g_queue_new ();
+ for (l = g_queue_peek_head_link (files); l != NULL; l = l->next)
+ {
+ NautilusFile *file1;
+
+ file1 = NAUTILUS_FILE (l->data);
+ while ((item_model = g_list_model_get_item (self->internal_model, i)))
+ {
+ NautilusFile *file2;
+ g_autofree gchar *file1_uri;
+ g_autofree gchar *file2_uri;
+
+ file2 = nautilus_view_item_model_get_file (item_model);
+ file1_uri = nautilus_file_get_uri (file1);
+ file2_uri = nautilus_file_get_uri (file2);
+ if (g_strcmp0 (file1_uri, file2_uri) == 0)
+ {
+ g_queue_push_tail (item_models, item_model);
+ break;
+ }
+ }
+ }
+
+ return item_models;
+}
+
+void
+nautilus_view_model_set_selected (NautilusViewModel *self,
+ GQueue *item_models)
+{
+ GList *l;
+
+ g_print ("set selected\n");
+ for (l = g_queue_peek_head_link (item_models); l != NULL; l = l->next)
+ {
+ NautilusViewItemModel *item_model;
+
+ item_model = NAUTILUS_VIEW_ITEM_MODEL (l->data);
+ nautilus_view_item_model_set_selected (item_model, TRUE);
+ }
+}
diff --git a/src/nautilus-view-model.h b/src/nautilus-view-model.h
index 2d6aaed..3490b9a 100644
--- a/src/nautilus-view-model.h
+++ b/src/nautilus-view-model.h
@@ -23,6 +23,10 @@ void nautilus_view_model_set_sort_type (NautilusViewModel *self,
NautilusViewModelSortData *sort_data);
GListStore * nautilus_view_model_get_g_model (NautilusViewModel *self);
+GQueue * nautilus_view_model_get_item_models_from_files (NautilusViewModel *self,
+ GQueue *files);
+void nautilus_view_model_set_selected (NautilusViewModel *self,
+ GQueue *item_models);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]