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.
This commit is contained in:
Christian Dywan 2009-04-12 01:32:06 +02:00
parent 50f078575b
commit e7d20f467c
2 changed files with 69 additions and 24 deletions

View file

@ -377,8 +377,9 @@ midori_search_action_manage_activate_cb (GtkWidget* menuitem,
gtk_widget_show (dialog);
}
static GdkPixbuf*
midori_search_action_get_icon (MidoriSearchAction* search_action,
/* Private function, used by MidoriView */
/* static */ GdkPixbuf*
midori_search_action_get_icon (KatzeNet* net,
KatzeItem* item,
GtkWidget* widget)
{
@ -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);
}

View file

@ -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;
if ((search = g_object_get_data (G_OBJECT (widget), "search")))
search = g_strdup (search);
else
g_object_get (view->settings, "location-entry-search",
&location_entry_search, NULL);
if (strstr (location_entry_search, "%s"))
&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);
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, ' '))