mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 22:10:36 +00:00
Make use of NSInvocation
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@17346 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d6c5c9c4a0
commit
4b8e37012d
3 changed files with 71 additions and 6 deletions
|
@ -28,6 +28,7 @@
|
|||
#include "gnustep/gui/config.h"
|
||||
#include <Foundation/NSCoder.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSInvocation.h>
|
||||
#include "AppKit/NSResponder.h"
|
||||
#include "AppKit/NSApplication.h"
|
||||
#include "AppKit/NSMenu.h"
|
||||
|
@ -96,12 +97,30 @@
|
|||
return NO;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the receiver responds to anAction, it performs that method with
|
||||
* anObject as its argument, discards any return value, and return YES.<br />
|
||||
* Otherwise, the next responder in the chain is asked to perform
|
||||
* anAction and the result of that is returned.<br />
|
||||
* If no responder in the chain is able to respond to anAction, then
|
||||
* NO is returned.
|
||||
*/
|
||||
- (BOOL) tryToPerform: (SEL)anAction with: (id)anObject
|
||||
{
|
||||
/* Can we perform the action -then do it */
|
||||
if ([self respondsToSelector: anAction])
|
||||
{
|
||||
[self performSelector: anAction withObject: anObject];
|
||||
NSInvocation *inv;
|
||||
NSMethodSignature *sig;
|
||||
|
||||
sig = [self methodSignatureForSelector: anAction];
|
||||
inv = [NSInvocation invocationWithMethodSignature: sig];
|
||||
[inv setSelector: anAction];
|
||||
if ([sig numberOfArguments] > 2)
|
||||
{
|
||||
[inv setArgument: &anObject atIndex: 2];
|
||||
}
|
||||
[inv invokeWithTarget: self];
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue