2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import "AICreateCommand.h"
18 #import "NSStringScriptingAdditions.h"
20 @interface NSScriptObjectSpecifier(NSPrivate)
21 + (NSScriptObjectSpecifier *)_objectSpecifierFromDescriptor:(NSAppleEventDescriptor *)desc inCommandConstructionContext:(id)context;
24 @implementation AICreateCommand
26 * @brief Overrides default NSCreateCommand behavior when creating an object; rather than calling alloc/init, calls make<Key>WithProperties:
28 * make<Key>WithProperties: is responsible for parsing all options passed to it during creation.
29 * As well, it must insert the new object into the correct container, looking at the Location key if necessary.
31 - (id)performDefaultImplementation
33 #warning This uses a Private API
34 NSScriptClassDescription *newObjectDescription = [self createClassDescription];
35 id target = [self subjectsSpecifier];
41 NSString *methodName = [NSString stringWithFormat:@"make%@WithProperties:",[[newObjectDescription className] camelCase]];
42 SEL customMethod = NSSelectorFromString(methodName);
44 if ([target respondsToSelector:customMethod])
46 //this can do the insert, based on the parameters, methinks.
47 NSMethodSignature *method = [target methodSignatureForSelector:customMethod];
52 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:method];
53 [invocation setSelector:customMethod];
54 NSDictionary *resolvedKeyDictionary = [self evaluatedArguments];
55 [invocation setArgument:&resolvedKeyDictionary atIndex:2];
56 [invocation invokeWithTarget:target];
57 [invocation getReturnValue:&r];
60 r = [super performDefaultImplementation];
62 if ([r isKindOfClass:[NSScriptObjectSpecifier class]])
65 return [r objectSpecifier];
69 * @brief returns the object in the 'subj' key in this apple event.
71 * This uses a private API. It's the only way I've found to get the target of the 'make' command, which is necessary
72 * in order to override performDefaultImplementation.
74 - (id)subjectsSpecifier
76 NSAppleEventDescriptor *subjDesc = [[self appleEvent] attributeDescriptorForKeyword: 'subj'];
77 NSScriptObjectSpecifier *subjSpec = [NSScriptObjectSpecifier _objectSpecifierFromDescriptor: subjDesc inCommandConstructionContext: nil];
78 return [subjSpec objectsByEvaluatingSpecifier];