]> spindle.queued.net Git - midori/commitdiff
Move search engine items in selection context menus to a submenu
authorEnrico Tröger <enrico.troeger@uvena.de>
Sat, 18 Apr 2009 17:26:42 +0000 (19:26 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sat, 18 Apr 2009 17:39:17 +0000 (19:39 +0200)
midori/midori-view.c

index 7c36d2c4904b8e7acb2233cecd11f8d2131ee04d..bb10bfe553f6852fc10b17517bd1853c505c7402 100644 (file)
@@ -1043,21 +1043,24 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
         {
             KatzeArray* search_engines;
             KatzeItem* item;
+            GtkWidget* sub_menu = gtk_menu_new ();
+
+            menuitem = gtk_image_menu_item_new_with_mnemonic (_("Search _with"));
+            gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), sub_menu);
+            gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem, 1);
+            gtk_widget_show (menuitem);
 
             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);
+                menuitem = gtk_image_menu_item_new_with_mnemonic (katze_item_get_name (item));
                 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);
+                gtk_menu_shell_insert (GTK_MENU_SHELL (sub_menu), menuitem, i - 1);
                 g_object_set_data (G_OBJECT (menuitem), "search",
                                    (gchar*)katze_item_get_uri (item));
                 g_signal_connect (menuitem, "activate",
@@ -1067,19 +1070,15 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
             g_object_unref (search_engines);
         }
         items = gtk_container_get_children (GTK_CONTAINER (menu));
-        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);
-        }
+        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);
         g_list_free (items);
+
         if (strchr (view->selected_text, '.')
             && !strchr (view->selected_text, ' '))
         {