ActionGroups

[ Start > PikeModules > Module > GTK2 > ActionGroups ] [ Edit this Page | Show Page Versions | Show Raw Source ]


Create an Action Group

There are several types of action groups: radio, menu, toolbar, toggle, popup.

1 Defining the action groups

1.1 Menu actions

To create a regular menu action group, create an array like the following:

array menu_actions=({
 ([ "name": "FileMenu", "label": "_File" ]),
 ([ "name": "FileOpen", "label": "_Open",
    "callback": open_file, "data": 0 ]),
 ([ "name": "FileQuit", "label": "_Quit",
    "callback": appQuit, "data": 0 ]),
 ([ "name": "EditMenu", "label": "_Edit" ]),
 ([ "name": "EditCopy", "label": "_Copy",
    "callback": edit_copy, "data": 0 ]),
 ([ "name": "EditPast", "label": "_Paste",
    "callback": edit_past, "data": 0 ])
});

The name is what the item will be referenced in the xml definition for the UiManager. The label is what will be displayed in the menu. Callback is, of course, the actual function that will be called when the item is selected. It can be a lambda function if you wish. Data is some info that will be passed to the function, as with a normal signal. You can only pass one piece of data to the callback, but that can be anything, an array, mapping, object, or whatever, so you really aren't limited.

Toolbar actions look exactly the same. Actually, there is no difference between menu actions and toolbar actions, just where they are placed, which is defined when creating the UiManager.

1.1 Radio actions

Similar to regular menu actions, but with an additional "value" parameter, and without the "data" parameter

array radio_actions=({
 ([ "name": "ViewIcons", "label": "Icons", "value": 0 ])
})

Radio actions don't have a callback set in the action group, only in the ui manager. This is because they all work as a group, not individually.

1.1 Toggle actions

Toggle actions look like:

array toggle_actions=({
 ([ "name": "Connect", "label": "_Connect", "stock_id": "hdadmin-connect", "active": 0 ])
});

The "active" parameter defines whether the item is default clicked or not.

1 Creating the action group(s)

Now that you have the action group definitions, you have to create one or more action groups to go with them.

object gt1=GTK2.ActionGroup("Group1");

You can name the group anything you'd like. The label is so that you can add more than one action group to a ui manager. If you add an action group that has some elements that are already defined (by an earlier action group), then the later ones will take precedence. This is handy because you can easily change menus on the fly when some state changes, then later on remove an action group, and the menus will change back to how they were before you added it. This simplifies menu creation.

Add some actions:

gt1->add_actions(menu_actions);
gt1->add_toggle_actions(toggle_actions);
gt1->add_radio_actions(radio_actions,my_radio_callback,"some data");

Now that the actions have been added, now you can add the action group to a UiManager.


Powered by PikeWiki2

 
gotpike.org | Copyright © 2004 - 2009 | Pike is a trademark of Department of Computer and Information Science, Linköping University