| 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 "ApplicationDelegate.h" |
|---|
| 22 | #import "PreferencesController.h" |
|---|
| 23 | #import "AcknowledgmentsController.h" |
|---|
| 24 | #import "UppercaseStringValueTransformer.h" |
|---|
| 25 | #import "TagEditor.h" |
|---|
| 26 | #import "ServicesProvider.h" |
|---|
| 27 | |
|---|
| 28 | @implementation ApplicationDelegate |
|---|
| 29 | |
|---|
| 30 | + (void)initialize |
|---|
| 31 | { |
|---|
| 32 | NSValueTransformer *transformer; |
|---|
| 33 | |
|---|
| 34 | transformer = [[[UppercaseStringValueTransformer alloc] init] autorelease]; |
|---|
| 35 | [NSValueTransformer setValueTransformer:transformer forName:@"UppercaseStringValueTransformer"]; |
|---|
| 36 | |
|---|
| 37 | [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:@"startupVersionCheck"]]; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | - (void) applicationWillFinishLaunching:(NSNotification *)aNotification |
|---|
| 41 | { |
|---|
| 42 | [[TagEditor sharedEditor] showWindow:self]; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | - (void) applicationDidFinishLaunching:(NSNotification *)aNotification |
|---|
| 46 | { |
|---|
| 47 | // Register services |
|---|
| 48 | [[NSApplication sharedApplication] setServicesProvider:[[ServicesProvider alloc] init]]; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | - (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication *) sender |
|---|
| 52 | { |
|---|
| 53 | return ([[TagEditor sharedEditor] applicationShouldTerminate] ? NSTerminateNow : NSTerminateCancel); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | - (void) application:(NSApplication *)sender openFiles:(NSArray *)filenames |
|---|
| 57 | { |
|---|
| 58 | TagEditor *editor = [TagEditor sharedEditor]; |
|---|
| 59 | NSEnumerator *enumerator; |
|---|
| 60 | NSString *filename; |
|---|
| 61 | BOOL success = YES; |
|---|
| 62 | |
|---|
| 63 | enumerator = [filenames objectEnumerator]; |
|---|
| 64 | while((filename = [enumerator nextObject])) { |
|---|
| 65 | success &= [editor addFile:[filename stringByExpandingTildeInPath]]; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | [editor openFilesDrawerIfNeeded]; |
|---|
| 69 | |
|---|
| 70 | [[NSApplication sharedApplication] replyToOpenOrPrint:(success ? NSApplicationDelegateReplySuccess : NSApplicationDelegateReplyFailure)]; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | - (BOOL) application:(NSApplication *)sender delegateHandlesKey:(NSString *)key |
|---|
| 74 | { |
|---|
| 75 | return [key isEqualToString:@"files"]; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | - (IBAction) showPreferences:(id)sender |
|---|
| 79 | { |
|---|
| 80 | [[PreferencesController sharedPreferences] showWindow:self]; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | - (IBAction) showAcknowledgments:(id)sender |
|---|
| 84 | { |
|---|
| 85 | [[AcknowledgmentsController sharedController] showWindow:self]; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | - (unsigned) countOfFiles { return [[TagEditor sharedEditor] countOfFiles]; } |
|---|
| 89 | - (KeyValueTaggedFile *) objectInFilesAtIndex:(unsigned)idx { return [[TagEditor sharedEditor] objectInFilesAtIndex:idx]; } |
|---|
| 90 | |
|---|
| 91 | @end |
|---|