Wrap _has_selection with a check if it is effectly empty
This commit is contained in:
parent
323cf2458d
commit
b38e3f429e
3 changed files with 41 additions and 3 deletions
|
@ -701,6 +701,7 @@ midori_web_view_populate_popup_cb (GtkWidget* web_view,
|
||||||
GtkWidget* menu,
|
GtkWidget* menu,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
|
gboolean has_selection;
|
||||||
const gchar* uri;
|
const gchar* uri;
|
||||||
GtkAction* action;
|
GtkAction* action;
|
||||||
GtkWidget* menuitem;
|
GtkWidget* menuitem;
|
||||||
|
@ -708,6 +709,12 @@ midori_web_view_populate_popup_cb (GtkWidget* web_view,
|
||||||
GtkStockItem stockitem;
|
GtkStockItem stockitem;
|
||||||
GtkWidget* image;
|
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));
|
uri = midori_web_view_get_link_uri (MIDORI_WEB_VIEW (web_view));
|
||||||
if (uri)
|
if (uri)
|
||||||
{
|
{
|
||||||
|
@ -726,12 +733,12 @@ midori_web_view_populate_popup_cb (GtkWidget* web_view,
|
||||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
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 */
|
/* 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");
|
action = _action_by_name (browser, "UndoTabClose");
|
||||||
menuitem = gtk_action_create_menu_item (action);
|
menuitem = gtk_action_create_menu_item (action);
|
||||||
|
|
|
@ -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));
|
text = webkit_web_view_get_selected_text (WEBKIT_WEB_VIEW (web_view));
|
||||||
if (text && strchr (text, '.') && !strchr (text, ' '))
|
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 web_view->news_feeds;
|
||||||
return NULL;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -117,6 +117,9 @@ midori_web_view_get_link_uri (MidoriWebView* web_view);
|
||||||
MidoriWebList*
|
MidoriWebList*
|
||||||
midori_web_view_get_news_feeds (MidoriWebView* web_view);
|
midori_web_view_get_news_feeds (MidoriWebView* web_view);
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
midori_web_view_has_selection (MidoriWebView* web_view);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __MIDORI_WEB_VIEW_H__ */
|
#endif /* __MIDORI_WEB_VIEW_H__ */
|
||||||
|
|
Loading…
Reference in a new issue