From e7d20f467cbdb9583b6a2c58a0742fa3a99ffddf Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sun, 12 Apr 2009 01:32:06 +0200 Subject: [PATCH] Show all search engines in selection context menu This replaces the generic Search the Web unless no search engines are defined, which is actually a corner case. --- midori/midori-searchaction.c | 20 +++++----- midori/midori-view.c | 73 +++++++++++++++++++++++++++++------- 2 files changed, 69 insertions(+), 24 deletions(-) diff --git a/midori/midori-searchaction.c b/midori/midori-searchaction.c index f7df3c9c..e8e860dc 100644 --- a/midori/midori-searchaction.c +++ b/midori/midori-searchaction.c @@ -377,10 +377,11 @@ midori_search_action_manage_activate_cb (GtkWidget* menuitem, gtk_widget_show (dialog); } -static GdkPixbuf* -midori_search_action_get_icon (MidoriSearchAction* search_action, - KatzeItem* item, - GtkWidget* widget) +/* Private function, used by MidoriView */ +/* static */ GdkPixbuf* +midori_search_action_get_icon (KatzeNet* net, + KatzeItem* item, + GtkWidget* widget) { const gchar* icon; @@ -403,8 +404,7 @@ midori_search_action_get_icon (MidoriSearchAction* search_action, } if ((icon = katze_item_get_uri (item)) && (g_strstr_len (icon, 8, "://"))) - return katze_net_load_icon (search_action->net, - icon, NULL, widget, NULL); + return katze_net_load_icon (net, icon, NULL, widget, NULL); return gtk_widget_render_icon (widget, GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL); @@ -438,8 +438,8 @@ midori_search_action_icon_released_cb (GtkWidget* entry, menuitem = gtk_image_menu_item_new_with_label ( katze_item_get_name (item)); image = gtk_image_new (); - icon = midori_search_action_get_icon (MIDORI_SEARCH_ACTION (action), - item, entry); + icon = midori_search_action_get_icon ( + MIDORI_SEARCH_ACTION (action)->net, item, entry); gtk_image_set_from_pixbuf (GTK_IMAGE (image), icon); g_object_unref (icon); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); @@ -493,7 +493,7 @@ midori_search_action_set_entry_icon (MidoriSearchAction* search_action, if (search_action->current_item) { - icon = midori_search_action_get_icon (search_action, + icon = midori_search_action_get_icon (search_action->net, search_action->current_item, entry); gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry), GTK_ICON_ENTRY_PRIMARY, icon); @@ -730,7 +730,7 @@ midori_search_action_dialog_render_icon_cb (GtkTreeViewColumn* column, gtk_tree_model_get (model, iter, 0, &item, -1); search_action = g_object_get_data (G_OBJECT (treeview), "search-action"); - icon = midori_search_action_get_icon (search_action, item, treeview); + icon = midori_search_action_get_icon (search_action->net, item, treeview); g_object_set (renderer, "pixbuf", icon, "yalign", 0.25, NULL); g_object_unref (icon); } diff --git a/midori/midori-view.c b/midori/midori-view.c index f77e0c03..18987330 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -39,6 +39,11 @@ webkit_web_view_get_selected_text (WebKitWebView* web_view); void webkit_web_frame_print (WebKitWebFrame* web_frame); +GdkPixbuf* +midori_search_action_get_icon (KatzeNet* net, + KatzeItem* item, + GtkWidget* widget); + struct _MidoriView { GtkScrolledWindow parent_instance; @@ -900,18 +905,21 @@ static void midori_web_view_menu_search_web_activate_cb (GtkWidget* widget, MidoriView* view) { + gchar* search; gchar* uri; - gchar* location_entry_search; - g_object_get (view->settings, "location-entry-search", - &location_entry_search, NULL); - if (strstr (location_entry_search, "%s")) + if ((search = g_object_get_data (G_OBJECT (widget), "search"))) + search = g_strdup (search); + else + g_object_get (view->settings, "location-entry-search", + &search, NULL); + if (strstr (search, "%s")) { - uri = g_strdup_printf (location_entry_search, view->selected_text); - g_free (location_entry_search); + uri = g_strdup_printf (search, view->selected_text); + g_free (search); } else - uri = location_entry_search; + uri = search; g_signal_emit (view, signals[NEW_TAB], 0, uri, view->open_tabs_in_the_background); @@ -1048,14 +1056,51 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view, if (!view->link_uri && has_selection) { + GtkWidget* window; + guint i; + + window = gtk_widget_get_toplevel (GTK_WIDGET (web_view)); + i = 0; + if (katze_object_has_property (window, "search-engines")) + { + KatzeArray* search_engines; + KatzeItem* item; + + search_engines = katze_object_get_object (window, "search-engines"); + while ((item = katze_array_get_nth_item (search_engines, i++))) + { + GdkPixbuf* pixbuf; + gchar* text = g_strdup_printf (_("Search with %s"), + katze_item_get_name (item)); + menuitem = gtk_image_menu_item_new_with_mnemonic (text); + g_free (text); + pixbuf = midori_search_action_get_icon (view->net, item, + GTK_WIDGET (web_view)); + icon = gtk_image_new_from_pixbuf (pixbuf); + g_object_unref (pixbuf); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), icon); + gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem, i - 1); + g_object_set_data (G_OBJECT (menuitem), "search", + (gchar*)katze_item_get_uri (item)); + g_signal_connect (menuitem, "activate", + G_CALLBACK (midori_web_view_menu_search_web_activate_cb), view); + gtk_widget_show (menuitem); + } + g_object_unref (search_engines); + } items = gtk_container_get_children (GTK_CONTAINER (menu)); - menuitem = (GtkWidget*)g_list_nth_data (items, 0); - /* hack to localize menu item */ - label = gtk_bin_get_child (GTK_BIN (menuitem)); - gtk_label_set_label (GTK_LABEL (label), _("_Search the Web")); - /* hack to implement Search the Web */ - g_signal_connect (menuitem, "activate", - G_CALLBACK (midori_web_view_menu_search_web_activate_cb), view); + menuitem = (GtkWidget*)g_list_nth_data (items, i - 1); + if (i > 1) + gtk_widget_destroy (menuitem); + else + { + /* hack to localize menu item */ + label = gtk_bin_get_child (GTK_BIN (menuitem)); + gtk_label_set_label (GTK_LABEL (label), _("_Search the Web")); + /* hack to implement Search the Web */ + 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, ' ')) -- 2.39.5