-
Notifications
You must be signed in to change notification settings - Fork 0
/
TLLaunchWindowController.m
131 lines (109 loc) · 3.71 KB
/
TLLaunchWindowController.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// TLLaunchWindowController.m
// Tagalog
//
// Created by Nathan Vander Wilt on 4/20/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "TLLaunchWindowController.h"
#import "TLJimBos.h"
#import "TLImageCaptureManager.h"
@implementation TLLaunchWindowController
@synthesize window;
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[self window] setDelegate:nil];
[self setWindow:nil];
[recentDocumentItems release];
[super dealloc];
}
- (void)appRegistered:(NSNotification*)aNotification {
(void)aNotification;
[demoInfo setHidden:YES];
}
/* NOTE: Fontin font must be installed on build machine, or a default font name gets saved to compiled NIB */
- (void)loadLocalFonts {
// Based on http://www.cocoabuilder.com/archive/message/cocoa/2005/1/16/125883
// see also http://www.cocoabuilder.com/archive/message/cocoa/2007/1/24/177638
NSString* fontsFolder = [[NSBundle mainBundle] resourcePath];
if (fontsFolder) {
NSURL* fontsURL = [NSURL fileURLWithPath:fontsFolder isDirectory:YES];
if (fontsURL) {
FSRef fsRef;
Boolean success = CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
if (success) {
ATSFontActivateFromFileReference(&fsRef, kATSFontContextLocal, kATSFontFormatUnspecified,
NULL, kATSOptionFlagsProcessSubdirectories, NULL);
}
}
}
}
- (void)loadWindow {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appRegistered:)
name:TLJimBosAppRegisteredNotification
object:nil];
[self loadLocalFonts];
BOOL loaded = [NSBundle loadNibNamed:@"Launch" owner:self];
if (!loaded) {
NSLog(@"Couldn't load launch window");
}
[[self window] setDelegate:self];
if (![[TLJimBos sharedRegistrar] isRegistered]) {
[demoInfo setHidden:NO];
}
if ([[TLImageCaptureManager sharedImageCaptureManager] shouldAutoLaunch]) {
[cameraLaunch setState:NSOnState];
}
else {
[cameraLaunch setState:NSOffState];
}
}
- (NSWindow*)window {
if (!window) {
[self loadWindow];
}
return window;
}
- (IBAction)toggleCameraLaunch:(id)sender {
(void)sender;
BOOL newAutoLaunch = ([cameraLaunch state] == NSOnState);
[[TLImageCaptureManager sharedImageCaptureManager] setShouldAutoLaunch:newAutoLaunch];
}
- (IBAction)openTracklog:(id)sender {
if ([[NSApp delegate] respondsToSelector:@selector(openDocument:)]) {
(void)[[NSApp delegate] openDocument:sender];
}
}
- (IBAction)openRecentTracklog:(id)sender {
(void)sender;
if ([[NSApp delegate] respondsToSelector:@selector(application:openFile:)]) {
NSMenuItem* item = [openRecent selectedItem];
NSString* filename = [recentDocumentItems objectForKey:item];
(void)[[NSApp delegate] application:NSApp openFile:filename];
}
}
- (IBAction)buyTagalog:(id)sender {
[[TLJimBos sharedRegistrar] buyMercatalog:sender];
}
- (void)windowDidBecomeKey:(NSNotification*)notification {
(void)notification;
[recentDocumentItems release];
recentDocumentItems = [[NSMapTable mapTableWithStrongToStrongObjects] retain];
NSArray* recentFileURLs = [[NSDocumentController sharedDocumentController] recentDocumentURLs];
NSMenu* newRecentMenu = [[NSMenu new] autorelease];
NSMenuItem* newTitleItem = [[NSMenuItem new] autorelease];
NSMenuItem* oldTitleItem = [[openRecent menu] itemAtIndex:0];
[newTitleItem setTitle:[oldTitleItem title]];
[newRecentMenu addItem:newTitleItem];
for (NSURL* recentURL in recentFileURLs) {
NSString* filename = [recentURL path];
NSMenuItem* item = [[NSMenuItem new] autorelease];
[item setTitle:[filename lastPathComponent]];
[newRecentMenu addItem:item];
[recentDocumentItems setObject:filename forKey:item];
}
[openRecent setMenu:newRecentMenu];
[openRecent setEnabled:([recentFileURLs count] ? YES : NO)];
}
@end