| 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2005, 2006 Stephen F. Booth <me@sbooth.org> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #import "TagArrayController.h" |
|---|
| 22 | |
|---|
| 23 | @implementation TagArrayController |
|---|
| 24 | |
|---|
| 25 | - (void) setDelegate:(id <TagArrayControllerDelegateMethods>)delegate { _delegate = delegate; } |
|---|
| 26 | - (id <TagArrayControllerDelegateMethods>) delegate { return _delegate; } |
|---|
| 27 | |
|---|
| 28 | - (void) objectDidBeginEditing:(id)editor |
|---|
| 29 | { |
|---|
| 30 | NSDictionary *dictionary; |
|---|
| 31 | |
|---|
| 32 | if(nil != _delegate) { |
|---|
| 33 | dictionary = [[self arrangedObjects] objectAtIndex:[self selectionIndex]]; |
|---|
| 34 | _previousTag = [[[dictionary valueForKey:@"key"] uppercaseString] retain]; |
|---|
| 35 | _previousValue = [[dictionary valueForKey:@"value"] retain]; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | [super objectDidBeginEditing:editor]; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | - (void) objectDidEndEditing:(id)editor |
|---|
| 42 | { |
|---|
| 43 | NSDictionary *dictionary; |
|---|
| 44 | NSString *tag, *value; |
|---|
| 45 | |
|---|
| 46 | if(nil != _delegate) { |
|---|
| 47 | dictionary = [[self arrangedObjects] objectAtIndex:[self selectionIndex]]; |
|---|
| 48 | tag = [[dictionary valueForKey:@"key"] uppercaseString]; |
|---|
| 49 | value = [dictionary valueForKey:@"value"]; |
|---|
| 50 | |
|---|
| 51 | if([_previousTag isEqualToString:tag]) { |
|---|
| 52 | [_delegate updateTag:tag withValue:_previousValue toValue:value]; |
|---|
| 53 | } |
|---|
| 54 | else { |
|---|
| 55 | [_delegate renameTag:_previousTag withValue:_previousValue toTag:tag]; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | [_previousTag release]; |
|---|
| 59 | [_previousValue release]; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | [super objectDidEndEditing:editor]; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | #pragma mark Drag and Drop |
|---|
| 66 | |
|---|
| 67 | - (BOOL) tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard |
|---|
| 68 | { |
|---|
| 69 | [pboard declareTypes:[NSArray arrayWithObject:@"org.sbooth.Tag.TagItem"] owner:self]; |
|---|
| 70 | [pboard setPropertyList:[[self arrangedObjects] objectsAtIndexes:rowIndexes] forType:@"org.sbooth.Tag.TagItem"]; |
|---|
| 71 | |
|---|
| 72 | return YES; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | @end |
|---|