[nautilus/wip/csoriano/dnd: 8/9] dnd: use sidebar show drop targets



commit 7dd2c7b25e4956f0a16453da3df17242ae812406
Author: Carlos Soriano <csoriano gnome org>
Date:   Fri Sep 25 09:19:43 2015 +0200

    dnd: use sidebar show drop targets
    
    Currently the dnd on the sidebar is only trigered when hovering
    above the sidebar itself. However we would like to give some
    feedback all along on the dnd operation.
    For that GtkPlacesSidebar has set_drop_targets_visible public API,
    which was implemnted a few months ago and the GtkFileChooser is
    already using.
    
    I just forgot to implement the support for it on Nautilus... but
    of course all the work was done for Nautilus, since users will probably
    use dnd more on nautilus than on the file chooser.

 libnautilus-private/nautilus-canvas-dnd.c |   10 ++-
 libnautilus-private/nautilus-dnd.c        |  138 +++++++++++++++++++++++++++++
 libnautilus-private/nautilus-dnd.h        |    4 +
 src/nautilus-window.c                     |   21 ++++-
 src/nautilus-window.h                     |    4 +
 5 files changed, 175 insertions(+), 2 deletions(-)
---
diff --git a/libnautilus-private/nautilus-canvas-dnd.c b/libnautilus-private/nautilus-canvas-dnd.c
index b4da369..a035ef9 100644
--- a/libnautilus-private/nautilus-canvas-dnd.c
+++ b/libnautilus-private/nautilus-canvas-dnd.c
@@ -32,6 +32,8 @@
 
 #include <config.h>
 #include <math.h>
+#include <src/nautilus-window.h>
+
 #include "nautilus-canvas-dnd.h"
 
 #include "nautilus-file-dnd.h"
@@ -528,12 +530,16 @@ drag_end_callback (GtkWidget *widget,
 {
        NautilusCanvasContainer *container;
        NautilusCanvasDndInfo *dnd_info;
+        NautilusWindow *window;
 
        container = NAUTILUS_CANVAS_CONTAINER (widget);
+        window = NAUTILUS_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (container)));
        dnd_info = container->details->dnd_info;
 
        nautilus_drag_destroy_selection_list (dnd_info->drag_info.selection_list);
        dnd_info->drag_info.selection_list = NULL;
+
+        nautilus_window_end_dnd (window, context);
 }
 
 static NautilusCanvasIcon *
@@ -1258,12 +1264,14 @@ drag_begin_callback (GtkWidget      *widget,
 {
        NautilusCanvasContainer *container;
        NautilusDragInfo *drag_info;
+        NautilusWindow *window;
        cairo_surface_t *surface;
        double x1, y1, x2, y2, winx, winy;
        int x_offset, y_offset;
        int start_x, start_y;
 
        container = NAUTILUS_CANVAS_CONTAINER (widget);
+        window = NAUTILUS_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (container)));
 
        start_x = container->details->dnd_info->drag_info.start_x +
                gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
@@ -1289,7 +1297,7 @@ drag_begin_callback (GtkWidget      *widget,
        drag_info = &(container->details->dnd_info->drag_info);
        drag_info->selection_cache = nautilus_drag_create_selection_cache (widget,
                                                                           each_icon_get_data_binder);
-
+        nautilus_window_start_dnd (window, context);
 }
 
 void
diff --git a/libnautilus-private/nautilus-dnd.c b/libnautilus-private/nautilus-dnd.c
index 694f295..788b04a 100644
--- a/libnautilus-private/nautilus-dnd.c
+++ b/libnautilus-private/nautilus-dnd.c
@@ -382,6 +382,137 @@ source_is_deletable (GFile *file)
 }
 
 void
+nautilus_drag_sidebar_default_drop_action_for_icons (GdkDragContext *context,
+                                            const char *target_uri_string, const GList *items,
+                                            int *action)
+{
+       gboolean same_fs;
+       gboolean target_is_source_parent;
+       gboolean source_deletable;
+       const char *dropped_uri;
+       GFile *target, *dropped, *dropped_directory;
+       GdkDragAction actions;
+       NautilusFile *dropped_file, *target_file;
+
+        g_print ("default %d\n", gdk_drag_context_get_suggested_action (context));
+       if (target_uri_string == NULL) {
+        g_print ("uri null\n");
+               *action = 0;
+               return;
+       }
+
+       actions = gdk_drag_context_get_actions (context) & (GDK_ACTION_MOVE | GDK_ACTION_COPY);
+       if (actions == 0) {
+        g_print ("actions 0\n");
+                /* We can't use copy or move, just go with the suggested action. */
+               *action = gdk_drag_context_get_suggested_action (context);
+               return;
+       }
+
+       if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_ASK) {
+        g_print ("ask\n");
+               /* Don't override ask */
+               *action = gdk_drag_context_get_suggested_action (context);
+               return;
+       }
+
+       dropped_uri = ((NautilusDragSelectionItem *)items->data)->uri;
+       dropped_file = ((NautilusDragSelectionItem *)items->data)->file;
+       target_file = nautilus_file_get_existing_by_uri (target_uri_string);
+
+        g_print ("hey 1\n");
+       if (eel_uri_is_desktop (dropped_uri) &&
+           !eel_uri_is_desktop (target_uri_string)) {
+               /* Desktop items only move on the desktop */
+               *action = 0;
+               return;
+       }
+
+       /*
+        * Check for trash URI.  We do a find_directory for any Trash directory.
+        * Passing 0 permissions as gnome-vfs would override the permissions
+        * passed with 700 while creating .Trash directory
+        */
+       if (eel_uri_is_trash (target_uri_string)) {
+               /* Only move to Trash */
+               if (actions & GDK_ACTION_MOVE) {
+                       *action = GDK_ACTION_MOVE;
+               }
+               nautilus_file_unref (target_file);
+               return;
+
+       } else if (dropped_file != NULL && nautilus_file_is_launcher (dropped_file)) {
+               if (actions & GDK_ACTION_MOVE) {
+                       *action = GDK_ACTION_MOVE;
+               }
+               nautilus_file_unref (target_file);
+               return;
+       } else if (eel_uri_is_desktop (target_uri_string)) {
+               target = nautilus_get_desktop_location ();
+
+               nautilus_file_unref (target_file);
+               target_file = nautilus_file_get (target);
+
+               if (eel_uri_is_desktop (dropped_uri)) {
+                       /* Only move to Desktop icons */
+                       if (actions & GDK_ACTION_MOVE) {
+                               *action = GDK_ACTION_MOVE;
+                       }
+
+                       g_object_unref (target);
+                       nautilus_file_unref (target_file);
+                       return;
+               }
+       } else if (target_file != NULL && nautilus_file_is_archive (target_file)) {
+               *action = GDK_ACTION_COPY;
+
+               nautilus_file_unref (target_file);
+               return;
+       } else {
+               target = g_file_new_for_uri (target_uri_string);
+       }
+
+        g_print ("hey 2\n");
+       same_fs = check_same_fs (target_file, dropped_file);
+
+       nautilus_file_unref (target_file);
+
+       /* Compare the first dropped uri with the target uri for same fs match. */
+       dropped = g_file_new_for_uri (dropped_uri);
+       dropped_directory = g_file_get_parent (dropped);
+       target_is_source_parent = FALSE;
+       if (dropped_directory != NULL) {
+               /* If the dropped file is already in the same directory but
+                  is in another filesystem we still want to move, not copy
+                  as this is then just a move of a mountpoint to another
+                  position in the dir */
+               target_is_source_parent = g_file_equal (dropped_directory, target);
+               g_object_unref (dropped_directory);
+       }
+       source_deletable = source_is_deletable (dropped);
+
+       if ((same_fs && source_deletable) || target_is_source_parent ||
+           g_file_has_uri_scheme (dropped, "trash")) {
+               if (actions & GDK_ACTION_MOVE) {
+                       *action = GDK_ACTION_MOVE;
+               } else {
+                       *action = gdk_drag_context_get_suggested_action (context);
+               }
+       } else {
+               if (actions & GDK_ACTION_COPY) {
+                       *action = GDK_ACTION_COPY;
+               } else {
+                       *action = gdk_drag_context_get_suggested_action (context);
+               }
+       }
+        g_print ("hey 3 %d\n", *action);
+
+       g_object_unref (target);
+       g_object_unref (dropped);
+
+}
+
+void
 nautilus_drag_default_drop_action_for_icons (GdkDragContext *context,
                                             const char *target_uri_string, const GList *items,
                                             int *action)
@@ -394,19 +525,23 @@ nautilus_drag_default_drop_action_for_icons (GdkDragContext *context,
        GdkDragAction actions;
        NautilusFile *dropped_file, *target_file;
 
+        g_print ("default %d\n", gdk_drag_context_get_suggested_action (context));
        if (target_uri_string == NULL) {
+        g_print ("uri null\n");
                *action = 0;
                return;
        }
 
        actions = gdk_drag_context_get_actions (context) & (GDK_ACTION_MOVE | GDK_ACTION_COPY);
        if (actions == 0) {
+        g_print ("actions 0\n");
                 /* We can't use copy or move, just go with the suggested action. */
                *action = gdk_drag_context_get_suggested_action (context);
                return;
        }
 
        if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_ASK) {
+        g_print ("ask\n");
                /* Don't override ask */
                *action = gdk_drag_context_get_suggested_action (context);
                return;
@@ -416,6 +551,7 @@ nautilus_drag_default_drop_action_for_icons (GdkDragContext *context,
        dropped_file = ((NautilusDragSelectionItem *)items->data)->file;
        target_file = nautilus_file_get_existing_by_uri (target_uri_string);
 
+        g_print ("hey 1\n");
        if (eel_uri_is_desktop (dropped_uri) &&
            !eel_uri_is_desktop (target_uri_string)) {
                /* Desktop items only move on the desktop */
@@ -467,6 +603,7 @@ nautilus_drag_default_drop_action_for_icons (GdkDragContext *context,
                target = g_file_new_for_uri (target_uri_string);
        }
 
+        g_print ("hey 2\n");
        same_fs = check_same_fs (target_file, dropped_file);
 
        nautilus_file_unref (target_file);
@@ -499,6 +636,7 @@ nautilus_drag_default_drop_action_for_icons (GdkDragContext *context,
                        *action = gdk_drag_context_get_suggested_action (context);
                }
        }
+        g_print ("hey 3 %d\n", *action);
 
        g_object_unref (target);
        g_object_unref (dropped);
diff --git a/libnautilus-private/nautilus-dnd.h b/libnautilus-private/nautilus-dnd.h
index 2b343ce..c62d828 100644
--- a/libnautilus-private/nautilus-dnd.h
+++ b/libnautilus-private/nautilus-dnd.h
@@ -117,6 +117,10 @@ gboolean               nautilus_drag_items_local                   (const char           
                *target_uri,
 gboolean                   nautilus_drag_uris_local                    (const char                           
*target_uri,
                                                                         const GList                          
*source_uri_list);
 gboolean                   nautilus_drag_items_on_desktop              (const GList                          
*selection_list);
+void                       nautilus_drag_sidebar_default_drop_action_for_icons (GdkDragContext               
        *context,
+                                                                        const char                           
*target_uri,
+                                                                        const GList                          
*items,
+                                                                        int                                  
*action);
 void                       nautilus_drag_default_drop_action_for_icons (GdkDragContext                       
*context,
                                                                         const char                           
*target_uri,
                                                                         const GList                          
*items,
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index da28b52..b171f7e 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -977,6 +977,24 @@ build_selection_list_from_gfile_list (GList *gfile_list)
        return g_list_reverse (result);
 }
 
+void
+nautilus_window_start_dnd (NautilusWindow *window,
+                           GdkDragContext *context)
+{
+        gtk_places_sidebar_set_drop_targets_visible (GTK_PLACES_SIDEBAR (window->priv->places_sidebar),
+                                                     TRUE,
+                                                     context);
+}
+
+void
+nautilus_window_end_dnd (NautilusWindow *window,
+                         GdkDragContext *context)
+{
+        gtk_places_sidebar_set_drop_targets_visible (GTK_PLACES_SIDEBAR (window->priv->places_sidebar),
+                                                     FALSE,
+                                                     context);
+}
+
 /* Callback used when the places sidebar needs to know the drag action to suggest */
 static GdkDragAction
 places_sidebar_drag_action_requested_cb (GtkPlacesSidebar *sidebar,
@@ -992,7 +1010,8 @@ places_sidebar_drag_action_requested_cb (GtkPlacesSidebar *sidebar,
        items = build_selection_list_from_gfile_list (source_file_list);
        uri = g_file_get_uri (dest_file);
 
-       nautilus_drag_default_drop_action_for_icons (context, uri, items, &action);
+       nautilus_drag_sidebar_default_drop_action_for_icons (context, uri, items, &action);
+        g_print ("action %d %s\n", action, uri);
 
        nautilus_drag_destroy_selection_list (items);
        g_free (uri);
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index d9b0b24..8ba877b 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -145,4 +145,8 @@ void nautilus_window_sync_title            (NautilusWindow *window,
 void nautilus_window_show_operation_notification (NautilusWindow *window,
                                                   gchar          *main_label,
                                                   GFile          *folder_to_open);
+void nautilus_window_start_dnd (NautilusWindow *window,
+                                GdkDragContext *context);
+void nautilus_window_end_dnd (NautilusWindow *window,
+                              GdkDragContext *context);
 #endif


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