View previous topic :: View next topic |
Author |
Message |
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Sun Aug 31, 2008 10:04 am Post subject: Actions - common event handlers for menu's and toolbars. |
|
|
Is it possible in gtkD (or generally in gtk+) to associate menu item and toolbar item with one action.
So for example:
1) Define an action. Assign some predefined stock item to it - Like Stock.OPEN.
2) Assign an event handler for it
3) Then create MenuItem and ToolBar
Because now as much I understood all I can do is:
Code: |
void onMenuActivate(MenuItem menuItem)
{
}
void onToolButtonClicked(ToolButton button)
{
}
menu.append(new MenuItem(&onMenuActivate, "_Open", "file.open", true, accelGroup, 'o'));
auto buttonOpen = new ToolButton(StockID.OPEN);
buttonOpen.addOnClicked(&onToolButtonClicked);
toolbar.insert(buttonOpen);
|
Maybe Im wrong, can somebody please spot some light on this? |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Mon Sep 01, 2008 1:38 pm Post subject: |
|
|
This should do it, but it would be nice if the casting wasn't needed.
Code: | void onWitgetActivate(Widget widget)
{
}
menu.append(new MenuItem(cast(delegate(MenuItem))&onWitgetActivate, "_Open", "file.open", true, accelGroup, 'o'));
auto buttonOpen = new ToolButton(StockID.OPEN);
buttonOpen.addOnClicked(cast(delegate(ToolButton))&onWitgetActivate);
toolbar.insert(buttonOpen); |
|
|
Back to top |
|
|
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Fri Sep 05, 2008 12:26 pm Post subject: |
|
|
Something like this might do it.
Code: | void onActionActivate(Action action)
{
}
action Action = new Action("open", "_Open", "tooltip", "gtk-open"); //Should accept an StockID.
action.addOnActivate(&onActionActivate);
action.setAccelGroup(accelGroup);
auto menuItem = action.createMenuItem
menuItem.addAccelerator("activate", accelGroup, 'o', GdkModifierType.CONTROL_MASK, GtkAccelFlags.VISIBLE)
menu.append(menuItem);
toolbar.insert(action.createToolItem); |
|
|
Back to top |
|
|
eldar
Joined: 14 Jun 2008 Posts: 101 Location: Ufa, Russia
|
Posted: Fri Sep 05, 2008 11:54 pm Post subject: |
|
|
Ok thanks. By the way in TestWindow demo in the tool bar there are added PushButtons, which look ugly on toolbar - maybe replace them with ToolButtons? |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sat Sep 06, 2008 9:30 am Post subject: |
|
|
good idea, svn r604 |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Mon Sep 15, 2008 4:02 am Post subject: |
|
|
with svn r613 the constructor for gtk.Action accepts an StockID.
Code: | action Action = new Action("open", "_Open", "tooltip", "gtk-open"); //Should accept an StockID. |
could be changed into:
Code: | action Action = new Action("open", "_Open", "tooltip", StockID.OPEN); |
|
|
Back to top |
|
|
|