From fe8a90e5ecdc21069bc6617f07b7ab12a5a4a012 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sun, 18 Jan 2009 15:00:58 +0000 Subject: Bug 558084 – simplify drag data handling svn path=/trunk/; revision=3351 --- diff --git a/ChangeLog b/ChangeLog index 7102a73..530c485 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2009-01-18 Christian Persch + + * libview/ev-view.c: (ev_view_drag_data_get), + (ev_view_drag_motion), (ev_view_update_primary_selection), + (clear_link_selected): + * shell/ev-sidebar-attachments.c: + (ev_sidebar_attachments_drag_data_get), + (ev_sidebar_attachments_get_property), + (ev_sidebar_attachments_init): + * shell/ev-window.c: Update drag handling code to use the + gtk_*_add_uri_targets and gtk_*_add_text_targets targets instead of + hardcoding the targets lists. Bug #558084. + 2009-01-18 Carlos Garcia Campos * libdocument/Makefile.am: diff --git a/libview/ev-view.c b/libview/ev-view.c index e6fb3ce..5acce47 100644 --- a/libview/ev-view.c +++ b/libview/ev-view.c @@ -72,21 +72,6 @@ enum { TARGET_DND_IMAGE }; -enum { - TARGET_STRING, - TARGET_TEXT, - TARGET_COMPOUND_TEXT, - TARGET_UTF8_STRING, - TARGET_TEXT_BUFFER_CONTENTS -}; - -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 guint signals[N_SIGNALS]; typedef enum { @@ -2752,7 +2737,7 @@ ev_view_drag_data_get (GtkWidget *widget, if (view->image_dnd_info.image) { GdkPixbuf *pixbuf; const gchar *tmp_uri; - gchar **uris; + gchar **uris[2]; ev_document_doc_mutex_lock (); pixbuf = ev_document_images_get_image (EV_DOCUMENT_IMAGES (view->document), @@ -2762,13 +2747,9 @@ ev_view_drag_data_get (GtkWidget *widget, tmp_uri = ev_image_save_tmp (view->image_dnd_info.image, pixbuf); g_object_unref (pixbuf); - uris = g_new0 (gchar *, 2); uris[0] = (gchar *)tmp_uri; - + uris[1] = NULL; gtk_selection_data_set_uris (selection_data, uris); - - /* g_free instead of g_strfreev since tmp_uri is const */ - g_free (uris); } } } @@ -5625,13 +5606,23 @@ ev_view_update_primary_selection (EvView *ev_view) GDK_SELECTION_PRIMARY); if (ev_view->selection_info.selections || ev_view->link_selected) { + GtkTargetList *target_list; + GtkTargetEntry *targets; + int n_targets; + + target_list = gtk_target_list_new (NULL, 0); + gtk_target_list_add_text_targets (target_list, 0); + targets = gtk_target_table_new_from_list (target_list, &n_targets); + gtk_target_list_unref (target_list); + if (!gtk_clipboard_set_with_owner (clipboard, - clipboard_targets, - G_N_ELEMENTS (clipboard_targets), + targets, n_targets, ev_view_primary_get_cb, ev_view_primary_clear_cb, G_OBJECT (ev_view))) ev_view_primary_clear_cb (clipboard, ev_view); + + gtk_target_table_free (targets, n_targets); } else { if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (ev_view)) gtk_clipboard_clear (clipboard); diff --git a/shell/ev-sidebar-attachments.c b/shell/ev-sidebar-attachments.c index 44c027f..47549f6 100644 --- a/shell/ev-sidebar-attachments.c +++ b/shell/ev-sidebar-attachments.c @@ -55,10 +55,6 @@ enum { N_SIGNALS }; -static const GtkTargetEntry drag_targets[] = { - { "text/uri-list", 0, 0 } -}; - static guint signals[N_SIGNALS]; struct _EvSidebarAttachmentsPrivate { @@ -398,15 +394,15 @@ ev_sidebar_attachments_drag_data_get (GtkWidget *widget, gpointer user_data) { EvSidebarAttachments *ev_attachbar = EV_SIDEBAR_ATTACHMENTS (user_data); - GString *uri_list; - gchar *uris = NULL; GList *selected = NULL, *l; + GPtrArray *uris; + char **uri_list; selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (ev_attachbar->priv->icon_view)); if (!selected) return; - uri_list = g_string_new (NULL); + uris = g_ptr_array_new (); for (l = selected; l && l->data; l = g_list_next (l)) { EvAttachment *attachment; @@ -434,9 +430,7 @@ ev_sidebar_attachments_drag_data_get (GtkWidget *widget, gchar *uri; uri = g_file_get_uri (file); - g_string_append (uri_list, uri); - g_string_append_c (uri_list, '\n'); - g_free (uri); + g_ptr_array_add (uris, uri); } if (error) { @@ -449,15 +443,10 @@ ev_sidebar_attachments_drag_data_get (GtkWidget *widget, g_object_unref (attachment); } - uris = g_string_free (uri_list, FALSE); - - if (uris) { - gtk_selection_data_set (data, - data->target, - 8, - (guchar *)uris, - strlen (uris)); - } + g_ptr_array_add (uris, NULL); /* NULL-terminate */ + uri_list = (char **) g_ptr_array_free (uris, FALSE); + gtk_selection_data_set_uris (data, uri_list); + g_strfreev (uri_list); g_list_free (selected); } @@ -545,6 +534,12 @@ ev_sidebar_attachments_class_init (EvSidebarAttachmentsClass *ev_attachbar_class static void ev_sidebar_attachments_init (EvSidebarAttachments *ev_attachbar) { +#if !GTK_CHECK_VERSION (2, 15, 0) + const GtkTargetEntry drag_targets[] = { + { "text/uri-list", 0, 0 } + }; +#endif + GtkWidget *swindow; ev_attachbar->priv = EV_SIDEBAR_ATTACHMENTS_GET_PRIVATE (ev_attachbar); @@ -594,12 +589,21 @@ ev_sidebar_attachments_init (EvSidebarAttachments *ev_attachbar) g_object_unref); /* Drag and Drop */ +#if GTK_CHECK_VERSION (2, 15, 0) + gtk_icon_view_enable_model_drag_source ( + GTK_ICON_VIEW (ev_attachbar->priv->icon_view), + GDK_BUTTON1_MASK, + NULL, 0, + GDK_ACTION_COPY); + gtk_drag_source_add_uri_targets (ev_attachbar->priv->icon_view); +#else gtk_icon_view_enable_model_drag_source ( GTK_ICON_VIEW (ev_attachbar->priv->icon_view), GDK_BUTTON1_MASK, drag_targets, G_N_ELEMENTS (drag_targets), GDK_ACTION_COPY); +#endif g_signal_connect (G_OBJECT (ev_attachbar->priv->icon_view), "drag-data-get", diff --git a/shell/ev-window.c b/shell/ev-window.c index abfcae2..54db149 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -242,10 +242,6 @@ static const gchar *document_print_settings[] = { GTK_PRINT_SETTINGS_OUTPUT_URI }; -static const GtkTargetEntry ev_window_drop_targets[] = { - { "text/uri-list", 0, 0 } -}; - static void ev_window_update_actions (EvWindow *ev_window); static void ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar, GParamSpec *pspec, @@ -6265,9 +6261,9 @@ ev_window_init (EvWindow *ev_window) /* Drag and Drop */ gtk_drag_dest_set (GTK_WIDGET (ev_window), GTK_DEST_DEFAULT_ALL, - ev_window_drop_targets, - G_N_ELEMENTS (ev_window_drop_targets), + NULL, 0, GDK_ACTION_COPY); + gtk_drag_dest_add_uri_targets (GTK_WIDGET (ev_window)); } /** -- cgit v0.9.1