Yasumichi Akahoshi
yasum****@users*****
2005年 9月 26日 (月) 15:46:59 JST
Index: cxplorer/src/cxp-dir-view.c diff -u cxplorer/src/cxp-dir-view.c:1.26 cxplorer/src/cxp-dir-view.c:1.27 --- cxplorer/src/cxp-dir-view.c:1.26 Sat Sep 3 21:55:35 2005 +++ cxplorer/src/cxp-dir-view.c Mon Sep 26 15:46:59 2005 @@ -1,4 +1,4 @@ -/* $Id: cxp-dir-view.c,v 1.26 2005/09/03 12:55:35 yasumichi Exp $ */ +/* $Id: cxp-dir-view.c,v 1.27 2005/09/26 06:46:59 yasumichi Exp $ */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ #include <glib/gi18n.h> #include <string.h> #include <cxp.h> +#include <errno.h> #include "cxp-dir-view.h" /* @@ -60,6 +61,17 @@ LAST_SIGNAL }; +enum +{ + TARGET_CXP_FILE_INFO, + TARGET_STRING +}; + +static GtkTargetEntry cxp_target_types[] = { + {"_CXP_FILE_INFO", 0, TARGET_CXP_FILE_INFO}, + {"STRING", 0, TARGET_STRING} +}; + static GObjectClass *parent_class = NULL; static guint cxp_dir_view_signals[LAST_SIGNAL] = { 0 }; @@ -101,6 +113,7 @@ static GtkTreeIter *cxp_dir_view_search_child_node (GtkTreeModel * model, GtkTreeIter * parent, gchar * label); +void cxp_dir_view_drag_data_received (GtkWidget *widget, GdkDragContext *dc, gint x, gint y, GtkSelectionData *selection_data, guint info, guint t, gpointer data); /** * cxp_dir_view_get_type @@ -149,12 +162,15 @@ priv->dirview = cxp_dir_view_tree_view_new (self); gtk_container_add (GTK_CONTAINER (self), priv->dirview); priv->dispose_has_run = FALSE; + gtk_drag_dest_set (priv->dirview, GTK_DEST_DEFAULT_ALL, cxp_target_types, G_N_ELEMENTS(cxp_target_types), GDK_ACTION_MOVE); /* signal connect */ g_signal_connect (priv->dirview, "row_expanded", G_CALLBACK (cxp_dir_view_on_row_expanded), self); g_signal_connect (priv->dirview, "cursor_changed", G_CALLBACK (cxp_dir_view_on_cursor_changed), self); + g_signal_connect (priv->dirview, "drag_data_received", + G_CALLBACK (cxp_dir_view_drag_data_received), self); } /** @@ -717,3 +733,46 @@ cxp_dir_view_change_directory (instance, currentDirectory); g_free (currentDirectory); } + +void cxp_dir_view_drag_data_received (GtkWidget *widget, GdkDragContext *dc, gint x, gint y, GtkSelectionData *selection_data, guint info, guint t, gpointer data) +{ + CxpDirViewPrivate *priv = CXP_DIR_VIEW_GET_PRIVATE (data); + gchar *move_files; + gchar **move_file; + gchar *src_base; + gchar *dest_dir; + gchar *dest_path; + guint index; + GtkTreeViewDropPosition pos; + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW(priv->dirview)); + if(gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW(priv->dirview), x, y, &path, &pos)) + { + if (gtk_tree_model_get_iter(model, &iter, path)) + { + gtk_tree_model_get (model, &iter, COL_FULL_PATH, &dest_dir, -1); + move_files = selection_data->data; + move_file = g_strsplit (move_files, "\n", 0); + for(index=0; move_file[index] != NULL; index++) + { + if(g_file_test(move_file[index], G_FILE_TEST_EXISTS)) + { + src_base = g_path_get_basename (move_file[index]); + dest_path = g_build_filename (dest_dir, src_base, NULL); + errno = 0; + if(rename(move_file[index], dest_path) == -1) + { + cxp_error_dialog_run_about_file (src_base); + } + g_free (dest_path); + g_free (src_base); + } + } + g_free (dest_dir); + g_strfreev (move_file); + } + } +}