[epiphany] Make text and URLs dropped in location entry clear entry and load new URL



commit 2f91a8561c8ac98c3b088a14bdd6e6d2ffb5ba59
Author: William Jon McCann <william jon mccann gmail com>
Date:   Fri Dec 13 11:16:21 2013 -0500

    Make text and URLs dropped in location entry clear entry and load new URL
    
    https://bugzilla.gnome.org/show_bug.cgi?id=171180

 lib/widgets/ephy-location-entry.c |    8 +++++-
 src/ephy-location-controller.c    |   51 +++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletions(-)
---
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 8c955b7..0814acc 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -898,6 +898,12 @@ ephy_location_entry_construct_contents (EphyLocationEntry *lentry)
                                         GTK_ENTRY_ICON_PRIMARY,
                                         _("Drag and drop this icon to create a link to this page"));
 
+       gtk_drag_dest_set (entry,
+                          GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
+                          url_drag_types,
+                          G_N_ELEMENTS (url_drag_types),
+                          GDK_ACTION_MOVE | GDK_ACTION_COPY);
+
        g_object_connect (entry,
                          "signal::icon-press", G_CALLBACK (icon_button_press_event_cb), lentry,
                          "signal::populate-popup", G_CALLBACK (entry_populate_popup_cb), lentry,
@@ -907,7 +913,7 @@ ephy_location_entry_construct_contents (EphyLocationEntry *lentry)
                          "signal::drag-drop", G_CALLBACK (entry_drag_drop_cb), lentry,
                          "signal::drag-data-get", G_CALLBACK (favicon_drag_data_get_cb), lentry,
                          NULL);
-                         
+
        g_signal_connect_after (entry, "key-press-event",
                                G_CALLBACK (entry_key_press_after_cb), lentry);
        g_signal_connect_after (entry, "activate",
diff --git a/src/ephy-location-controller.c b/src/ephy-location-controller.c
index a1884c4..7ac778d 100644
--- a/src/ephy-location-controller.c
+++ b/src/ephy-location-controller.c
@@ -27,6 +27,7 @@
 #include "ephy-embed-container.h"
 #include "ephy-embed-utils.h"
 #include "ephy-link.h"
+#include "ephy-dnd.h"
 #include "ephy-location-entry.h"
 #include "ephy-shell.h"
 
@@ -136,6 +137,53 @@ action_activated_cb (GtkEntryCompletion *completion,
 }
 
 static void
+entry_drag_data_received_cb (GtkWidget *widget,
+                            GdkDragContext *context,
+                            gint x, gint y,
+                            GtkSelectionData *selection_data,
+                            guint info,
+                            guint time,
+                            EphyLocationController *controller)
+{
+       GtkEntry *entry;
+       GdkAtom url_type;
+       GdkAtom text_type;
+       const guchar *sel_data;
+
+       sel_data = gtk_selection_data_get_data (selection_data);
+
+       url_type = gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE);
+       text_type = gdk_atom_intern (EPHY_DND_TEXT_TYPE, FALSE);
+
+       if (gtk_selection_data_get_length (selection_data) <= 0 || sel_data == NULL)
+               return;
+
+       entry = GTK_ENTRY (widget);
+
+       if (gtk_selection_data_get_target (selection_data) == url_type)
+       {
+               char **uris;
+
+               uris = g_uri_list_extract_uris ((char *)sel_data);
+               if (uris != NULL && uris[0] != NULL && *uris[0] != '\0')
+               {
+                       gtk_entry_set_text (entry, (char *)uris[0]);
+                       ephy_link_open (EPHY_LINK (controller),
+                                       uris[0],
+                                       NULL,
+                                       ephy_link_flags_from_current_event ());
+               }
+               g_strfreev (uris);
+       } else if (gtk_selection_data_get_target (selection_data) == text_type) {
+               gtk_entry_set_text (entry, (const gchar *)sel_data);
+               ephy_link_open (EPHY_LINK (controller),
+                               (const gchar *)sel_data,
+                               NULL,
+                               ephy_link_flags_from_current_event ());
+       }
+}
+
+static void
 entry_activate_cb (GtkEntry *entry,
                   EphyLocationController *controller)
 {
@@ -399,6 +447,9 @@ ephy_location_controller_constructed (GObject *object)
                                priv->location_entry, "show-lock",
                                G_BINDING_SYNC_CREATE);
 
+       g_signal_connect_object (widget, "drag-data-received",
+                                G_CALLBACK (entry_drag_data_received_cb),
+                                controller, 0);
        g_signal_connect_object (widget, "activate",
                                 G_CALLBACK (entry_activate_cb),
                                 controller, 0);


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