Put NSAutoreleasePool usage around other distributed notification observer methods
[adiumx.git] / Source / AIMoveCommand.m
blob000e288832a522b55322542474efee5a60152c89
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
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.
8  * 
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.
12  * 
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.
15  */
17 #import "AIMoveCommand.h"
18 #import "NSStringScriptingAdditions.h"
20 @implementation AIMoveCommand
21 /**
22  * @brief Checks if target responds to 'move<Key>:toIndex:'. If so, then uses that method to move. Otherwise, calls super.
23  *
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.
26  */
27 - (id)performDefaultImplementation
29         NSPositionalSpecifier *toLocation = [[self evaluatedArguments] objectForKey:@"ToLocation"];
30         
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)];
36                 if (!method) {
37                         NSLog(@"%@ doesn't support %@!",NSStringFromClass([target class]),method);
38                         return nil;
39                 }
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];
47                 id r;
48                 [invocation getReturnValue:&r];
49                 return r;
50         }
51         else
52                 return [super performDefaultImplementation];
53         return nil;
55 @end