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 "AIMoveCommand.h"
18 #import "NSStringScriptingAdditions.h"
20 @implementation AIMoveCommand
22 * @brief Checks if target responds to 'move<Key>:toIndex:'. If so, then uses that method to move. Otherwise, calls super.
24 * This class overrides NSMoveCommand, and is more useful for those cases when a move is not a remove/insert pair.
25 * The target can specify exactly how to get the object into itself, in its own move<Key>:toIndex: method.
27 - (id)performDefaultImplementation
29 NSPositionalSpecifier *toLocation = [[self evaluatedArguments] objectForKey:@"ToLocation"];
31 NSString *keyClassName = [[self keySpecifier] key];
32 NSString *methodName = [NSString stringWithFormat:@"move%@:toIndex:",[keyClassName camelCase]];
33 id target = [toLocation insertionContainer];
34 if ([target respondsToSelector:NSSelectorFromString(methodName)]) {
35 NSMethodSignature *method = [target methodSignatureForSelector:NSSelectorFromString(methodName)];
37 NSLog(@"%@ doesn't support %@!",NSStringFromClass([target class]),method);
40 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:method];
41 [invocation setSelector:NSSelectorFromString(methodName)];
42 id chat = [[self keySpecifier] objectsByEvaluatingSpecifier];
43 [invocation setArgument:&chat atIndex:2];
44 unsigned int index = [toLocation insertionIndex];
45 [invocation setArgument:&index atIndex:3];
46 [invocation invokeWithTarget:target];
48 [invocation getReturnValue:&r];
52 return [super performDefaultImplementation];