]> www.fi.muni.cz Git - evince.git/commitdiff
Update also the primary selection when copying a link address. Fixes bug
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 20 Apr 2008 11:00:14 +0000 (11:00 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Sun, 20 Apr 2008 11:00:14 +0000 (11:00 +0000)
2008-04-20  Carlos Garcia Campos  <carlosgc@gnome.org>

* shell/ev-view-private.h:
* shell/ev-view.[ch]: (ev_view_button_release_event),
(ev_view_finalize), (ev_view_clipboard_copy), (ev_view_copy),
(ev_view_primary_get_cb), (ev_view_primary_clear_cb),
(ev_view_update_primary_selection), (clear_link_selected),
(ev_view_copy_link_address):
* shell/ev-window.c: (ev_view_popup_cmd_copy_link_address):

Update also the primary selection when copying a link
address. Fixes bug #520855.

svn path=/trunk/; revision=3017

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

index 6e6c2cb9cae2fbdc85122e90dc0debde5b5715c5..4ecf581d9a154599b8fdbf1c4a56b3d5bd313c26 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2008-04-20  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * shell/ev-view-private.h:
+       * shell/ev-view.[ch]: (ev_view_button_release_event),
+       (ev_view_finalize), (ev_view_clipboard_copy), (ev_view_copy),
+       (ev_view_primary_get_cb), (ev_view_primary_clear_cb),
+       (ev_view_update_primary_selection), (clear_link_selected),
+       (ev_view_copy_link_address):
+       * shell/ev-window.c: (ev_view_popup_cmd_copy_link_address):
+
+       Update also the primary selection when copying a link
+       address. Fixes bug #520855.
+       
 2008-04-19  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * libdocument/ev-document-factory.c: (get_document_from_uri):
index c36cd57bd421633fb1f2c3f0fd7e1f75c78f1bde..3e72e82af6482a783cdc285ce76c31b5e39ea619 100644 (file)
@@ -161,6 +161,9 @@ struct _EvView {
        EvViewSelectionMode selection_mode;
        SelectionInfo selection_info;
 
+       /* Copy link address selection */
+       EvLinkAction *link_selected;
+
        /* Image DND */
        ImageDNDInfo image_dnd_info;
 
index f984396c861ea96a6f64d9c197dc14820dc07d0b..d107df965b19b1d73577b63918a2479c70bed4e8 100644 (file)
@@ -320,6 +320,7 @@ static void       compute_selections                         (EvView
                                                              GdkPoint           *start,
                                                              GdkPoint           *stop);
 static void       clear_selection                            (EvView             *view);
+static void       clear_link_selected                        (EvView             *view);
 static void       selection_free                             (EvViewSelection    *selection);
 static char*      get_selected_text                          (EvView             *ev_view);
 static void       ev_view_primary_get_cb                     (GtkClipboard       *clipboard,
@@ -3178,6 +3179,7 @@ ev_view_button_release_event (GtkWidget      *widget,
        }
 
        if (view->selection_info.selections) {
+               clear_link_selected (view);
                ev_view_update_primary_selection (view);
                
                if (view->selection_info.in_drag) {
@@ -3823,6 +3825,7 @@ ev_view_finalize (GObject *object)
        g_free (view->find_status);
 
        clear_selection (view);
+       clear_link_selected (view);
 
        if (view->image_dnd_info.image)
                g_object_unref (view->image_dnd_info.image);
@@ -5746,19 +5749,27 @@ get_selected_text (EvView *view)
        return normalized_text;
 }
 
+static void
+ev_view_clipboard_copy (EvView      *view,
+                       const gchar *text)
+{
+       GtkClipboard *clipboard;
+
+       clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view),
+                                             GDK_SELECTION_CLIPBOARD);
+       gtk_clipboard_set_text (clipboard, text, -1);
+}
+
 void
 ev_view_copy (EvView *ev_view)
 {
-       GtkClipboard *clipboard;
        char *text;
 
        if (!EV_IS_SELECTION (ev_view->document))
                return;
 
        text = get_selected_text (ev_view);
-       clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view),
-                                             GDK_SELECTION_CLIPBOARD);
-       gtk_clipboard_set_text (clipboard, text, -1);
+       ev_view_clipboard_copy (ev_view, text);
        g_free (text);
 }
 
@@ -5769,15 +5780,20 @@ ev_view_primary_get_cb (GtkClipboard     *clipboard,
                        gpointer          data)
 {
        EvView *ev_view = EV_VIEW (data);
-       char *text;
 
-       if (!EV_IS_SELECTION (ev_view->document))
-               return;
-
-       text = get_selected_text (ev_view);
-       if (text) {
-               gtk_selection_data_set_text (selection_data, text, -1);
-               g_free (text);
+       if (ev_view->link_selected) {
+               gtk_selection_data_set_text (selection_data,
+                                            ev_link_action_get_uri (ev_view->link_selected),
+                                            -1);
+       } else if (EV_IS_SELECTION (ev_view->document) &&
+                  ev_view->selection_info.selections) {
+               gchar *text;
+               
+               text = get_selected_text (ev_view);
+               if (text) {
+                       gtk_selection_data_set_text (selection_data, text, -1);
+                       g_free (text);
+               }
        }
 }
 
@@ -5788,6 +5804,7 @@ ev_view_primary_clear_cb (GtkClipboard *clipboard,
        EvView *view = EV_VIEW (data);
 
        clear_selection (view);
+       clear_link_selected (view);
 }
 
 static void
@@ -5798,7 +5815,7 @@ ev_view_update_primary_selection (EvView *ev_view)
        clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view),
                                               GDK_SELECTION_PRIMARY);
 
-       if (ev_view->selection_info.selections) {
+       if (ev_view->selection_info.selections || ev_view->link_selected) {
                if (!gtk_clipboard_set_with_owner (clipboard,
                                                   clipboard_targets,
                                                   G_N_ELEMENTS (clipboard_targets),
@@ -5812,6 +5829,27 @@ ev_view_update_primary_selection (EvView *ev_view)
        }
 }
 
+static void
+clear_link_selected (EvView *view)
+{
+       if (view->link_selected) {
+               g_object_unref (view->link_selected);
+               view->link_selected = NULL;
+       }
+}
+
+void
+ev_view_copy_link_address (EvView       *view,
+                          EvLinkAction *action)
+{
+       clear_link_selected (view);
+       
+       ev_view_clipboard_copy (view, ev_link_action_get_uri (action));
+       
+       view->link_selected = g_object_ref (action);
+       ev_view_update_primary_selection (view);
+}
+
 /*** Cursor operations ***/
 
 static GdkCursor *
index dd8d1df141f8909913da2ea15c1461b01724df63..0c6d608c2297f963a5e57641a3e2e5999a5e7351 100644 (file)
@@ -75,6 +75,8 @@ void          ev_view_set_loading       (EvView         *view,
                                           gboolean        loading);
 /* Clipboard */
 void           ev_view_copy              (EvView         *view);
+void            ev_view_copy_link_address (EvView         *view,
+                                          EvLinkAction   *action);
 void           ev_view_select_all        (EvView         *view);
 gboolean        ev_view_get_has_selection (EvView         *view);
 
index 1f78e875544770618170f3f72794a6a4ee18f1de..dd05d662d2b88ab2f871f6d8cd9c48594e8f028f 100644 (file)
@@ -4797,19 +4797,14 @@ ev_view_popup_cmd_open_link_new_window (GtkAction *action, EvWindow *window)
 static void
 ev_view_popup_cmd_copy_link_address (GtkAction *action, EvWindow *window)
 {
-       GtkClipboard *clipboard;
        EvLinkAction *ev_action;
-       const gchar *uri;
 
        ev_action = ev_link_get_action (window->priv->link);
        if (!ev_action)
                return;
 
-       uri = ev_link_action_get_uri (ev_action);
-
-       clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
-                                             GDK_SELECTION_CLIPBOARD);
-       gtk_clipboard_set_text (clipboard, uri, -1);
+       ev_view_copy_link_address (EV_VIEW (window->priv->view),
+                                  ev_action);
 }