UiManager
1 Creating a Ui Manager
Creating a Ui Manager is easy:
{code}
ui=GTK2.UiManager();
{code}
Now add your [PikeModules/Module/GTK2/ActionGroups]:
{code}
ui->insert_action_group(gt1,0);
{code}
The parameter is the position. If you have a two groups called the same name, then the group with the lower number (earlier) will hide a high number (later) group.
Now you want to add your ui definition, but first you'll have to create it:
This can be in a separate file, to make menu editing easy:
{code}
{code}
This is a sample xml definition of a menu structure, with a toolbar. It can be several levels deep by just using a menu instead of a menuitem.
Now, just add the ui definition(s) to the ui:
{code}
int id=ui->add_ui_from_file("menu.xml");
{code}
You can also add from a string with ui->add_ui_from_string();
The return value is an id you can use to remove the ui definition from the ui manager. The ui's get merged.
All this is a bunch of convenient shortcuts for doing it all by hand with:
ui->new_merge_id() and ui->add_ui().
UiManager takes all this info and creates the appropriate widgets. You can get the widgets for packing into your containers (vbox or whatever) with the following:
{code}
object menub=ui->get_widget("/MyMenuBar");
object toolb=ui->get_widget("/MyToolBar");
{code}
Where "MyMenuBar" and "MyToolBar" are the names you used for the menubar and toolbar in the xml definition. The / means that it will search from the top of the xml tree.
If you want to get the widget for a specific action, you can do something like:
{code}
object widget=ui->get_widget("/MyMenuBar/EditMenu/EditCopy");
{code}
This will get the widget for the menu item EditCopy from the example xml definition above.
Powered by PikeWiki2
|
|