forked from sbooth/Tag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApplicationDelegate.m
91 lines (74 loc) · 3 KB
/
ApplicationDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* $Id$
*
* Copyright (C) 2005, 2006 Stephen F. Booth <me@sbooth.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#import "ApplicationDelegate.h"
#import "PreferencesController.h"
#import "AcknowledgmentsController.h"
#import "UppercaseStringValueTransformer.h"
#import "TagEditor.h"
#import "ServicesProvider.h"
@implementation ApplicationDelegate
+ (void)initialize
{
NSValueTransformer *transformer;
transformer = [[[UppercaseStringValueTransformer alloc] init] autorelease];
[NSValueTransformer setValueTransformer:transformer forName:@"UppercaseStringValueTransformer"];
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:@"startupVersionCheck"]];
}
- (void) applicationWillFinishLaunching:(NSNotification *)aNotification
{
[[TagEditor sharedEditor] showWindow:self];
}
- (void) applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Register services
[[NSApplication sharedApplication] setServicesProvider:[[ServicesProvider alloc] init]];
}
- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication *) sender
{
return ([[TagEditor sharedEditor] applicationShouldTerminate] ? NSTerminateNow : NSTerminateCancel);
}
- (void) application:(NSApplication *)sender openFiles:(NSArray *)filenames
{
TagEditor *editor = [TagEditor sharedEditor];
NSEnumerator *enumerator;
NSString *filename;
BOOL success = YES;
enumerator = [filenames objectEnumerator];
while((filename = [enumerator nextObject])) {
success &= [editor addFile:[filename stringByExpandingTildeInPath]];
}
[editor openFilesDrawerIfNeeded];
[[NSApplication sharedApplication] replyToOpenOrPrint:(success ? NSApplicationDelegateReplySuccess : NSApplicationDelegateReplyFailure)];
}
- (BOOL) application:(NSApplication *)sender delegateHandlesKey:(NSString *)key
{
return [key isEqualToString:@"files"];
}
- (IBAction) showPreferences:(id)sender
{
[[PreferencesController sharedPreferences] showWindow:self];
}
- (IBAction) showAcknowledgments:(id)sender
{
[[AcknowledgmentsController sharedController] showWindow:self];
}
- (unsigned) countOfFiles { return [[TagEditor sharedEditor] countOfFiles]; }
- (KeyValueTaggedFile *) objectInFilesAtIndex:(unsigned)idx { return [[TagEditor sharedEditor] objectInFilesAtIndex:idx]; }
@end