[epiphany] e-window: add a smarter CopyEmailAddress action



commit 997b046b63c66566561402cfafc6d0a25322a02b
Author: Diego Escalante Urrelo <diegoe igalia com>
Date:   Mon Dec 10 09:21:19 2012 -0500

    e-window: add a smarter CopyEmailAddress action
    
    It omits the mailto: in mail links and has a different string in the
    context menu, to make this clear.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688166

 src/ephy-window.c             |   24 ++++++++++++++++++++++--
 src/popup-commands.c          |    4 ++++
 src/resources/epiphany-ui.xml |    1 +
 3 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index adb7e95..4b45989 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -240,6 +240,8 @@ static const GtkActionEntry ephy_popups_entries [] = {
 	  NULL, NULL, G_CALLBACK (popup_cmd_bookmark_link) },
 	{ "CopyLinkAddress", NULL, N_("_Copy Link Address"), NULL,
 	  NULL, G_CALLBACK (popup_cmd_copy_link_address) },
+	{ "CopyEmailAddress", NULL, N_("_Copy E-mail Address"), NULL,
+	  NULL, G_CALLBACK (popup_cmd_copy_link_address) },
 
 	/* Images. */
 
@@ -1920,8 +1922,17 @@ populate_context_menu (WebKitWebView *web_view,
 			add_action_to_context_menu (context_menu,
 						    priv->popups_action_group, "BookmarkLink");
 		}
-		add_action_to_context_menu (context_menu,
-					    priv->popups_action_group, "CopyLinkAddress");
+
+		if (g_str_has_prefix (uri, "mailto:";))
+		{
+			add_action_to_context_menu (context_menu,
+						    priv->popups_action_group, "CopyEmailAddress");
+		}
+		else
+		{
+			add_action_to_context_menu (context_menu,
+						    priv->popups_action_group, "CopyLinkAddress");
+		}
 	}
 	else if (webkit_hit_test_result_context_is_editable (hit_test_result))
 	{
@@ -2021,6 +2032,7 @@ show_embed_popup (EphyWindow *window,
 	guint context;
 	const char *popup;
 	gboolean can_open_in_new;
+	gboolean mailto;
 	GtkWidget *widget;
 	guint button;
 	char *uri;
@@ -2028,6 +2040,7 @@ show_embed_popup (EphyWindow *window,
 
 	g_object_get (hit_test_result, "link-uri", &uri, NULL);
 	can_open_in_new = uri && ephy_embed_utils_address_has_web_scheme (uri);
+	mailto = g_str_has_prefix (uri, "mailto:";);
 	g_free (uri);
 
 	g_object_get (hit_test_result, "context", &context, NULL);
@@ -2036,6 +2049,13 @@ show_embed_popup (EphyWindow *window,
 
 	if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK)
 	{
+		GtkAction *action;
+
+		action = gtk_action_group_get_action (priv->popups_action_group, "CopyEmailAddress");
+		gtk_action_set_visible (action, mailto);
+		action = gtk_action_group_get_action (priv->popups_action_group, "CopyLinkAddress");
+		gtk_action_set_visible (action, !mailto);
+
 		popup = "/EphyLinkPopup";
 		update_edit_actions_sensitivity (window, TRUE);
 	}
diff --git a/src/popup-commands.c b/src/popup-commands.c
index c917788..0380e86 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -204,6 +204,10 @@ popup_cmd_copy_link_address (GtkAction *action,
 	{
 		ephy_embed_event_get_property (event, "link-uri", &value);
 		address = g_value_get_string (&value);
+
+		if (g_str_has_prefix (address, "mailto:";))
+			address = address + 7;
+
 		popup_cmd_copy_to_clipboard (window, address);
 		g_value_unset (&value);
 	}
diff --git a/src/resources/epiphany-ui.xml b/src/resources/epiphany-ui.xml
index 4afa856..976dddc 100644
--- a/src/resources/epiphany-ui.xml
+++ b/src/resources/epiphany-ui.xml
@@ -49,6 +49,7 @@
 		<menuitem name="DownloadLinkAsLP" action="DownloadLinkAs"/>
 		<menuitem name="BookmarkLinkLP" action="BookmarkLink"/>
 		<menuitem name="CopyLinkAddressLP" action="CopyLinkAddress"/>
+		<menuitem name="CopyEmailAddressLP" action="CopyEmailAddress"/>
 		<separator />
 		<menuitem name="OpenImageLP" action="OpenImage"/>
 		<menuitem name="SaveImageAsLP" action="SaveImageAs"/>



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