]> spindle.queued.net Git - midori/commitdiff
Wrap _has_selection with a check if it is effectly empty
authorChristian Dywan <christian@twotoasts.de>
Sun, 10 Aug 2008 17:22:34 +0000 (19:22 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sun, 10 Aug 2008 17:22:34 +0000 (19:22 +0200)
midori/midori-browser.c
midori/midori-webview.c
midori/midori-webview.h

index 612b1df8543c1bf0c0a7264524c4dda46415da0f..cd354d6145ece99a185211ce4becc55b0917e9a7 100644 (file)
@@ -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);
index c55589cfe06c18e8f207748297b79f89f3e95cdf..8afc0b2bfccbc74be201734223eabec047f641ee 100644 (file)
@@ -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;
+}
index ed7f965b869ef784102874c5e3e52d10a30e64be..76571c72de72752f498c55056c6ea9511ba9ce88 100644 (file)
@@ -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__ */