]> spindle.queued.net Git - midori/commitdiff
Implement a hack to make Search the Web menu item useful
authorEnrico Tröger <enrico.troeger@uvena.de>
Thu, 12 Feb 2009 22:38:48 +0000 (23:38 +0100)
committerChristian Dywan <christian@twotoasts.de>
Thu, 12 Feb 2009 22:38:48 +0000 (23:38 +0100)
midori/midori-view.c

index dc35fc617efdd22fda81826a9776d0f3529affc9..6d16148ac3cc7fd48428bd2d6a164ea459f776dc 100644 (file)
@@ -824,6 +824,29 @@ midori_web_view_menu_new_window_activate_cb (GtkWidget*  widget,
     g_signal_emit (view, signals[NEW_WINDOW], 0, view->link_uri);
 }
 
+static void
+midori_web_view_menu_search_web_activate_cb (GtkWidget*  widget,
+                                             MidoriView* view)
+{
+    gchar* uri;
+    gchar* location_entry_search;
+
+    g_object_get (view->settings, "location-entry-search",
+                  &location_entry_search, NULL);
+    if (strstr (location_entry_search, "%s"))
+    {
+        uri = g_strdup_printf (location_entry_search, view->selected_text);
+        g_free (location_entry_search);
+    }
+    else
+        uri = location_entry_search;
+
+    g_signal_emit (view, signals[NEW_TAB], 0, uri,
+        view->open_tabs_in_the_background);
+
+    g_free (uri);
+}
+
 static void
 midori_web_view_menu_save_as_activate_cb (GtkWidget*  widget,
                                           MidoriView* view)
@@ -872,6 +895,7 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
        determine that the mouse is over a text area or selection. */
     items = gtk_container_get_children (GTK_CONTAINER (menu));
     menuitem = (GtkWidget*)g_list_nth_data (items, 0);
+    g_list_free (items);
     if (GTK_IS_IMAGE_MENU_ITEM (menuitem))
     {
         icon = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (menuitem));
@@ -934,6 +958,12 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
 
     if (!view->link_uri && has_selection)
     {
+        /* hack to implement Search the Web */
+        items = gtk_container_get_children (GTK_CONTAINER (menu));
+        menuitem = (GtkWidget*)g_list_nth_data (items, 0);
+        g_signal_connect (menuitem, "activate",
+            G_CALLBACK (midori_web_view_menu_search_web_activate_cb), view);
+        g_list_free (items);
         if (strchr (view->selected_text, '.')
             && !strchr (view->selected_text, ' '))
         {