<menu> under <toolitem> in ui
- From: Allin Cottrell <cottrell wfu edu>
- To: gtk-app-devel-list gnome org
- Subject: <menu> under <toolitem> in ui
- Date: Wed, 29 Jul 2009 10:27:56 -0400 (EDT)
I'm trying to get a button on a toolbar to produce a menu.
The GtkUIManager docs indicate this can be done but I haven't got
the details right yet and I wonder if someone can put me on the
right track.
The ui definition is like this:
const gchar *my_ui =
"<ui>"
" <toolbar name='ToolBar'>"
" <toolitem action='TopicsButton'>"
" <menu action='Topics'>"
" <placeholder name='TopicsMenuItems'/>"
" </menu>"
" </toolitem>"
" <toolitem action='WindowFind'/>"
" <toolitem action='ZoomIn'/>"
" <toolitem action='ZoomOut'/>"
" </toolbar>"
"</ui>";
I.e. the first toolitem carries a menu (to be constructed
dynamicallly) but the others are simple buttons.
And I have this array of GtkActionEntry:
GtkActionEntry my_menu_items[] = {
{ "Topics", NULL, NULL, NULL, NULL, NULL },
{ "WindowFind", GTK_STOCK_FIND,
N_("_Find in window"), NULL, NULL, G_CALLBACK(text_find) },
{ "ZoomIn", GTK_STOCK_ZOOM_IN, N_("_Larger"), NULL, NULL,
G_CALLBACK(text_zoom) },
{ "ZoomOut", GTK_STOCK_ZOOM_OUT, N_("_Smaller"), NULL, NULL,
G_CALLBACK(text_zoom) }
};
The action 'TopicsButton' doesn't have an entry in this array
because, as I understand it, I have to create a special GtkAction
with a proxy connected, as in:
GtkAction *action;
GtkToolItem *proxy;
action = gtk_action_new("TopicsButton", NULL, N_("_Topics"),
GTK_STOCK_INDEX);
proxy = gtk_menu_tool_button_new(NULL, NULL);
gtk_action_connect_proxy(action, GTK_WIDGET(proxy));
I then:
1. use gtk_action_group_add_action_with_accel() to add the
TopicsButton action to a newly created GtkActionGroup.
2. append the actions from the array above using
gtk_action_group_add_actions().
3. use gtk_ui_manager_new() to get a manager, and use
gtk_ui_manager_insert_action_group() to add the whole group.
4. use gtk_ui_manager_add_ui_from_string() with 'my_ui' as
argument.
The toolbar is shown, but the button that's supposed to carry
a menu has no "down arrow" and I get this message:
Gtk-CRITICAL **: gtk_menu_tool_button_set_menu: assertion
`GTK_IS_MENU_TOOL_BUTTON (button)' failed
Allin Cottrell
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]