-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLaunchWindowController.m
More file actions
112 lines (94 loc) · 3.23 KB
/
LaunchWindowController.m
File metadata and controls
112 lines (94 loc) · 3.23 KB
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
//
// LaunchWindowController.m
// Geotagalog
//
// Created by Nathan Vander Wilt on 4/20/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "LaunchWindowController.h"
#import "TLImageCaptureManager.h"
@implementation LaunchWindowController
@synthesize window;
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[self window] setDelegate:nil];
[self setWindow:nil];
[recentDocumentItems release];
[super dealloc];
}
/* 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 {
[self loadLocalFonts];
BOOL loaded = [NSBundle loadNibNamed:@"Launch" owner:self];
if (!loaded) {
NSLog(@"Couldn't load launch window");
}
[[self window] setDelegate:self];
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];
}
}
- (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