FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Actions - common event handlers for menu's and toolbars.

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Sun Aug 31, 2008 10:04 am    Post subject: Actions - common event handlers for menu's and toolbars. Reply with quote

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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Mon Sep 01, 2008 1:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Fri Sep 05, 2008 7:11 am    Post subject: Reply with quote

http://library.gnome.org/devel/gtk/2.12/GtkAction.html
It says that action is triggered by menu or toolbar item - maybe it is what we need?
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Fri Sep 05, 2008 12:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Fri Sep 05, 2008 11:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sat Sep 06, 2008 9:30 am    Post subject: Reply with quote

good idea, svn r604
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Mon Sep 15, 2008 4:02 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group