[epiphany/gnome-3-18] location-entry: Encode URI before copy/paste



commit 6a36029a1212d047861d4a00425a2558f086bbc5
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Sat Feb 6 23:01:23 2016 -0600

    location-entry: Encode URI before copy/paste
    
    The location entry is currently the only place in our UI where it is
    possible to copy a decoded URI. This is basically never what the user
    wants.
    
    I am getting tired of accidentally pasting broken URIs like
    https://build.webkit.org/results/GTK Linux 64-bit Release
    (Tests)/r196216 (13627)/results.html. URIs should be encoded before
    stored in the clipboard. Now I can copy
    https://build.webkit.org/results/GTK%20Linux%2064-bit%20Release%20(Tests)/r196216%20(13627)/results.html
    instead as nature intended.
    
    Of course, if only part of the entry is selected, then it's not a full
    URI and should not be messed with; in this case, just copy it raw.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761660

 lib/widgets/ephy-location-entry.c |   43 +++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 629be35..fa2e863 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -210,15 +210,58 @@ ephy_location_entry_get_preferred_width (GtkWidget       *widget,
 }
 
 static void
+ephy_location_entry_copy_clipboard (GtkEntry *entry)
+{
+       char *text;
+       gint start;
+       gint end;
+
+       if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
+               return;
+
+       text = gtk_editable_get_chars (GTK_EDITABLE (entry), start, end);
+
+       if (start == 0)
+       {
+               char *tmp = text;
+               text = g_uri_escape_string (tmp,
+                                           G_URI_RESERVED_CHARS_ALLOWED_IN_PATH,
+                                           FALSE /* allow_utf8 */);
+               g_free (tmp);
+       }
+
+       gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
+                                                         GDK_SELECTION_CLIPBOARD),
+                                                         text, -1);
+       g_free (text);
+}
+
+static void
+ephy_location_entry_cut_clipboard (GtkEntry *entry)
+{
+       if (!gtk_editable_get_editable (GTK_EDITABLE (entry)))
+       {
+               gtk_widget_error_bell (GTK_WIDGET (entry));
+               return;
+       }
+
+       ephy_location_entry_copy_clipboard (entry);
+       gtk_editable_delete_selection (GTK_EDITABLE (entry));
+}
+
+static void
 ephy_location_entry_class_init (EphyLocationEntryClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+       GtkEntryClass *entry_class = GTK_ENTRY_CLASS (klass);
 
        object_class->get_property = ephy_location_entry_get_property;
        object_class->set_property = ephy_location_entry_set_property;
        object_class->finalize = ephy_location_entry_finalize;
        widget_class->get_preferred_width = ephy_location_entry_get_preferred_width;
+       entry_class->copy_clipboard = ephy_location_entry_copy_clipboard;
+       entry_class->cut_clipboard = ephy_location_entry_cut_clipboard;
 
        /**
        * EphyLocationEntry:location:


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