diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 612b1df8..cd354d61 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -701,6 +701,7 @@ midori_web_view_populate_popup_cb (GtkWidget* web_view, GtkWidget* menu, MidoriBrowser* browser) { + gboolean has_selection; const gchar* uri; GtkAction* action; GtkWidget* menuitem; @@ -708,6 +709,12 @@ midori_web_view_populate_popup_cb (GtkWidget* web_view, GtkStockItem stockitem; GtkWidget* image; + if (MIDORI_IS_WEB_VIEW (web_view) + && midori_web_view_has_selection (MIDORI_WEB_VIEW (web_view))) + has_selection = TRUE; + else + has_selection = FALSE; + uri = midori_web_view_get_link_uri (MIDORI_WEB_VIEW (web_view)); if (uri) { @@ -726,12 +733,12 @@ midori_web_view_populate_popup_cb (GtkWidget* web_view, gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); } - if (webkit_web_view_has_selection (WEBKIT_WEB_VIEW (web_view))) + if (has_selection) { /* TODO: view selection source */ } - if (!uri && !webkit_web_view_has_selection (WEBKIT_WEB_VIEW (web_view))) + if (!uri && !has_selection) { action = _action_by_name (browser, "UndoTabClose"); menuitem = gtk_action_create_menu_item (action); diff --git a/midori/midori-webview.c b/midori/midori-webview.c index c55589cf..8afc0b2b 100644 --- a/midori/midori-webview.c +++ b/midori/midori-webview.c @@ -728,7 +728,7 @@ webkit_web_view_populate_popup_cb (GtkWidget* web_view, } } - if (!uri && webkit_web_view_has_selection (WEBKIT_WEB_VIEW (web_view))) + if (!uri && midori_web_view_has_selection (MIDORI_WEB_VIEW (web_view))) { text = webkit_web_view_get_selected_text (WEBKIT_WEB_VIEW (web_view)); if (text && strchr (text, '.') && !strchr (text, ' ')) @@ -1175,3 +1175,31 @@ midori_web_view_get_news_feeds (MidoriWebView* web_view) return web_view->news_feeds; return NULL; } + +/** + * midori_web_view_has_selection: + * @web_view: a #MidoriWebView + * + * Determines whether something on the page is selected. + * + * By contrast to webkit_web_view_has_selection() this + * returns %FALSE if there is a selection that + * effectively only consists of whitespace. + * + * Return value: %TRUE if effectively there is a selection + **/ +gboolean +midori_web_view_has_selection (MidoriWebView* web_view) +{ + gchar* text; + + g_return_val_if_fail (MIDORI_IS_WEB_VIEW (web_view), FALSE); + + text = webkit_web_view_get_selected_text (WEBKIT_WEB_VIEW (web_view)); + if (text && *text) + { + g_free (text); + return TRUE; + } + return FALSE; +} diff --git a/midori/midori-webview.h b/midori/midori-webview.h index ed7f965b..76571c72 100644 --- a/midori/midori-webview.h +++ b/midori/midori-webview.h @@ -117,6 +117,9 @@ midori_web_view_get_link_uri (MidoriWebView* web_view); MidoriWebList* midori_web_view_get_news_feeds (MidoriWebView* web_view); +gboolean +midori_web_view_has_selection (MidoriWebView* web_view); + G_END_DECLS #endif /* __MIDORI_WEB_VIEW_H__ */