diff options
author | Dave Camp <dave@ximian.com> | 2002-07-25 20:59:17 +0000 |
---|---|---|
committer | Dave Camp <campd@src.gnome.org> | 2002-07-25 20:59:17 +0000 |
commit | 8fed4ca3ef5611d56720fecaec5fdd7d3bf47174 (patch) | |
tree | 356a6a849934e3c0b5250f552e702082cdc67eda | |
parent | c53f887dd2c5530c2b25d8e40dd1ff9d7fc7f419 (diff) | |
download | nautilus-8fed4ca3ef5611d56720fecaec5fdd7d3bf47174.tar.gz |
New functions. (create_tree): Create a NautilusTreeViewDragDest.
2002-07-25 Dave Camp <dave@ximian.com>
* components/tree/nautilus-tree-view.c: (get_root_uri_callback),
(get_file_for_path_callback), (move_copy_items_callback): New
functions.
(create_tree): Create a NautilusTreeViewDragDest.
(nautilus_tree_view_dispose): Unref the DragDest object.
(nautilus_tree_view_class_init): initialize dispose.
* libnautilus-private/Makefile.am: Build
nautilus-tree-view-drag-dest.[ch].
* libnautilus-tree-view-drag-dest.c:
* libnautilus-tree-view-drag-dest.h: New files.
* libnautilus-private/nautilus-dnd.c:
(nautilus_drag_selection_includes_special_link): Moved here
from nautilus-icon-dnd.c.
* libnautilus-private/nautilus-dnd.h: Prototype for
nautilus_drag_selection_includes_special_link.
* libnautilus-private/nautilus-file.c:
(nautilus_file_get_drop_target_uri): Moved here from
fm-directory-view.
* libnautilus-private/nautilus-file.h:
* libnautilus-private/nautilus-icon-dnd.c:
(nautilus_icon_container_receive_dropped_icons): Call
nautilus_drag_selection_includes_special_link().
* libnautilus-private/nautilus-marshal.list: New marshallers.
* src/file-manager/fm-icon-view.c:
(get_icon_drop_target_uri_callback): Use
nautilus_file_get_drop_target_uri().
* src/file-manager/fm-list-view.c: (get_root_uri_callback),
(get_file_for_path_callback), (move_copy_items_callback): New
functions.
(create_and_set_up_tree_view): Create a NautilusViewDragDest
object.
(fm_list_view_dispose): Unref the DragDest object.
-rw-r--r-- | ChangeLog | 35 | ||||
-rw-r--r-- | components/tree/nautilus-tree-view.c | 79 | ||||
-rw-r--r-- | libnautilus-private/Makefile.am | 2 | ||||
-rw-r--r-- | libnautilus-private/nautilus-dnd.c | 28 | ||||
-rw-r--r-- | libnautilus-private/nautilus-dnd.h | 1 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file.c | 25 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file.h | 2 | ||||
-rw-r--r-- | libnautilus-private/nautilus-icon-dnd.c | 30 | ||||
-rw-r--r-- | libnautilus-private/nautilus-marshal.list | 3 | ||||
-rw-r--r-- | libnautilus-private/nautilus-tree-view-drag-dest.c | 686 | ||||
-rw-r--r-- | libnautilus-private/nautilus-tree-view-drag-dest.h | 75 | ||||
-rw-r--r-- | src/file-manager/fm-icon-view.c | 24 | ||||
-rw-r--r-- | src/file-manager/fm-list-view.c | 88 |
13 files changed, 1020 insertions, 58 deletions
@@ -1,3 +1,38 @@ +2002-07-25 Dave Camp <dave@ximian.com> + + * components/tree/nautilus-tree-view.c: (get_root_uri_callback), + (get_file_for_path_callback), (move_copy_items_callback): New + functions. + (create_tree): Create a NautilusTreeViewDragDest. + (nautilus_tree_view_dispose): Unref the DragDest object. + (nautilus_tree_view_class_init): initialize dispose. + * libnautilus-private/Makefile.am: Build + nautilus-tree-view-drag-dest.[ch]. + * libnautilus-tree-view-drag-dest.c: + * libnautilus-tree-view-drag-dest.h: New files. + * libnautilus-private/nautilus-dnd.c: + (nautilus_drag_selection_includes_special_link): Moved here + from nautilus-icon-dnd.c. + * libnautilus-private/nautilus-dnd.h: Prototype for + nautilus_drag_selection_includes_special_link. + * libnautilus-private/nautilus-file.c: + (nautilus_file_get_drop_target_uri): Moved here from + fm-directory-view. + * libnautilus-private/nautilus-file.h: + * libnautilus-private/nautilus-icon-dnd.c: + (nautilus_icon_container_receive_dropped_icons): Call + nautilus_drag_selection_includes_special_link(). + * libnautilus-private/nautilus-marshal.list: New marshallers. + * src/file-manager/fm-icon-view.c: + (get_icon_drop_target_uri_callback): Use + nautilus_file_get_drop_target_uri(). + * src/file-manager/fm-list-view.c: (get_root_uri_callback), + (get_file_for_path_callback), (move_copy_items_callback): New + functions. + (create_and_set_up_tree_view): Create a NautilusViewDragDest + object. + (fm_list_view_dispose): Unref the DragDest object. + === nautilus 2.0.2 === 2002-07-25 Dave Camp <dave@ximian.com> diff --git a/components/tree/nautilus-tree-view.c b/components/tree/nautilus-tree-view.c index 990febb7e..805da7a54 100644 --- a/components/tree/nautilus-tree-view.c +++ b/components/tree/nautilus-tree-view.c @@ -44,8 +44,10 @@ #include <gtk/gtktreeview.h> #include <libgnomevfs/gnome-vfs-utils.h> #include <libnautilus-private/nautilus-file-attributes.h> +#include <libnautilus-private/nautilus-file-operations.h> #include <libnautilus-private/nautilus-global-preferences.h> #include <libnautilus-private/nautilus-program-choosing.h> +#include <libnautilus-private/nautilus-tree-view-drag-dest.h> #define NAUTILUS_PREFERENCES_TREE_VIEW_EXPANSION_STATE "tree-sidebar-panel/expansion_state" @@ -57,6 +59,8 @@ struct NautilusTreeViewDetails { NautilusFile *activation_file; GHashTable *expanded_uris; + + NautilusTreeViewDragDest *drag_dest; }; typedef struct { @@ -342,6 +346,52 @@ compare_rows (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer call return result; } + +static char * +get_root_uri_callback (NautilusTreeViewDragDest *dest, + gpointer user_data) +{ + NautilusTreeView *view; + + view = NAUTILUS_TREE_VIEW (user_data); + + return g_strdup ("file:///"); +} + +static NautilusFile * +get_file_for_path_callback (NautilusTreeViewDragDest *dest, + GtkTreePath *path, + gpointer user_data) +{ + NautilusTreeView *view; + + view = NAUTILUS_TREE_VIEW (user_data); + + return sort_model_path_to_file (view, path); +} + +static void +move_copy_items_callback (NautilusTreeViewDragDest *dest, + const GList *item_uris, + const char *target_uri, + guint action, + int x, + int y, + gpointer user_data) +{ + NautilusTreeView *view; + + view = NAUTILUS_TREE_VIEW (user_data); + + nautilus_file_operations_copy_move + (item_uris, + NULL, + target_uri, + action, + GTK_WIDGET (view->details->tree_widget), + NULL, NULL); +} + static void create_tree (NautilusTreeView *view) { @@ -369,6 +419,21 @@ create_tree (NautilusTreeView *view) g_signal_connect_object (view->details->tree_widget, "destroy", G_CALLBACK (save_expansion_state_callback), view, 0); + view->details->drag_dest = + nautilus_tree_view_drag_dest_new (view->details->tree_widget); + g_signal_connect_object (view->details->drag_dest, + "get_root_uri", + G_CALLBACK (get_root_uri_callback), + view, 0); + g_signal_connect_object (view->details->drag_dest, + "get_file_for_path", + G_CALLBACK (get_file_for_path_callback), + view, 0); + g_signal_connect_object (view->details->drag_dest, + "move_copy_items", + G_CALLBACK (move_copy_items_callback), + view, 0); + /* Create column */ column = gtk_tree_view_column_new (); @@ -468,6 +533,19 @@ nautilus_tree_view_instance_init (NautilusTreeView *view) } static void +nautilus_tree_view_dispose (GObject *object) +{ + NautilusTreeView *view; + + view = NAUTILUS_TREE_VIEW (object); + + if (view->details->drag_dest) { + g_object_unref (view->details->drag_dest); + view->details->drag_dest = NULL; + } +} + +static void nautilus_tree_view_finalize (GObject *object) { NautilusTreeView *view; @@ -491,5 +569,6 @@ nautilus_tree_view_finalize (GObject *object) static void nautilus_tree_view_class_init (NautilusTreeViewClass *class) { + G_OBJECT_CLASS (class)->dispose = nautilus_tree_view_dispose; G_OBJECT_CLASS (class)->finalize = nautilus_tree_view_finalize; } diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am index 2c77c1633..33321d639 100644 --- a/libnautilus-private/Makefile.am +++ b/libnautilus-private/Makefile.am @@ -147,6 +147,8 @@ libnautilus_private_la_SOURCES = \ nautilus-trash-file.h \ nautilus-trash-monitor.c \ nautilus-trash-monitor.h \ + nautilus-tree-view-drag-dest.c \ + nautilus-tree-view-drag-dest.h \ nautilus-undo-context.c \ nautilus-undo-context.h \ nautilus-undo-manager.c \ diff --git a/libnautilus-private/nautilus-dnd.c b/libnautilus-private/nautilus-dnd.c index 08472f622..d59389599 100644 --- a/libnautilus-private/nautilus-dnd.c +++ b/libnautilus-private/nautilus-dnd.c @@ -30,6 +30,7 @@ #include "nautilus-dnd.h" #include "nautilus-program-choosing.h" +#include "nautilus-link.h" #include <eel/eel-glib-extensions.h> #include <eel/eel-string.h> #include <eel/eel-vfs-extensions.h> @@ -731,3 +732,30 @@ nautilus_drag_autoscroll_stop (NautilusDragInfo *drag_info) drag_info->auto_scroll_timeout_id = 0; } } + +gboolean +nautilus_drag_selection_includes_special_link (GList *selection_list) +{ + GList *node; + char *uri, *local_path; + gboolean link_in_selection; + + link_in_selection = FALSE; + + for (node = selection_list; node != NULL; node = node->next) { + uri = ((NautilusDragSelectionItem *) node->data)->uri; + + /* FIXME bugzilla.gnome.org 43020: This does sync. I/O and works only locally. */ + local_path = gnome_vfs_get_local_path_from_uri (uri); + link_in_selection = local_path != NULL + && (nautilus_link_local_is_trash_link (local_path) || nautilus_link_local_is_home_link (local_path) || + nautilus_link_local_is_volume_link (local_path)); + g_free (local_path); + + if (link_in_selection) { + break; + } + } + + return link_in_selection; +} diff --git a/libnautilus-private/nautilus-dnd.h b/libnautilus-private/nautilus-dnd.h index 05f03dca9..6b46eb69a 100644 --- a/libnautilus-private/nautilus-dnd.h +++ b/libnautilus-private/nautilus-dnd.h @@ -139,5 +139,6 @@ void nautilus_drag_autoscroll_start (Nautilu gpointer user_data); void nautilus_drag_autoscroll_stop (NautilusDragInfo *drag_info); +gboolean nautilus_drag_selection_includes_special_link (GList *selection_list); #endif diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c index edbdccde1..39cb59717 100644 --- a/libnautilus-private/nautilus-file.c +++ b/libnautilus-private/nautilus-file.c @@ -2359,6 +2359,31 @@ nautilus_file_get_activation_uri (NautilusFile *file) return nautilus_file_get_uri (file); } + +char * +nautilus_file_get_drop_target_uri (NautilusFile *file) +{ + char *uri, *target_uri; + + g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL); + + uri = nautilus_file_get_uri (file); + + /* Check for Nautilus link */ + if (nautilus_file_is_nautilus_link (file)) { + /* FIXME bugzilla.gnome.org 43020: This does sync. I/O and works only locally. */ + if (!eel_vfs_has_capability (uri, EEL_VFS_CAPABILITY_IS_REMOTE_AND_SLOW)) { + target_uri = nautilus_link_local_get_link_uri (uri); + if (target_uri != NULL) { + g_free (uri); + uri = target_uri; + } + } + } + + return uri; +} + char * nautilus_file_get_custom_icon_uri (NautilusFile *file) { diff --git a/libnautilus-private/nautilus-file.h b/libnautilus-private/nautilus-file.h index b4ad72a0e..6b88c53a9 100644 --- a/libnautilus-private/nautilus-file.h +++ b/libnautilus-private/nautilus-file.h @@ -291,6 +291,8 @@ GList *nautilus_file_list_filter_hidden_and_backup (GList */ char * nautilus_file_get_activation_uri (NautilusFile *file); +char * nautilus_file_get_drop_target_uri (NautilusFile *file); + /* Get custom icon (if specified by metadata or link contents) */ char * nautilus_file_get_custom_icon_uri (NautilusFile *file); diff --git a/libnautilus-private/nautilus-icon-dnd.c b/libnautilus-private/nautilus-icon-dnd.c index ba80aee40..c876fa834 100644 --- a/libnautilus-private/nautilus-icon-dnd.c +++ b/libnautilus-private/nautilus-icon-dnd.c @@ -795,34 +795,6 @@ nautilus_icon_container_find_drop_target (NautilusIconContainer *container, return nautilus_icon_container_get_icon_drop_target_uri (container, drop_target_icon); } -/* FIXME bugzilla.gnome.org 42485: This belongs in FMDirectoryView, not here. */ -static gboolean -selection_includes_special_link (GList *selection_list) -{ - GList *node; - char *uri, *local_path; - gboolean link_in_selection; - - link_in_selection = FALSE; - - for (node = selection_list; node != NULL; node = node->next) { - uri = ((NautilusDragSelectionItem *) node->data)->uri; - - /* FIXME bugzilla.gnome.org 43020: This does sync. I/O and works only locally. */ - local_path = gnome_vfs_get_local_path_from_uri (uri); - link_in_selection = local_path != NULL - && (nautilus_link_local_is_trash_link (local_path) || nautilus_link_local_is_home_link (local_path) || - nautilus_link_local_is_volume_link (local_path)); - g_free (local_path); - - if (link_in_selection) { - break; - } - } - - return link_in_selection; -} - static gboolean selection_is_image_file (GList *selection_list) { @@ -870,7 +842,7 @@ nautilus_icon_container_receive_dropped_icons (NautilusIconContainer *container, if (context->action == GDK_ACTION_ASK) { /* FIXME bugzilla.gnome.org 42485: This belongs in FMDirectoryView, not here. */ /* Check for special case items in selection list */ - if (selection_includes_special_link (container->details->dnd_info->drag_info.selection_list)) { + if (nautilus_drag_selection_includes_special_link (container->details->dnd_info->drag_info.selection_list)) { /* We only want to move the trash */ action = GDK_ACTION_MOVE; } else { diff --git a/libnautilus-private/nautilus-marshal.list b/libnautilus-private/nautilus-marshal.list index 126de58e5..c0d617827 100644 --- a/libnautilus-private/nautilus-marshal.list +++ b/libnautilus-private/nautilus-marshal.list @@ -1,3 +1,5 @@ +STRING:VOID +OBJECT:BOXED BOOLEAN:POINTER INT:POINTER,INT INT:POINTER,BOOLEAN @@ -10,3 +12,4 @@ VOID:POINTER,POINTER VOID:POINTER,STRING VOID:STRING,STRING VOID:POINTER,POINTER,POINTER,INT,INT,INT +VOID:POINTER,STRING,UINT,INT,INT diff --git a/libnautilus-private/nautilus-tree-view-drag-dest.c b/libnautilus-private/nautilus-tree-view-drag-dest.c new file mode 100644 index 000000000..96ffb5cd0 --- /dev/null +++ b/libnautilus-private/nautilus-tree-view-drag-dest.c @@ -0,0 +1,686 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* + * Nautilus + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * Nautilus is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * Nautilus is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Dave Camp <dave@ximian.com> + */ + +/* nautilus-tree-view-drag-dest.c: Handles drag and drop for treeviews which + * contain a hierarchy of files + */ + +#include <config.h> +#include "nautilus-tree-view-drag-dest.h" + +#include <eel/eel-gtk-macros.h> +#include <gtk/gtkmain.h> +#include <gtk/gtksignal.h> +#include <libgnome/gnome-macros.h> +#include <libgnomevfs/gnome-vfs-utils.h> +#include "nautilus-file-dnd.h" +#include "nautilus-icon-dnd.h" +#include "nautilus-link.h" +#include "nautilus-marshal.h" + +#define AUTO_SCROLL_MARGIN 20 + +struct _NautilusTreeViewDragDestDetails { + GtkTreeView *tree_view; + + gboolean drop_occurred; + + gboolean have_drag_data; + guint drag_type; + GtkSelectionData *drag_data; + GList *drag_list; + + guint highlight_id; + guint scroll_id; +}; + +enum { + GET_ROOT_URI, + GET_FILE_FOR_PATH, + MOVE_COPY_ITEMS, + LAST_SIGNAL +}; + +static void nautilus_tree_view_drag_dest_instance_init (NautilusTreeViewDragDest *dest); +static void nautilus_tree_view_drag_dest_class_init (NautilusTreeViewDragDestClass *class); + +static guint signals[LAST_SIGNAL]; + +GNOME_CLASS_BOILERPLATE (NautilusTreeViewDragDest, + nautilus_tree_view_drag_dest, + GObject, G_TYPE_OBJECT); + +static GtkTargetEntry drag_types [] = { + { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST }, + { NAUTILUS_ICON_DND_URI_LIST_TYPE, 0, NAUTILUS_ICON_DND_URI_LIST }, + { NAUTILUS_ICON_DND_URL_TYPE, 0, NAUTILUS_ICON_DND_URL } + /* FIXME: Should handle emblems once the list view supports them */ +}; + + +static void +gtk_tree_view_vertical_autoscroll (GtkTreeView *tree_view) +{ + GdkRectangle visible_rect; + GtkAdjustment *vadjustment; + GdkWindow *window; + int y; + int offset; + float value; + + window = gtk_tree_view_get_bin_window (tree_view); + vadjustment = gtk_tree_view_get_vadjustment (tree_view); + + gdk_window_get_pointer (window, NULL, &y, NULL); + + y += vadjustment->value; + + gtk_tree_view_get_visible_rect (tree_view, &visible_rect); + + offset = y - (visible_rect.y + 2 * AUTO_SCROLL_MARGIN); + if (offset > 0) { + offset = y - (visible_rect.y + visible_rect.height - 2 * AUTO_SCROLL_MARGIN); + if (offset < 0) { + return; + } + } + + value = CLAMP (vadjustment->value + offset, 0.0, + vadjustment->upper - vadjustment->page_size); + gtk_adjustment_set_value (vadjustment, value); +} + +static int +scroll_timeout (gpointer data) +{ + GtkTreeView *tree_view = GTK_TREE_VIEW (data); + + gtk_tree_view_vertical_autoscroll (tree_view); + + return TRUE; +} + +static void +remove_scroll_timeout (NautilusTreeViewDragDest *dest) +{ + if (dest->details->scroll_id) { + gtk_timeout_remove (dest->details->scroll_id); + dest->details->scroll_id = 0; + } +} + +static gboolean +highlight_expose (GtkWidget *widget, + GdkEventExpose *event, + gpointer data) +{ + GdkWindow *bin_window; + int width; + int height; + + if (GTK_WIDGET_DRAWABLE (widget)) { + bin_window = + gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget)); + + gdk_drawable_get_size (bin_window, &width, &height); + + gtk_paint_focus (widget->style, + bin_window, + GTK_WIDGET_STATE (widget), + NULL, + widget, + "treeview-drop-indicator", + 0, 0, width, height); + } + + return FALSE; +} + +static void +set_widget_highlight (NautilusTreeViewDragDest *dest, gboolean highlight) +{ + if (!highlight && dest->details->highlight_id) { + g_signal_handler_disconnect (dest->details->tree_view, + dest->details->highlight_id); + dest->details->highlight_id = 0; + } + + if (highlight && !dest->details->highlight_id) { + dest->details->highlight_id = + g_signal_connect_object (dest->details->tree_view, + "expose_event", + G_CALLBACK (highlight_expose), + dest, + G_CONNECT_AFTER); + } + gtk_widget_queue_draw (GTK_WIDGET (dest->details->tree_view)); +} + +static void +set_drag_dest_row (NautilusTreeViewDragDest *dest, + GtkTreePath *path) +{ + if (path) { + set_widget_highlight (dest, FALSE); + gtk_tree_view_set_drag_dest_row + (dest->details->tree_view, + path, + GTK_TREE_VIEW_DROP_INTO_OR_BEFORE); + } else { + set_widget_highlight (dest, TRUE); + gtk_tree_view_set_drag_dest_row (dest->details->tree_view, + NULL, + 0); + } +} + +static void +clear_drag_dest_row (NautilusTreeViewDragDest *dest) +{ + gtk_tree_view_set_drag_dest_row (dest->details->tree_view, NULL, 0); + set_widget_highlight (dest, FALSE); +} + +static void +get_drag_data (NautilusTreeViewDragDest *dest, + GdkDragContext *context, + guint32 time) +{ + GdkAtom target; + + target = gtk_drag_dest_find_target (GTK_WIDGET (dest->details->tree_view), + context, + NULL); + + gtk_drag_get_data (GTK_WIDGET (dest->details->tree_view), + context, target, time); +} + +static void +free_drag_data (NautilusTreeViewDragDest *dest) +{ + dest->details->have_drag_data = FALSE; + + if (dest->details->drag_data) { + gtk_selection_data_free (dest->details->drag_data); + dest->details->drag_data = NULL; + } + + if (dest->details->drag_list) { + nautilus_drag_destroy_selection_list (dest->details->drag_list); + dest->details->drag_list = NULL; + } +} + +static char * +get_root_uri (NautilusTreeViewDragDest *dest) +{ + char *uri; + + g_signal_emit (dest, signals[GET_ROOT_URI], 0, &uri); + + return uri; +} + +static NautilusFile * +file_for_path (NautilusTreeViewDragDest *dest, GtkTreePath *path) +{ + NautilusFile *file; + char *uri; + + if (path) { + g_signal_emit (dest, signals[GET_FILE_FOR_PATH], 0, path, &file); + } else { + uri = get_root_uri (dest); + + file = nautilus_file_get (uri); + + g_free (uri); + } + + return file; +} + +static GtkTreePath * +get_drop_path (NautilusTreeViewDragDest *dest, + GtkTreePath *path) +{ + NautilusFile *file; + GtkTreePath *ret; + + if (!path) { + return NULL; + } + + file = file_for_path (dest, path); + + ret = NULL; + + if (!file || !nautilus_drag_can_accept_items (file, dest->details->drag_list)){ + if (gtk_tree_path_get_depth (path) == 1) { + ret = NULL; + } else { + ret = gtk_tree_path_copy (path); + gtk_tree_path_up (ret); + } + } else { + ret = gtk_tree_path_copy (path); + } + + nautilus_file_unref (file); + + return ret; +} + +static char * +get_drop_target (NautilusTreeViewDragDest *dest, + GtkTreePath *path) +{ + NautilusFile *file; + char *target; + + file = file_for_path (dest, path); + target = nautilus_file_get_drop_target_uri (file); + nautilus_file_unref (file); + + return target; +} + +static guint +get_drop_action (NautilusTreeViewDragDest *dest, + GdkDragContext *context, + GtkTreePath *path) +{ + char *drop_target; + guint action; + + if (!dest->details->have_drag_data || !dest->details->drag_list) { + return 0; + } + + switch (dest->details->drag_type) { + case NAUTILUS_ICON_DND_GNOME_ICON_LIST : + drop_target = get_drop_target (dest, path); + + if (!drop_target) { + return 0; + } + + nautilus_drag_default_drop_action_for_icons + (context, + drop_target, + dest->details->drag_list, + &action); + + g_free (drop_target); + + return action; + case NAUTILUS_ICON_DND_URI_LIST : + case NAUTILUS_ICON_DND_URL : + return context->suggested_action; + } + + return 0; +} + +static gboolean +drag_motion_callback (GtkWidget *widget, + GdkDragContext *context, + int x, + int y, + guint32 time, + gpointer data) +{ + NautilusTreeViewDragDest *dest; + GtkTreePath *path; + GtkTreePath *drop_path; + GtkTreeViewDropPosition pos; + guint action; + + dest = NAUTILUS_TREE_VIEW_DRAG_DEST (data); + + gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget), + x, y, &path, &pos); + + + if (!dest->details->have_drag_data) { + get_drag_data (dest, context, time); + } + drop_path = get_drop_path (dest, path); + + action = get_drop_action (dest, context, drop_path); + + if (action) { + set_drag_dest_row (dest, drop_path); + } else { + clear_drag_dest_row (dest); + } + + if (path) { + gtk_tree_path_free (path); + } + + if (drop_path) { + gtk_tree_path_free (drop_path); + } + + if (dest->details->scroll_id == 0) { + dest->details->scroll_id = + gtk_timeout_add (150, + scroll_timeout, + dest->details->tree_view); + } + + gdk_drag_status (context, action, time); + + return TRUE; +} + +static void +drag_leave_callback (GtkWidget *widget, + GdkDragContext *context, + guint32 time, + gpointer data) +{ + NautilusTreeViewDragDest *dest; + + dest = NAUTILUS_TREE_VIEW_DRAG_DEST (data); + + clear_drag_dest_row (dest); + + free_drag_data (dest); + + remove_scroll_timeout (dest); +} + +static void +receive_uris (NautilusTreeViewDragDest *dest, + GdkDragContext *context, + GList *source_uris, + int x, int y) +{ + char *drop_target; + GtkTreePath *path; + GtkTreePath *drop_path; + GtkTreeViewDropPosition pos; + GdkDragAction action; + + gtk_tree_view_get_dest_row_at_pos (dest->details->tree_view, x, y, + &path, &pos); + + drop_path = get_drop_path (dest, path); + + drop_target = get_drop_target (dest, drop_path); + + if (context->action == GDK_ACTION_ASK) { + if (nautilus_drag_selection_includes_special_link (dest->details->drag_list)) { + /* We only want to move the trash */ + action = GDK_ACTION_MOVE; + } else { + action = GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK; + } + context->action = nautilus_drag_drop_action_ask (action); + } + + /* We only want to copy external uris */ + if (dest->details->drag_type == NAUTILUS_ICON_DND_URI_LIST) { + action = GDK_ACTION_COPY; + } + + if (context->action > 0) { + g_signal_emit (dest, signals[MOVE_COPY_ITEMS], 0, + source_uris, + drop_target, + context->action, + x, y); + } + + if (path) { + gtk_tree_path_free (path); + } + + if (drop_path) { + gtk_tree_path_free (drop_path); + } + + g_free (drop_target); +} + +static void +receive_dropped_icons (NautilusTreeViewDragDest *dest, + GdkDragContext *context, + int x, int y) +{ + GList *source_uris; + GList *l; + + /* FIXME: ignore local only moves */ + + if (!dest->details->drag_list) { + return; + } + + source_uris = NULL; + for (l = dest->details->drag_list; l != NULL; l = l->next) { + source_uris = g_list_prepend (source_uris, + ((NautilusDragSelectionItem *)l->data)->uri); + } + + source_uris = g_list_reverse (source_uris); + + receive_uris (dest, context, source_uris, x, y); + + g_list_free (source_uris); +} + +static void +receive_dropped_uri_list (NautilusTreeViewDragDest *dest, + GdkDragContext *context, + int x, int y) +{ + GList *source_uris; + + if (!dest->details->drag_data) { + return; + } + + source_uris = nautilus_icon_dnd_uri_list_extract_uris ((char*)dest->details->drag_data->data); + + receive_uris (dest, context, source_uris, x, y); + + nautilus_icon_dnd_uri_list_free_strings (source_uris); +} + +static gboolean +drag_data_received_callback (GtkWidget *widget, + GdkDragContext *context, + int x, + int y, + GtkSelectionData *selection_data, + guint info, + guint32 time, + gpointer data) +{ + NautilusTreeViewDragDest *dest; + gboolean success; + + dest = NAUTILUS_TREE_VIEW_DRAG_DEST (data); + + if (!dest->details->have_drag_data) { + dest->details->have_drag_data = TRUE; + dest->details->drag_type = info; + dest->details->drag_data = + gtk_selection_data_copy (selection_data); + if (info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) { + dest->details->drag_list = + nautilus_drag_build_selection_list (selection_data); + } + } + + if (dest->details->drop_occurred) { + success = FALSE; + switch (info) { + case NAUTILUS_ICON_DND_GNOME_ICON_LIST : + receive_dropped_icons (dest, context, x, y); + success = TRUE; + break; + case NAUTILUS_ICON_DND_URI_LIST : + case NAUTILUS_ICON_DND_URL : + receive_dropped_uri_list (dest, context, x, y); + success = TRUE; + break; + } + + dest->details->drop_occurred = FALSE; + free_drag_data (dest); + gtk_drag_finish (context, success, FALSE, time); + } + + /* appease GtkTreeView by preventing its drag_data_receive + * from being called */ + g_signal_stop_emission_by_name (dest->details->tree_view, + "drag_data_received"); + + return TRUE; +} + +static gboolean +drag_drop_callback (GtkWidget *widget, + GdkDragContext *context, + int x, + int y, + guint32 time, + gpointer data) +{ + NautilusTreeViewDragDest *dest; + + dest = NAUTILUS_TREE_VIEW_DRAG_DEST (data); + + dest->details->drop_occurred = TRUE; + + get_drag_data (dest, context, time); + remove_scroll_timeout (dest); + clear_drag_dest_row (dest); + + return TRUE; +} + +static void +nautilus_tree_view_drag_dest_finalize (GObject *object) +{ + NautilusTreeViewDragDest *dest; + + dest = NAUTILUS_TREE_VIEW_DRAG_DEST (object); + + free_drag_data (dest); + + g_free (dest->details); + + EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); +} + +static void +nautilus_tree_view_drag_dest_instance_init (NautilusTreeViewDragDest *dest) +{ + dest->details = g_new0 (NautilusTreeViewDragDestDetails, 1); +} + +static void +nautilus_tree_view_drag_dest_class_init (NautilusTreeViewDragDestClass *class) +{ + GObjectClass *gobject_class; + + gobject_class = G_OBJECT_CLASS (class); + + gobject_class->finalize = nautilus_tree_view_drag_dest_finalize; + + signals[GET_ROOT_URI] = + g_signal_new ("get_root_uri", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (NautilusTreeViewDragDestClass, + get_root_uri), + NULL, NULL, + nautilus_marshal_STRING__VOID, + G_TYPE_STRING, 0); + signals[GET_FILE_FOR_PATH] = + g_signal_new ("get_file_for_path", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (NautilusTreeViewDragDestClass, + get_file_for_path), + NULL, NULL, + nautilus_marshal_OBJECT__BOXED, + NAUTILUS_TYPE_FILE, 1, + GTK_TYPE_TREE_PATH); + signals[MOVE_COPY_ITEMS] = + g_signal_new ("move_copy_items", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (NautilusTreeViewDragDestClass, + move_copy_items), + NULL, NULL, + + nautilus_marshal_VOID__POINTER_STRING_UINT_INT_INT, + G_TYPE_NONE, 5, + G_TYPE_POINTER, + G_TYPE_STRING, + G_TYPE_UINT, + G_TYPE_INT, + G_TYPE_INT); +} + +NautilusTreeViewDragDest * +nautilus_tree_view_drag_dest_new (GtkTreeView *tree_view) +{ + NautilusTreeViewDragDest *dest; + + dest = g_object_new (NAUTILUS_TYPE_TREE_VIEW_DRAG_DEST, NULL); + + dest->details->tree_view = tree_view; + + gtk_drag_dest_set (GTK_WIDGET (tree_view), + 0, drag_types, G_N_ELEMENTS (drag_types), + GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_ASK); + + g_signal_connect_object (tree_view, + "drag_motion", + G_CALLBACK (drag_motion_callback), + dest, 0); + g_signal_connect_object (tree_view, + "drag_leave", + G_CALLBACK (drag_leave_callback), + dest, 0); + g_signal_connect_object (tree_view, + "drag_drop", + G_CALLBACK (drag_drop_callback), + dest, 0); + g_signal_connect_object (tree_view, + "drag_data_received", + G_CALLBACK (drag_data_received_callback), + dest, 0); + + return dest; +} diff --git a/libnautilus-private/nautilus-tree-view-drag-dest.h b/libnautilus-private/nautilus-tree-view-drag-dest.h new file mode 100644 index 000000000..5029c13b7 --- /dev/null +++ b/libnautilus-private/nautilus-tree-view-drag-dest.h @@ -0,0 +1,75 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* + * Nautilus + * + * Copyright (C) 2002 Sun Microsystems, Inc. + * + * Nautilus is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * Nautilus is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Dave Camp <dave@ximian.com> + */ + +/* nautilus-tree-view-drag-dest.h: Handles drag and drop for treeviews which + * contain a hierarchy of files + */ + +#ifndef NAUTILUS_TREE_VIEW_DRAG_DEST_H +#define NAUTILUS_TREE_VIEW_DRAG_DEST_H + +#include <gtk/gtktreeview.h> + +#include "nautilus-file.h" + +G_BEGIN_DECLS + +#define NAUTILUS_TYPE_TREE_VIEW_DRAG_DEST (nautilus_tree_view_drag_dest_get_type ()) +#define NAUTILUS_TREE_VIEW_DRAG_DEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_TREE_VIEW_DRAG_DEST, NautilusTreeViewDragDest)) +#define NAUTILUS_TREE_VIEW_DRAG_DEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_TREE_VIEW_DRAG_DEST, NautilusTreeViewDragDestClass)) +#define NAUTILUS_IS_TREE_VIEW_DRAG_DEST(obj) (G_TYPE_INSTANCE_CHECK_TYPE ((obj), NAUTILUS_TYPE_TREE_VIEW_DRAG_DEST)) +#define NAUTILUS_IS_TREE_VIEW_DRAG_DEST_CLASS(klass) (G_TYPE_CLASS_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_TREE_VIEW_DRAG_DEST)) + +typedef struct _NautilusTreeViewDragDest NautilusTreeViewDragDest; +typedef struct _NautilusTreeViewDragDestClass NautilusTreeViewDragDestClass; +typedef struct _NautilusTreeViewDragDestDetails NautilusTreeViewDragDestDetails; + +struct _NautilusTreeViewDragDest { + GObject parent; + + NautilusTreeViewDragDestDetails *details; +}; + +struct _NautilusTreeViewDragDestClass { + GObjectClass parent; + + char *(*get_root_uri) (NautilusTreeViewDragDest *dest); + NautilusFile *(*get_file_for_path) (NautilusTreeViewDragDest *dest, + GtkTreePath *path); + void (*move_copy_items) (NautilusTreeViewDragDest *dest, + const GList *item_uris, + const char *target_uri, + guint action, + int x, + int y); + +}; + +GType nautilus_tree_view_drag_dest_get_type (void); +NautilusTreeViewDragDest *nautilus_tree_view_drag_dest_new (GtkTreeView *tree_view); + +G_END_DECLS + +#endif diff --git a/src/file-manager/fm-icon-view.c b/src/file-manager/fm-icon-view.c index a00761c30..2c1ec0c66 100644 --- a/src/file-manager/fm-icon-view.c +++ b/src/file-manager/fm-icon-view.c @@ -1933,27 +1933,11 @@ get_icon_drop_target_uri_callback (NautilusIconContainer *container, NautilusFile *file, FMIconView *icon_view) { - char *uri, *target_uri; - - g_assert (NAUTILUS_IS_ICON_CONTAINER (container)); - g_assert (NAUTILUS_IS_FILE (file)); - g_assert (FM_IS_ICON_VIEW (icon_view)); - - uri = nautilus_file_get_uri (file); - - /* Check for Nautilus link */ - if (nautilus_file_is_nautilus_link (file)) { - /* FIXME bugzilla.gnome.org 43020: This does sync. I/O and works only locally. */ - if (!eel_vfs_has_capability (uri, EEL_VFS_CAPABILITY_IS_REMOTE_AND_SLOW)) { - target_uri = nautilus_link_local_get_link_uri (uri); - if (target_uri != NULL) { - g_free (uri); - uri = target_uri; - } - } - } + g_return_val_if_fail (NAUTILUS_IS_ICON_CONTAINER (container), NULL); + g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL); + g_return_val_if_fail (FM_IS_ICON_VIEW (icon_view), NULL); - return uri; + return nautilus_file_get_drop_target_uri (file); } /* Preferences changed callbacks */ diff --git a/src/file-manager/fm-list-view.c b/src/file-manager/fm-list-view.c index 26aa4f37a..cd257e155 100644 --- a/src/file-manager/fm-list-view.c +++ b/src/file-manager/fm-list-view.c @@ -38,10 +38,14 @@ #include <gtk/gtktreeview.h> #include <libgnome/gnome-i18n.h> #include <libgnome/gnome-macros.h> +#include <libgnomevfs/gnome-vfs-utils.h> #include <libnautilus-private/nautilus-directory-background.h> #include <libnautilus-private/nautilus-dnd.h> +#include <libnautilus-private/nautilus-file-dnd.h> #include <libnautilus-private/nautilus-global-preferences.h> +#include <libnautilus-private/nautilus-icon-dnd.h> #include <libnautilus-private/nautilus-metadata.h> +#include <libnautilus-private/nautilus-tree-view-drag-dest.h> struct FMListViewDetails { GtkTreeView *tree_view; @@ -56,12 +60,8 @@ struct FMListViewDetails { GtkCellRendererText *date_modified_cell; NautilusZoomLevel zoom_level; -}; -static GtkTargetEntry drag_types [] = { - { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST }, - { NAUTILUS_ICON_DND_URI_LIST_TYPE, 0, NAUTILUS_ICON_DND_URI_LIST }, - { NAUTILUS_ICON_DND_URL_TYPE, 0, NAUTILUS_ICON_DND_URL } + NautilusTreeViewDragDest *drag_dest; }; /* @@ -287,6 +287,60 @@ cell_renderer_edited (GtkCellRendererText *cell, nautilus_file_unref (file); } +static char * +get_root_uri_callback (NautilusTreeViewDragDest *dest, + gpointer user_data) +{ + FMListView *view; + + view = FM_LIST_VIEW (user_data); + + return fm_directory_view_get_uri (FM_DIRECTORY_VIEW (view)); +} + +static NautilusFile * +get_file_for_path_callback (NautilusTreeViewDragDest *dest, + GtkTreePath *path, + gpointer user_data) +{ + FMListView *view; + GtkTreeIter iter; + NautilusFile *file; + + view = FM_LIST_VIEW (user_data); + + file = NULL; + + if (gtk_tree_model_get_iter (GTK_TREE_MODEL (view->details->model), + &iter, path)) { + gtk_tree_model_get (GTK_TREE_MODEL (view->details->model), + &iter, + FM_LIST_MODEL_FILE_COLUMN, + &file, + -1); + } + + return file; +} + +static void +move_copy_items_callback (NautilusTreeViewDragDest *dest, + const GList *item_uris, + const char *target_uri, + guint action, + int x, + int y, + gpointer user_data) + +{ + fm_directory_view_move_copy_items (item_uris, + NULL, + target_uri, + action, + x, y, + FM_DIRECTORY_VIEW (user_data)); +} + static void create_and_set_up_tree_view (FMListView *view) { @@ -294,6 +348,21 @@ create_and_set_up_tree_view (FMListView *view) GtkTreeViewColumn *column; view->details->tree_view = GTK_TREE_VIEW (gtk_tree_view_new ()); + view->details->drag_dest = + nautilus_tree_view_drag_dest_new (view->details->tree_view); + + g_signal_connect_object (view->details->drag_dest, + "get_root_uri", + G_CALLBACK (get_root_uri_callback), + view, 0); + g_signal_connect_object (view->details->drag_dest, + "get_file_for_path", + G_CALLBACK (get_file_for_path_callback), + view, 0); + g_signal_connect_object (view->details->drag_dest, + "move_copy_items", + G_CALLBACK (move_copy_items_callback), + view, 0); g_signal_connect_object (gtk_tree_view_get_selection (view->details->tree_view), "changed", @@ -317,10 +386,6 @@ create_and_set_up_tree_view (FMListView *view) gtk_tree_selection_set_mode (gtk_tree_view_get_selection (view->details->tree_view), GTK_SELECTION_MULTIPLE); gtk_tree_view_set_rules_hint (view->details->tree_view, TRUE); - gtk_tree_view_enable_model_drag_source (view->details->tree_view, 0, - drag_types, G_N_ELEMENTS (drag_types), - GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK); - /* Create the file name column */ cell = gtk_cell_renderer_pixbuf_new (); view->details->pixbuf_cell = (GtkCellRendererPixbuf *)cell; @@ -821,6 +886,11 @@ fm_list_view_dispose (GObject *object) list_view->details->model = NULL; } + if (list_view->details->drag_dest) { + g_object_unref (list_view->details->drag_dest); + list_view->details->drag_dest = NULL; + } + G_OBJECT_CLASS (parent_class)->dispose (object); } |