Commit 8fed4ca3 authored by Dave Camp's avatar Dave Camp Committed by Dave Camp

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.
parent c53f887d
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>
......
......@@ -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 ();
......@@ -467,6 +532,19 @@ nautilus_tree_view_instance_init (NautilusTreeView *view)
filtering_changed_callback, 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)
{
......@@ -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;
}
......@@ -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 \
......
......@@ -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;
}
......@@ -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
......@@ -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)
{
......
......@@ -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);
......
......@@ -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 {
......
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
/* -*- 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