I want to show a custom menu item for a ToolItem when it is in the toolbar’s overflow menu. This seems to be the purpose of the set_proxy_menu_item method. However, when I set the proxy menu item via using this method, it has no effect on the overflow menu. It still uses the default menu item (with the ToolItem’s name as the label).
Here is a simple project (in Vala) that reproduces the problem. It creates a tiny window containing a toolbar with 3 buttons. The window should be small enough that all but one of these buttons is in the overflow menu.
When I view the overflow menu, I should see “proxy” for as the menu item for edit_button. Instead, I see “edit”.
What am I doing wrong?
void main(string[] args) {
Gtk.init(ref args);
MainWindow main_window = new MainWindow();
main_window.show_all();
Gtk.main();
}
public class MainWindow : Gtk.Window {
public MainWindow() {
destroy.connect(Gtk.main_quit);
title = "Main Window";
Gtk.Box main_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 6);
add(main_box);
Gtk.Toolbar toolbar = new Gtk.Toolbar();
main_box.pack_start(toolbar, false, false);
Gtk.ToolButton new_button = new Gtk.ToolButton.from_stock(Gtk.Stock.NEW);
Gtk.ToolButton edit_button = new Gtk.ToolButton.from_stock(Gtk.Stock.EDIT);
Gtk.ToolButton delete_button = new Gtk.ToolButton.from_stock(Gtk.Stock.DELETE);
Gtk.MenuItem proxy = new Gtk.MenuItem.with_label("proxy");
proxy.show_all();
edit_button.set_proxy_menu_item("proxy_menuitem", proxy);
toolbar.add(new_button);
toolbar.add(edit_button);
toolbar.add(delete_button);
Gtk.Label content_label = new Gtk.Label("Placeholder");
main_box.pack_start(content_label, false, false);
}
}
It turns out that
set_proxy_menu_itemis temporary, and should be used in a response to thecreate-menu-proxysignal. I can’t find this documented anywhere on the web, but here it is from the Gtk+ source code:So the right way to solve this would be something like:
You may not actually want to create a new proxy every time the signal is fired, but that should be enough to help anyone reading this get started.