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



commit 761d2fab37dffac086e8ba1df69c8ac499ec90e8
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 6ffd1aa..8dd3209 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -206,15 +206,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]