gtk - Why isn't my toolitem's proxy menu item being used? -
i want show custom menu item toolitem
when in toolbar's overflow menu. seems purpose of set_proxy_menu_item
method. however, when set proxy menu item via using method, has no effect on overflow menu. still uses default menu item (with toolitem's name label).
here simple project (in vala) reproduces problem. creates tiny window containing toolbar 3 buttons. window should small enough 1 of these buttons in overflow menu.
when view overflow menu, should see "proxy" menu item edit_button
. instead, see "edit".
what 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 set_proxy_menu_item
temporary, , should used in response create-menu-proxy
signal. can't find documented anywhere on web, here gtk+ source code:
/** * gtktoolitem::create-menu-proxy: * @tool_item: object signal emitted on * * signal emitted when toolbar needs information @tool_item * whether item should appear in toolbar overflow menu. in * response tool item should either * <itemizedlist> * <listitem>call gtk_tool_item_set_proxy_menu_item() %null * pointer , return %true indicate item should not appear * in overflow menu * </listitem> * <listitem> call gtk_tool_item_set_proxy_menu_item() new menu * item , return %true, or * </listitem> * <listitem> return %false indicate signal not * handled item. means * item not appear in overflow menu unless later handler * installs menu item. * </listitem> * </itemizedlist> * * toolbar may cache result of signal. when tool item changes * how respond signal must call gtk_tool_item_rebuild_menu() * invalidate cache , ensure toolbar rebuilds overflow * menu. * * return value: %true if signal handled, %false if not **/
so right way solve like:
edit_button.create_menu_proxy.connect(on_create_menu_proxy); ... private bool on_create_menu_proxy(gtk.toolitem tool_item) { gtk.menuitem proxy = new gtk.menuitem.with_label("proxy"); tool_item.set_proxy_menu_item("proxy_menuitem", proxy); return true; }
you may not want create new proxy every time signal fired, should enough reading started.
Comments
Post a Comment