[nautilus/wip/antoniof/gtk4-restore-clipboard: 2/2] view-icon-controller: Dim cut items




commit 86e3e4b2b02ced1d8e959cfa3f04893ecd9be72f
Author: António Fernandes <antoniof gnome org>
Date:   Sun Mar 27 03:08:34 2022 +0100

    view-icon-controller: Dim cut items
    
    As the canvas used to do.

 src/nautilus-view-icon-controller.c | 68 +++++++++++++++++++++++++++++++++++++
 src/nautilus-view-icon-item-ui.c    | 21 ++++++++++++
 src/nautilus-view-item-model.c      | 29 ++++++++++++++++
 src/nautilus-view-item-model.h      |  2 ++
 src/resources/css/Adwaita.css       |  4 +++
 5 files changed, 124 insertions(+)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index 8561c5106..765e1d6cc 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -7,6 +7,7 @@
 #include "nautilus-metadata.h"
 #include "nautilus-window-slot.h"
 #include "nautilus-directory.h"
+#include "nautilus-clipboard.h"
 #include "nautilus-global-preferences.h"
 #include "nautilus-thumbnails.h"
 
@@ -17,6 +18,8 @@ struct _NautilusViewIconController
     GtkGridView *view_ui;
     NautilusViewModel *model;
 
+    GList *cut_files;
+
     GIcon *view_icon;
     GActionGroup *action_group;
     gint zoom_level;
@@ -940,10 +943,65 @@ real_compare_files (NautilusFilesView *files_view,
                                            sort_constants->reversed);
 }
 
+static void
+on_clipboard_contents_received (GObject      *source_object,
+                                GAsyncResult *res,
+                                gpointer      user_data)
+{
+    NautilusFilesView *files_view = NAUTILUS_FILES_VIEW (source_object);
+    NautilusViewIconController *self = NAUTILUS_VIEW_ICON_CONTROLLER (files_view);
+    NautilusClipboard *clip;
+    NautilusViewItemModel *item;
+
+    for (GList *l = self->cut_files; l != NULL; l = l->next)
+    {
+        item = nautilus_view_model_get_item_from_file (self->model, l->data);
+        if (item != NULL)
+        {
+            nautilus_view_item_model_set_cut (item, FALSE);
+        }
+    }
+    g_clear_list (&self->cut_files, g_object_unref);
+
+    clip = nautilus_files_view_get_clipboard_finish (files_view, res, NULL);
+    if (clip != NULL && nautilus_clipboard_is_cut (clip))
+    {
+        self->cut_files = g_list_copy_deep (nautilus_clipboard_peek_files (clip),
+                                            (GCopyFunc) g_object_ref,
+                                            NULL);
+    }
+
+    for (GList *l = self->cut_files; l != NULL; l = l->next)
+    {
+        item = nautilus_view_model_get_item_from_file (self->model, l->data);
+        if (item != NULL)
+        {
+            nautilus_view_item_model_set_cut (item, TRUE);
+        }
+    }
+}
+
+static void
+update_clipboard_status (NautilusFilesView *files_view)
+{
+    nautilus_files_view_get_clipboard_async (files_view,
+                                             on_clipboard_contents_received,
+                                             NULL);
+}
+
+static void
+on_clipboard_owner_changed (GdkClipboard *clipboard,
+                            gpointer      user_data)
+{
+    update_clipboard_status (NAUTILUS_FILES_VIEW (user_data));
+}
+
+
 static void
 real_end_loading (NautilusFilesView *files_view,
                   gboolean           all_files_seen)
 {
+    update_clipboard_status (files_view);
 }
 
 static guint
@@ -1225,6 +1283,10 @@ dispose (GObject *object)
 static void
 finalize (GObject *object)
 {
+    NautilusViewIconController *self = NAUTILUS_VIEW_ICON_CONTROLLER (object);
+
+    g_clear_list (&self->cut_files, g_object_unref);
+
     G_OBJECT_CLASS (nautilus_view_icon_controller_parent_class)->finalize (object);
 }
 
@@ -1531,6 +1593,8 @@ nautilus_view_icon_controller_class_init (NautilusViewIconControllerClass *klass
 static void
 nautilus_view_icon_controller_init (NautilusViewIconController *self)
 {
+    GdkClipboard *clipboard;
+
     gtk_widget_add_css_class (GTK_WIDGET (self), "view");
     gtk_widget_add_css_class (GTK_WIDGET (self), "nautilus-grid-view");
     set_click_mode_from_settings (self);
@@ -1549,6 +1613,10 @@ nautilus_view_icon_controller_init (NautilusViewIconController *self)
                               "changed::" NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS,
                               G_CALLBACK (on_captions_preferences_changed),
                               self);
+
+    clipboard = gdk_display_get_clipboard (gdk_display_get_default ());
+    g_signal_connect_object (clipboard, "changed",
+                             G_CALLBACK (on_clipboard_owner_changed), self, 0);
 }
 
 NautilusViewIconController *
diff --git a/src/nautilus-view-icon-item-ui.c b/src/nautilus-view-icon-item-ui.c
index 4dbce7a62..d0ebff7b4 100644
--- a/src/nautilus-view-icon-item-ui.c
+++ b/src/nautilus-view-icon-item-ui.c
@@ -127,6 +127,25 @@ on_view_item_size_changed (GObject    *object,
     update_captions (self);
 }
 
+static void
+on_view_item_is_cut_changed (GObject    *object,
+                             GParamSpec *pspec,
+                             gpointer    user_data)
+{
+    NautilusViewIconItemUi *self = NAUTILUS_VIEW_ICON_ITEM_UI (user_data);
+    gboolean is_cut;
+
+    g_object_get (object, "is-cut", &is_cut, NULL);
+    if (is_cut)
+    {
+        gtk_widget_add_css_class (self->icon, "cut");
+    }
+    else
+    {
+        gtk_widget_remove_css_class (self->icon, "cut");
+    }
+}
+
 static void
 set_model (NautilusViewIconItemUi *self,
            NautilusViewItemModel  *model);
@@ -194,6 +213,8 @@ set_model (NautilusViewIconItemUi *self,
 
     g_signal_connect (self->model, "notify::icon-size",
                       (GCallback) on_view_item_size_changed, self);
+    g_signal_connect (self->model, "notify::is-cut",
+                      (GCallback) on_view_item_is_cut_changed, self);
     g_signal_connect_swapped (self->model, "file-changed",
                               (GCallback) on_file_changed, self);
 }
diff --git a/src/nautilus-view-item-model.c b/src/nautilus-view-item-model.c
index 40e3ce9f1..6cc3f54f5 100644
--- a/src/nautilus-view-item-model.c
+++ b/src/nautilus-view-item-model.c
@@ -5,6 +5,7 @@ struct _NautilusViewItemModel
 {
     GObject parent_instance;
     guint icon_size;
+    gboolean is_cut;
     NautilusFile *file;
     GtkWidget *item_ui;
 };
@@ -16,6 +17,7 @@ enum
     PROP_0,
     PROP_FILE,
     PROP_ICON_SIZE,
+    PROP_IS_CUT,
     PROP_ITEM_UI,
     N_PROPS
 };
@@ -70,6 +72,12 @@ nautilus_view_item_model_get_property (GObject    *object,
         }
         break;
 
+        case PROP_IS_CUT:
+        {
+            g_value_set_boolean (value, self->is_cut);
+        }
+        break;
+
         case PROP_ITEM_UI:
         {
             g_value_set_object (value, self->item_ui);
@@ -105,6 +113,12 @@ nautilus_view_item_model_set_property (GObject      *object,
         }
         break;
 
+        case PROP_IS_CUT:
+        {
+            self->is_cut = g_value_get_boolean (value);
+        }
+        break;
+
         case PROP_ITEM_UI:
         {
             g_set_object (&self->item_ui, g_value_get_object (value));
@@ -142,6 +156,12 @@ nautilus_view_item_model_class_init (NautilusViewItemModelClass *klass)
                                                        NAUTILUS_GRID_ICON_SIZE_LARGEST,
                                                        NAUTILUS_GRID_ICON_SIZE_LARGE,
                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+    g_object_class_install_property (object_class,
+                                     PROP_IS_CUT,
+                                     g_param_spec_boolean ("is-cut",
+                                                           "", "",
+                                                           FALSE,
+                                                           G_PARAM_READWRITE));
     g_object_class_install_property (object_class,
                                      PROP_FILE,
                                      g_param_spec_object ("file",
@@ -194,6 +214,15 @@ nautilus_view_item_model_set_icon_size (NautilusViewItemModel *self,
     g_object_set (self, "icon-size", icon_size, NULL);
 }
 
+void
+nautilus_view_item_model_set_cut (NautilusViewItemModel *self,
+                                  gboolean               is_cut)
+{
+    g_return_if_fail (NAUTILUS_IS_VIEW_ITEM_MODEL (self));
+
+    g_object_set (self, "is-cut", is_cut, NULL);
+}
+
 NautilusFile *
 nautilus_view_item_model_get_file (NautilusViewItemModel *self)
 {
diff --git a/src/nautilus-view-item-model.h b/src/nautilus-view-item-model.h
index a7986c9c3..27c4a8fd9 100644
--- a/src/nautilus-view-item-model.h
+++ b/src/nautilus-view-item-model.h
@@ -18,6 +18,8 @@ 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_cut (NautilusViewItemModel *self,
+                                       gboolean               is_cut);
 
 NautilusFile * nautilus_view_item_model_get_file (NautilusViewItemModel *self);
 
diff --git a/src/resources/css/Adwaita.css b/src/resources/css/Adwaita.css
index 8518d3df0..e84732532 100644
--- a/src/resources/css/Adwaita.css
+++ b/src/resources/css/Adwaita.css
@@ -168,3 +168,7 @@
               0px 2px 0px 0px @shade_color;
   border-radius: 2px;
 }
+
+.nautilus-grid-view .cut {
+  opacity: 0.55;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]