Make the tree a drag source -mig

This commit is contained in:
Miguel de Icaza 1998-12-04 21:32:19 +00:00
parent 0fac6acd38
commit 7d035cca51
7 changed files with 89 additions and 249 deletions

View File

@ -1,3 +1,11 @@
1998-12-04 Miguel de Icaza <miguel@nuclecu.unam.mx>
* gblist.c (blist_select_row): Warning fixes.
* olddnd.c: Moved the old DND code here for reference purposes.
* gscreen.c: Made the tree a drag source.
1998-12-04 Jonathan Blandford <jrb@redhat.com>
* gdialogs.c (trim_file_name): better update dialog

View File

@ -10,13 +10,13 @@
#include "gblist.h"
static void
blist_select_row (GtkCList *clist, gint row, gint column, GdkEventButton *event)
blist_select_row (GtkCList *clist, gint row, gint column, GdkEvent *event)
{
/* nothing */
}
static void
blist_unselect_row (GtkCList *clist, gint row, gint column, GdkEventButton *event)
blist_unselect_row (GtkCList *clist, gint row, gint column, GdkEvent *event)
{
/* nothing */
}

View File

@ -64,5 +64,6 @@ typedef struct {
} GpropExec;
GpropExec *gprop_exec_new (GnomeDesktopEntry *dentry);
void gprop_exec_get_data (GpropExec *ge, GnomeDesktopEntry *dentry);
#endif

View File

@ -849,180 +849,6 @@ panel_tree_drag_data_received (GtkWidget *widget,
g_free (path);
}
#ifdef OLD_DND
/*
* Handler for text/plain and url:ALL drag types
*
* Sets the drag information to the filenames selected on the panel
*/
static void
panel_transfer_file_names (GtkWidget *widget, GdkEventDragRequest *event, WPanel *panel, int *len, char **data)
{
*data = panel_build_selected_file_list (panel, len);
}
/*
* Handler for file:ALL type (target application only understands local pathnames)
*
* Makes local copies of the files and transfers the filenames.
*/
static void
panel_make_local_copies_and_transfer (GtkWidget *widget, GdkEventDragRequest *event, WPanel *panel,
int *len, char **data)
{
char *filename, *localname;
int i;
if (panel->marked){
char **local_names_array, *p;
int j, total_len;
/* First assemble all of the filenames */
local_names_array = malloc (sizeof (char *) * panel->marked);
total_len = j = 0;
for (i = 0; i < panel->count; i++){
char *filename;
if (!panel->dir.list [i].f.marked)
continue;
filename = concat_dir_and_file (panel->cwd, panel->dir.list [i].fname);
localname = mc_getlocalcopy (filename);
total_len += strlen (localname) + 1;
local_names_array [j++] = localname;
free (filename);
}
*len = total_len;
*data = p = malloc (total_len);
for (i = 0; i < j; i++){
strcpy (p, local_names_array [i]);
g_free (local_names_array [i]);
p += strlen (p) + 1;
}
} else {
filename = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
localname = mc_getlocalcopy (filename);
free (filename);
*data = localname;
*len = strlen (localname + 1);
}
}
static void
panel_drag_request (GtkWidget *widget, GdkEventDragRequest *event, WPanel *panel, int *len, char **data)
{
*len = 0;
*data = 0;
if ((strcmp (event->data_type, "text/plain") == 0) ||
(strcmp (event->data_type, "url:ALL") == 0)){
panel_transfer_file_names (widget, event, panel, len, data);
} else if (strcmp (event->data_type, "file:ALL") == 0){
if (vfs_file_is_local (panel->cwd))
panel_transfer_file_names (widget, event, panel, len, data);
else
panel_make_local_copies_and_transfer (widget, event, panel, len, data);
}
}
/*
* Listing mode: drag request handler
*/
static void
panel_clist_drag_request (GtkWidget *widget, GdkEventDragRequest *event, WPanel *panel)
{
GdkWindowPrivate *clist_window = (GdkWindowPrivate *) (GTK_WIDGET (widget)->window);
GdkWindowPrivate *clist_areaw = (GdkWindowPrivate *) (GTK_CLIST (widget)->clist_window);
char *data;
int len;
panel_drag_request (widget, event, panel, &len, &data);
/* Now transfer the DnD information */
if (len && data){
if (clist_window->dnd_drag_accepted)
gdk_window_dnd_data_set ((GdkWindow *)clist_window, (GdkEvent *) event, data, len);
else
gdk_window_dnd_data_set ((GdkWindow *)clist_areaw, (GdkEvent *) event, data, len);
free (data);
}
}
/*
* Invoked when a drop has happened on the panel
*/
static void
panel_clist_drop_data_available (GtkWidget *widget, GdkEventDropDataAvailable *data, WPanel *panel)
{
gint winx, winy;
gint dropx, dropy;
gint row;
char *drop_dir;
gdk_window_get_origin (GTK_CLIST (widget)->clist_window, &winx, &winy);
dropx = data->coords.x - winx;
dropy = data->coords.y - winy;
if (dropx < 0 || dropy < 0)
return;
if (gtk_clist_get_selection_info (GTK_CLIST (widget), dropx, dropy, &row, NULL) == 0)
drop_dir = panel->cwd;
else {
g_assert (row < panel->count);
}
#if 0
drop_on_directory (data, drop_dir, 0);
#endif
if (drop_dir != panel->cwd)
free (drop_dir);
update_one_panel_widget (panel, 0, UP_KEEPSEL);
panel_update_contents (panel);
}
static void
panel_drag_begin (GtkWidget *widget, GdkEvent *event, WPanel *panel)
{
GdkPoint hotspot = { 15, 15 };
if (panel->marked > 1){
if (drag_multiple && drag_multiple_ok){
gdk_dnd_set_drag_shape (drag_multiple->window, &hotspot,
drag_multiple_ok->window, &hotspot);
gtk_widget_show (drag_multiple);
gtk_widget_show (drag_multiple_ok);
}
} else {
if (drag_directory && drag_directory_ok)
gdk_dnd_set_drag_shape (drag_directory->window, &hotspot,
drag_directory_ok->window, &hotspot);
gtk_widget_show (drag_directory_ok);
gtk_widget_show (drag_directory);
}
}
static void
panel_icon_list_drag_begin (GtkWidget *widget, GdkEvent *event, WPanel *panel)
{
GnomeIconList *icons = GNOME_ICON_LIST (panel->icons);
icons->last_clicked = NULL;
panel_drag_begin (widget, event, panel);
}
static void
panel_artificial_drag_start (GtkCList *window, GdkEventMotion *event)
{
artificial_drag_start (window->clist_window, event->x, event->y);
}
#endif /* OLD_DND */
static void
load_dnd_icons (void)
{
@ -1243,7 +1069,7 @@ load_image_icon_view (char *base)
return im;
}
void
static void
load_imlib_icons (void)
{
static int loaded;
@ -1262,68 +1088,6 @@ load_imlib_icons (void)
loaded = 1;
}
#if OLD_DND
static void
panel_icon_list_artificial_drag_start (GtkObject *obj, GdkEventMotion *event)
{
artificial_drag_start (GTK_WIDGET (obj)->window, event->x, event->y);
}
/*
* Icon view drag request handler
*/
static void
panel_icon_list_drag_request (GtkWidget *widget, GdkEventDragRequest *event, WPanel *panel)
{
char *data;
int len;
panel_drag_request (widget, event, panel, &len, &data);
if (len && data){
gdk_window_dnd_data_set (widget->window, (GdkEvent *) event, data, len);
free (data);
}
}
static void
panel_icon_list_drop_data_available (GtkWidget *widget, GdkEventDropDataAvailable *data, WPanel *panel)
{
GnomeIconList *ilist = GNOME_ICON_LIST (widget);
gint winx, winy;
gint dropx, dropy;
gint item;
char *drop_dir;
gdk_window_get_origin (widget->window, &winx, &winy);
dropx = data->coords.x - winx;
dropy = data->coords.y - winy;
if (dropx < 0 || dropy < 0)
return;
item = gnome_icon_list_get_icon_at (ilist, dropx, dropy);
if (item == -1)
drop_dir = panel->cwd;
else {
g_assert (item < panel->count);
if (S_ISDIR (panel->dir.list [item].buf.st_mode))
drop_dir = concat_dir_and_file (panel->cwd, panel->dir.list [item].fname);
else
drop_dir = panel->cwd;
}
#if 0
drop_on_directory (data, drop_dir, 0);
#endif
if (drop_dir != panel->cwd)
free (drop_dir);
update_one_panel_widget (panel, 0, UP_KEEPSEL);
panel_update_contents (panel);
}
#endif
/*
* Strategy for activaing the drags from the icon-list:
@ -1423,7 +1187,7 @@ panel_create_icon_display (WPanel *panel)
return GTK_WIDGET (ilist);
}
void
static void
panel_switch_new_display_mode (WPanel *panel)
{
GtkWidget *old_list = panel->list;
@ -1874,6 +1638,62 @@ panel_tree_drag_leave (GtkWidget *widget, GdkDragContext *ctx, int x, int y, gui
}
}
/**
* panel_tree_drag_begin:
*
* callback invoked when the drag action starts from the Tree
*/
static void
panel_tree_drag_begin (GtkWidget *widget, GdkDragContext *context, WPanel *panel)
{
GtkDTree *dtree = GTK_DTREE (widget);
panel->dragging = 1;
dtree->drag_dir = g_strdup (dtree->current_path);
printf ("This is the directory being dragged: %s\n", dtree->current_path);
}
/**
* panel_tree_drag_end:
*
* callback invoked when the drag action initiated by the tree finishes.
*/
static void
panel_tree_drag_end (GtkWidget *widget, GdkDragContext *context, WPanel *panel)
{
GtkDTree *dtree = GTK_DTREE (widget);
panel->dragging = 0;
g_free (dtree->current_path);
dtree->current_path = NULL;
}
/**
* panel_tree_drag_data_get:
*
* Invoked when the tree is required to provide the dragged data
*/
static void
panel_tree_drag_data_get (GtkWidget *widget, GdkDragContext *context,
GtkSelectionData *selection_data, guint info,
guint32 time)
{
GtkDTree *dtree = GTK_DTREE (widget);
char *data;
printf ("TREE DATA GET\n");
switch (info){
case TARGET_URI_LIST:
case TARGET_TEXT_PLAIN:
data = copy_strings ("file:", dtree->drag_dir, NULL);
gtk_selection_data_set (
selection_data, selection_data->target, 8,
data, strlen (data)+1);
break;
}
}
/**
* panel_create_tree_view:
*
@ -1900,6 +1720,17 @@ panel_create_tree_view (WPanel *panel)
/* Data has been dropped signal handler */
gtk_signal_connect (GTK_OBJECT (tree), "drag_data_received",
GTK_SIGNAL_FUNC (panel_tree_drag_data_received), panel);
gtk_signal_connect (GTK_OBJECT (tree), "drag_begin",
GTK_SIGNAL_FUNC (panel_tree_drag_begin), panel);
gtk_signal_connect (GTK_OBJECT (tree), "drag_end",
GTK_SIGNAL_FUNC (panel_tree_drag_end), panel);
gtk_signal_connect (GTK_OBJECT (tree), "drag_data_get",
GTK_SIGNAL_FUNC (panel_tree_drag_data_get), panel);
/* Make directories draggable */
gtk_drag_source_set (GTK_WIDGET (tree), GDK_BUTTON1_MASK,
drag_types, ELEMENTS (drag_types),
GDK_ACTION_LINK | GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_ASK);
/* Mouse is being moved over ourselves */
gtk_signal_connect (GTK_OBJECT (tree), "drag_motion",

View File

@ -188,7 +188,7 @@ gtk_dtree_select_row (GtkCTree *ctree, GtkCTreeNode *row, gint column)
dtree->last_node = row;
gtk_clist_freeze (GTK_CLIST (ctree));
path = gtk_dtree_get_row_path (ctree, row, 0);
path = gtk_dtree_get_row_path (GTK_DTREE (ctree), row, 0);
if (dtree->current_path)
g_free (dtree->current_path);

View File

@ -20,6 +20,7 @@ typedef struct {
int drag_motion_x;
int drag_motion_y;
int timer_id;
char *drag_dir;
GtkCTreeNode *root_node; /* root node */
GtkCTreeNode *last_node; /* last visited node */
@ -40,7 +41,7 @@ typedef struct {
} GtkDTreeClass;
guint gtk_dtree_get_type (void);
GtkWidget *gtk_dtree_new ();
GtkWidget *gtk_dtree_new (void);
void gtk_dtree_select_parent (GtkDTree *dtree,
char *directory);
void gtk_dtree_select_child (GtkDTree *dtree);
@ -51,5 +52,6 @@ gboolean gtk_dtree_select_dir (GtkDTree *dtree,
char *gtk_dtree_get_row_path (GtkDTree *ctree,
GtkCTreeNode *row,
gint column);
void gtk_dtree_construct (GtkDTree *dtree);
#endif

View File

@ -1,13 +1,11 @@
#include <factory.idl>
module GNOME {
interface FileManagerFactory : Factory {
};
module FileManager {
interface Factory : GNOME::Factory {};
exception POSIX_ERROR {};
interface FileManager {
interface Window {
void chdir (in string dir)
raises (POSIX_ERROR);
};