Gnome Terminal Drag and Drop support



	Hi!. I've just hacked a patch to add support for drag & drop uris
to gnome-terminal. 
	Various questions are opened:
		Just now, the code drop the protocol from the uris. Should we
do it only with local files?.
		We need to translate uri-format to something like bash-format,
for example: /mnt/media/My%20Pictures to /mnt/media/My\ Pictures
		is there a gnome funtion for this?

Salu2

-- 
Fernando Herrera de las Heras
Onírica: análisis, diseño e implantación de soluciones informáticas
http://www.onirica.com
diff -ru gnome-terminal-1.9.2/configure.in gnome-terminal-1.9.2.fer/configure.in
--- gnome-terminal-1.9.2/configure.in	Sun Mar 24 21:46:59 2002
+++ gnome-terminal-1.9.2.fer/configure.in	Fri Apr 12 01:11:57 2002
@@ -46,7 +46,7 @@
 AC_PATH_XTRA
 
 ## here we get the flags we'll actually use
-PKG_CHECK_MODULES(TERM, gtk+-2.0 >= 2.0.0 gconf-2.0 >= 1.1.6 libglade-2.0 libgnomeui-2.0)
+PKG_CHECK_MODULES(TERM, gtk+-2.0 >= 2.0.0 gconf-2.0 >= 1.1.6 libglade-2.0 libgnomeui-2.0 gnome-vfs-2.0)
 
 TERM_LIBS="$X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS $TERM_LIBS"
 TERM_CFLAGS="$X_CFLAGS $TERM_CFLAGS"
diff -ru gnome-terminal-1.9.2/src/terminal-screen.c gnome-terminal-1.9.2.fer/src/terminal-screen.c
--- gnome-terminal-1.9.2/src/terminal-screen.c	Sun Mar 24 08:15:33 2002
+++ gnome-terminal-1.9.2.fer/src/terminal-screen.c	Fri Apr 12 01:49:29 2002
@@ -27,6 +27,7 @@
 #include "terminal.h"
 #include <libgnome/gnome-util.h> /* gnome_util_user_shell */
 #include <libgnome/gnome-url.h> /* gnome_url_show */
+#include <libgnomevfs/gnome-vfs-uri.h>
 #include <gdk/gdkx.h>
 #include <string.h>
 #include <stdlib.h>
@@ -63,6 +64,13 @@
 static void terminal_screen_update_on_realize (GtkWidget      *widget,
                                                TerminalScreen *screen);
 
+static void terminal_screen_drag_data_received_handler (GtkWidget *widget, GdkDragContext *context, 
+							gint x, gint y, 
+							GtkSelectionData *selection_data, 
+							guint info, guint time,
+                                                    	TerminalScreen *screen);
+
+
 static void     terminal_screen_popup_menu         (GtkWidget      *term,
                                                     TerminalScreen *screen);
 static gboolean terminal_screen_button_press_event (GtkWidget      *term,
@@ -119,6 +127,13 @@
 static void
 terminal_screen_init (TerminalScreen *screen)
 {  
+  static GtkTargetEntry drag_types[] =
+        {
+                { "text/uri-list", 0, 0 },
+        };
+
+  static gint n_drag_types = sizeof (drag_types) / sizeof (drag_types [0]);
+
   screen->priv = g_new0 (TerminalScreenPrivate, 1);
   
   screen->priv->term = terminal_widget_new ();
@@ -126,6 +141,17 @@
   g_object_ref (G_OBJECT (screen->priv->term));
   gtk_object_sink (GTK_OBJECT (screen->priv->term));
 
+  gtk_drag_dest_set(GTK_WIDGET (screen->priv->term),  
+			GTK_DEST_DEFAULT_MOTION |
+			GTK_DEST_DEFAULT_HIGHLIGHT |
+			GTK_DEST_DEFAULT_DROP,
+			drag_types, n_drag_types,
+			GDK_ACTION_COPY);
+                
+  g_signal_connect (G_OBJECT (screen->priv->term), "drag_data_received",
+                          G_CALLBACK (terminal_screen_drag_data_received_handler), 
+                          screen);
+
   terminal_widget_match_add (screen->priv->term,
                              "(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?");
   
@@ -1233,6 +1259,42 @@
 }
 
 static void
+terminal_screen_drag_data_received_handler     (GtkWidget *widget, GdkDragContext *context, 
+						gint x, gint y, GtkSelectionData *selection_data, 
+						guint info, guint time,
+                                               	TerminalScreen *screen)
+{
+        GList *list = NULL;
+        GList *file_list = NULL;
+        GList *p = NULL;
+        
+
+        list = gnome_vfs_uri_list_parse (selection_data->data);
+        p = list;
+
+        while (p != NULL)
+        {
+                file_list = g_list_append (file_list, 
+                                gnome_vfs_uri_to_string ((const GnomeVFSURI*)(p->data), 
+                                GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD));
+                p = p->next;
+        }
+        
+        gnome_vfs_uri_list_free (list);
+
+        if (file_list == NULL)
+                return;
+
+        for (p = file_list; p != NULL; p = p->next) {
+		terminal_widget_paste_dropped_data (screen->priv->term, p->data);
+		terminal_widget_paste_dropped_data (screen->priv->term, " ");
+                g_free (p->data);
+        }
+        
+        g_list_free (file_list);
+}
+
+static void
 set_raw_title (TerminalScreen *screen,
                const char     *title)
 {  
diff -ru gnome-terminal-1.9.2/src/terminal-widget-zvt.c gnome-terminal-1.9.2.fer/src/terminal-widget-zvt.c
--- gnome-terminal-1.9.2/src/terminal-widget-zvt.c	Mon Mar 18 02:34:17 2002
+++ gnome-terminal-1.9.2.fer/src/terminal-widget-zvt.c	Fri Apr 12 01:37:28 2002
@@ -675,6 +675,12 @@
 }
 
 void
+terminal_widget_paste_dropped_data (GtkWidget            *widget, gchar *text)
+{
+  zvt_term_writechild (ZVT_TERM (widget), text, strlen(text));
+}
+
+void
 terminal_widget_reset (GtkWidget            *widget,
                        gboolean              also_clear_afterward)
 {
diff -ru gnome-terminal-1.9.2/src/terminal-widget.h gnome-terminal-1.9.2.fer/src/terminal-widget.h
--- gnome-terminal-1.9.2/src/terminal-widget.h	Sun Mar 10 02:19:35 2002
+++ gnome-terminal-1.9.2.fer/src/terminal-widget.h	Fri Apr 12 01:49:51 2002
@@ -94,6 +94,8 @@
                                                        const GdkColor       *palette_entries);
 void       terminal_widget_copy_clipboard             (GtkWidget            *widget);
 void       terminal_widget_paste_clipboard            (GtkWidget            *widget);
+void	   terminal_widget_paste_dropped_data	      (GtkWidget	    *widget,
+						       gchar		    *text);
 void       terminal_widget_reset                      (GtkWidget            *widget,
                                                        gboolean              also_clear_afterward);
 


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