]> www.fi.muni.cz Git - evince.git/commitdiff
Move view drag and drop stuff to ev-view.
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 7 Jan 2007 12:20:03 +0000 (12:20 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Sun, 7 Jan 2007 12:20:03 +0000 (12:20 +0000)
2007-01-07  Carlos Garcia Campos  <carlosgc@gnome.org>
* shell/ev-window.c: (drag_data_received_cb), (ev_window_init):
* shell/ev-view.c: (ev_view_drag_data_received), (ev_view_class_init),
(ev_view_init):
Move view drag and drop stuff to ev-view.

svn path=/trunk/; revision=2192

ChangeLog
shell/ev-view.c
shell/ev-window.c

index c9e54bc01986d54c5998d22c0d3602288ffa90ec..b37077a999aa83b1f3d8a42d69931f1998812793 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-01-07  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * shell/ev-window.c: (drag_data_received_cb), (ev_window_init):
+       * shell/ev-view.c: (ev_view_drag_data_received), (ev_view_class_init),
+       (ev_view_init):
+
+       Move view drag and drop stuff to ev-view.
+
 2007-01-05  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-pixbuf-cache.c: (clear_job_selection):
index d83f5724b32d1c51892b843ba70a6b471c71ac52..f353f4739862440afea1867b4fda71bff77bf03d 100644 (file)
@@ -43,6 +43,7 @@
 #include "ev-page-cache.h"
 #include "ev-pixbuf-cache.h"
 #include "ev-tooltip.h"
+#include "ev-application.h"
 
 #define EV_VIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_VIEW, EvViewClass))
 #define EV_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EV_TYPE_VIEW))
@@ -79,13 +80,17 @@ enum {
        TARGET_TEXT_BUFFER_CONTENTS
 };
 
-static const GtkTargetEntry targets[] = {
+static const GtkTargetEntry clipboard_targets[] = {
        { "STRING", 0, TARGET_STRING },
        { "TEXT",   0, TARGET_TEXT },
        { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT },
        { "UTF8_STRING", 0, TARGET_UTF8_STRING },
 };
 
+static const GtkTargetEntry view_drop_targets[] = {
+       { "text/uri-list", 0, 0 }
+};
+
 static guint signals[N_SIGNALS];
 
 typedef enum {
@@ -1687,7 +1692,6 @@ ev_view_realize (GtkWidget *widget)
 
        GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
 
-
        attributes.window_type = GDK_WINDOW_CHILD;
        attributes.wclass = GDK_INPUT_OUTPUT;
        attributes.visual = gtk_widget_get_visual (widget);
@@ -1960,6 +1964,7 @@ ev_view_button_press_event (GtkWidget      *widget,
        return FALSE;
 }
 
+/*** Drag and Drop ***/
 static void
 ev_view_drag_data_get (GtkWidget        *widget,
                       GdkDragContext   *context,
@@ -1981,6 +1986,39 @@ ev_view_drag_data_get (GtkWidget        *widget,
        }
 }
 
+static void
+ev_view_drag_data_received (GtkWidget          *widget,
+                           GdkDragContext     *context,
+                           gint                x,
+                           gint                y,
+                           GtkSelectionData   *selection_data,
+                           guint               info,
+                           guint               time)
+{
+       gchar  **uris;
+       gint     i = 0;
+       GSList  *uri_list = NULL;
+
+       uris = gtk_selection_data_get_uris (selection_data);
+       if (!uris) {
+               gtk_drag_finish (context, FALSE, FALSE, time);
+               return;
+       }
+
+       for (i = 0; uris[i]; i++) {
+               uri_list = g_slist_prepend (uri_list, (gpointer) uris[i]);
+       }
+       
+       ev_application_open_uri_list (EV_APP, uri_list,
+                                     gtk_widget_get_screen (widget),
+                                     0);
+       gtk_drag_finish (context, TRUE, FALSE, time);
+       
+       g_strfreev (uris);
+       g_slist_free (uri_list);
+}
+
+
 static gboolean
 selection_update_idle_cb (EvView *view)
 {
@@ -2965,6 +3003,7 @@ ev_view_class_init (EvViewClass *class)
        widget_class->leave_notify_event = ev_view_leave_notify_event;
        widget_class->style_set = ev_view_style_set;
        widget_class->drag_data_get = ev_view_drag_data_get;
+       widget_class->drag_data_received = ev_view_drag_data_received;
        widget_class->popup_menu = ev_view_popup_menu;
        gtk_object_class->destroy = ev_view_destroy;
 
@@ -3132,6 +3171,12 @@ ev_view_init (EvView *view)
        view->sizing_mode = EV_SIZING_FIT_WIDTH;
        view->pending_scroll = SCROLL_TO_KEEP_POSITION;
        view->jump_to_find_result = TRUE;
+
+       gtk_drag_dest_set (GTK_WIDGET (view),
+                          GTK_DEST_DEFAULT_ALL,
+                          view_drop_targets,
+                          G_N_ELEMENTS (view_drop_targets),
+                          GDK_ACTION_COPY);
 }
 
 /*** Callbacks ***/
@@ -4502,8 +4547,8 @@ ev_view_update_primary_selection (EvView *ev_view)
 
        if (ev_view->selection_info.selections) {
                if (!gtk_clipboard_set_with_owner (clipboard,
-                                                  targets,
-                                                  G_N_ELEMENTS (targets),
+                                                  clipboard_targets,
+                                                  G_N_ELEMENTS (clipboard_targets),
                                                   ev_view_primary_get_cb,
                                                   ev_view_primary_clear_cb,
                                                   G_OBJECT (ev_view)))
index ce956b97c5b5f650af08676ba7a3fc43e9712891..ec979874bdba626c640959973a1e75d2e7f18358 100644 (file)
@@ -188,11 +188,6 @@ struct _EvWindowPrivate {
 #endif
 };
 
-static const GtkTargetEntry ev_drop_types[] = {
-       { "text/uri-list", 0, 0 }
-};
-
-
 #define EV_WINDOW_GET_PRIVATE(object) \
        (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
 
@@ -3864,35 +3859,6 @@ static const GtkActionEntry attachment_popup_entries [] = {
          NULL, G_CALLBACK (ev_attachment_popup_cmd_save_attachment_as) },
 };
 
-static void
-drag_data_received_cb (GtkWidget *widget, GdkDragContext *context,
-                      gint x, gint y, GtkSelectionData *selection_data,
-                      guint info, guint time, gpointer gdata)
-{
-       GList  *uri_list = NULL;
-       GSList *uris = NULL;
-       gchar  *uri;
-
-       uri_list = gnome_vfs_uri_list_parse ((gchar *) selection_data->data);
-
-       if (uri_list) {
-               while (uri_list) {
-                       uri = gnome_vfs_uri_to_string (uri_list->data, GNOME_VFS_URI_HIDE_NONE);
-                       uris = g_slist_append (uris, (gpointer) uri);
-                       
-                       uri_list = g_list_next (uri_list);
-               }
-
-               gnome_vfs_uri_list_free (uri_list);
-               
-               ev_application_open_uri_list (EV_APP, uris,
-                                             gtk_widget_get_screen (widget),
-                                             0);
-               
-               g_slist_free (uris);
-       }
-}
-
 static void
 activate_link_cb (EvPageAction *page_action, EvLink *link, EvWindow *window)
 {
@@ -4669,19 +4635,7 @@ ev_window_init (EvWindow *ev_window)
        /* Give focus to the document view */
        gtk_widget_grab_focus (ev_window->priv->view);
 
-       /* Drag and Drop */
-       gtk_drag_dest_unset (GTK_WIDGET (ev_window->priv->view));
-       gtk_drag_dest_set (GTK_WIDGET (ev_window->priv->view),
-                          GTK_DEST_DEFAULT_ALL,
-                          ev_drop_types,
-                          sizeof (ev_drop_types) / sizeof (ev_drop_types[0]),
-                          GDK_ACTION_COPY);
-       g_signal_connect_swapped (G_OBJECT (ev_window->priv->view), "drag-data-received",
-                                 G_CALLBACK (drag_data_received_cb),
-                                 ev_window);
-
        /* Set it user interface params */
-
        ev_window_setup_recent (ev_window);
 
        setup_chrome_from_metadata (ev_window);