GtkWidget* menu,
MidoriBrowser* browser)
{
+ gboolean has_selection;
const gchar* uri;
GtkAction* action;
GtkWidget* menuitem;
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)
{
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);
}
}
- 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, ' '))
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;
+}
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__ */