GNOME #571794

Index: epiphany-2.24.3/src/bookmarks/ephy-bookmark-action.c
===================================================================
--- epiphany-2.24.3.orig/src/bookmarks/ephy-bookmark-action.c	2008-08-04 15:21:51.000000000 +0200
+++ epiphany-2.24.3/src/bookmarks/ephy-bookmark-action.c	2009-02-20 13:34:30.388138066 +0100
@@ -72,6 +72,7 @@ typedef struct
 	GObject *weak_ptr;
 	GtkWidget *entry;
 	EphyLinkFlags flags;
+	gboolean activate;
 } ClipboardCtx;
 
 G_DEFINE_TYPE (EphyBookmarkAction, ephy_bookmark_action, EPHY_TYPE_LINK_ACTION)
@@ -81,12 +82,12 @@ clipboard_text_received_cb (GtkClipboard
 			    const char *text,
 			    ClipboardCtx *ctx)
 {
-	if (ctx->weak_ptr != NULL && text != NULL)
+	if (ctx->weak_ptr != NULL && (ctx->activate || 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)
+		if (text != NULL && strcmp (text, gtk_entry_get_text (GTK_ENTRY (ctx->entry))) != 0)
 		{
 			gtk_entry_set_text (GTK_ENTRY (ctx->entry), text);
 		}
@@ -94,6 +95,11 @@ clipboard_text_received_cb (GtkClipboard
 
 	if (ctx->weak_ptr != NULL)
 	{
+		if (ctx->activate)
+		{
+			ephy_bookmark_action_activate (EPHY_BOOKMARK_ACTION (ctx->weak_ptr),
+			                               ctx->entry, ctx->flags);
+		}
 		GObject **object = &(ctx->weak_ptr);
 		g_object_remove_weak_pointer (G_OBJECT (ctx->weak_ptr), 
 					      (gpointer *)object);
@@ -102,6 +108,33 @@ clipboard_text_received_cb (GtkClipboard
 	g_slice_free (ClipboardCtx, ctx);
 }
 
+static void
+request_clipboard (GtkWidget *entry,
+                   EphyBookmarkAction *action,
+                   gboolean activate)
+{
+	ClipboardCtx *ctx;
+	GObject **object;
+
+	ctx = g_slice_new (ClipboardCtx);
+	ctx->flags = EPHY_LINK_NEW_TAB | EPHY_LINK_JUMP_TO;
+	ctx->entry = entry;
+	ctx->activate = activate;
+
+	/* 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);
+}
+
 static gboolean
 entry_button_press_event_cb (GtkWidget *entry,
 			     GdkEventButton *event,
@@ -109,25 +142,7 @@ entry_button_press_event_cb (GtkWidget *
 {
 	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);
+		request_clipboard (entry, EPHY_BOOKMARK_ACTION (action), FALSE);
 		return TRUE;
 	}
 
@@ -384,6 +399,7 @@ activate_cb (GtkWidget *widget,
 	     EphyBookmarkAction *action)
 {
 	gboolean control = FALSE;
+	gboolean is_middle_click;
 	GdkEvent *event;
 
 	event = gtk_get_current_event ();
@@ -394,12 +410,30 @@ activate_cb (GtkWidget *widget,
 		{
 			control = (event->key.state & gtk_accelerator_get_default_mod_mask ()) == GDK_CONTROL_MASK;
 		}
-			
 		gdk_event_free (event);
 	}
 
+	/* If we are clicking on the button, use the entry instead */
+	if (!GTK_IS_EDITABLE (widget))
+	{
+		GtkWidget *otherwidget = gtk_widget_get_parent (widget);
+		if (otherwidget)
+			otherwidget = gtk_widget_get_parent (otherwidget);
+		if (otherwidget)
+			otherwidget = GTK_WIDGET (g_object_get_data (G_OBJECT (otherwidget), "entry"));
+		if (otherwidget)
+			widget = otherwidget;
+	}
+
+	is_middle_click = ephy_gui_is_middle_click ();
+	if (is_middle_click && GTK_IS_EDITABLE (widget))
+	{
+		request_clipboard (widget, action, TRUE);
+		return;
+	}
+
 	ephy_bookmark_action_activate
-	  (action, widget, (control || ephy_gui_is_middle_click ()) ? EPHY_LINK_NEW_TAB : 0);
+	  (action, widget, (control || is_middle_click) ? EPHY_LINK_NEW_TAB : 0);
 }
 
 static gboolean
