aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@src.gnome.org>2007-12-19 02:38:45 +0800
committerCosimo Cecchi <cosimoc@src.gnome.org>2007-12-19 02:38:45 +0800
commitd5791e21d37596e3592f04951829edf982e036cd (patch)
tree932d4ca83f6e4d98017b82c2607a52365e8fc83a /src
parentb9a140070c403f21637c4713d070c99ad0d05fcb (diff)
downloadgsoc2013-epiphany-d5791e21d37596e3592f04951829edf982e036cd.tar
gsoc2013-epiphany-d5791e21d37596e3592f04951829edf982e036cd.tar.gz
gsoc2013-epiphany-d5791e21d37596e3592f04951829edf982e036cd.tar.bz2
gsoc2013-epiphany-d5791e21d37596e3592f04951829edf982e036cd.tar.lz
gsoc2013-epiphany-d5791e21d37596e3592f04951829edf982e036cd.tar.xz
gsoc2013-epiphany-d5791e21d37596e3592f04951829edf982e036cd.tar.zst
gsoc2013-epiphany-d5791e21d37596e3592f04951829edf982e036cd.zip
Add middle-click-paste for smart bookmarks, as it is for new tab/window
buttons. Close bug #378165. svn path=/trunk/; revision=7784
Diffstat (limited to 'src')
-rw-r--r--src/bookmarks/ephy-bookmark-action.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/bookmarks/ephy-bookmark-action.c b/src/bookmarks/ephy-bookmark-action.c
index 7e0531582..cdbb7c363 100644
--- a/src/bookmarks/ephy-bookmark-action.c
+++ b/src/bookmarks/ephy-bookmark-action.c
@@ -80,6 +80,73 @@ enum
static GObjectClass *parent_class;
+typedef struct
+{
+ GObject *weak_ptr;
+ GtkWidget *entry;
+ EphyLinkFlags flags;
+} ClipboardCtx;
+
+static void
+clipboard_text_received_cb (GtkClipboard *clipboard,
+ const char *text,
+ ClipboardCtx *ctx)
+{
+ if (ctx->weak_ptr != NULL && text != NULL)
+ {
+ /* This is to avoid middle-clicking on a non-empty smart bookmark
+ * triggering another search.
+ */
+ if (strcmp (text, gtk_entry_get_text (GTK_ENTRY (ctx->entry))) != 0)
+ {
+ gtk_entry_set_text (GTK_ENTRY (ctx->entry), text);
+ ephy_bookmark_action_activate (EPHY_BOOKMARK_ACTION (ctx->weak_ptr),
+ ctx->entry, ctx->flags);
+ }
+ }
+
+ if (ctx->weak_ptr != NULL)
+ {
+ GObject **object = &(ctx->weak_ptr);
+ g_object_remove_weak_pointer (G_OBJECT (ctx->weak_ptr),
+ (gpointer *)object);
+ }
+
+ g_slice_free (ClipboardCtx, ctx);
+}
+
+static gboolean
+entry_button_press_event_cb (GtkWidget *entry,
+ GdkEventButton *event,
+ GtkAction *action)
+{
+ if (event->button == 2) /* middle click */
+ {
+ ClipboardCtx *ctx;
+ GObject **object;
+
+ ctx = g_slice_new (ClipboardCtx);
+ ctx->flags = EPHY_LINK_NEW_TAB | EPHY_LINK_JUMP_TO;
+ ctx->entry = entry;
+
+ /* We need to make sure we know if the action is destroyed between
+ * requesting the clipboard contents, and receiving them.
+ */
+
+ ctx->weak_ptr = G_OBJECT (action);
+ object = &(ctx->weak_ptr);
+ g_object_add_weak_pointer (ctx->weak_ptr, (gpointer *)object);
+
+ gtk_clipboard_request_text
+ (gtk_widget_get_clipboard (entry, GDK_SELECTION_PRIMARY),
+ (GtkClipboardTextReceivedFunc) clipboard_text_received_cb,
+ ctx);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static GtkWidget *
create_tool_item (GtkAction *action)
{
@@ -105,6 +172,8 @@ create_tool_item (GtkAction *action)
gtk_entry_set_width_chars (GTK_ENTRY (entry), ENTRY_WIDTH_CHARS);
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
g_object_set_data (G_OBJECT (item), "entry", entry);
+ g_signal_connect (entry, "button-press-event",
+ G_CALLBACK (entry_button_press_event_cb), action);
hbox = gtk_hbox_new (FALSE, 3);
gtk_widget_show (hbox);