NSDocument Enabling and handling menu items without implementing the action method in the document class
NSDocument Enabling and handling menu items without implementing the action method in the document class
- Subject: NSDocument Enabling and handling menu items without implementing the action method in the document class
- From: Eyal Redler <email@hidden>
- Date: Sun, 19 Jul 2009 15:06:00 +0300
Hi,
In the document based application I'm working on I have a lot of
methods in the document class which simply pass a command to some
internal object. This requires me do do the following in my NSDocument
subclass:
- (BOOL)validateMenuItem:(NSMenuItem *)item
{
SEL action = [item action];
if (action==@selector(myAction:))
return [internalObject shouldEnableMyAction];
else
...
}
- (void)myAction:(id)sender
{
[internalObject myAction:sender];
}
This works fine but it requires me to write an annoying amount such
glue code every time I add an action so I'm looking for a better way
to do this. Is it possible to further delegate the action methods and
menu validation from the NSDocument subclass? The best way for me
would be to have internalObject implement validateMenuItem and
myAction and have the NSDocument pass them along without actually
implementing each action method.
TIA
Eyal
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden