Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 150 lines (103 sloc) 4.208 kb
ee99867 @ccgus oh geeze
authored
1 //
2 // JSTAppDelegate.m
3 // jstalk
4 //
5 // Created by August Mueller on 1/14/09.
6 // Copyright 2009 Flying Meat Inc. All rights reserved.
7 //
8
9 #import "JSTAppDelegate.h"
ad40277 @ccgus Exposing and testing JSTalk's setShouldLoadExtras:
authored
10 #import "JSTalk.h"
ee99867 @ccgus oh geeze
authored
11
12 @interface JSTAppDelegate (PrivateStuff)
13 - (void) restoreWorkspace;
14 - (void) saveWorkspace;
bdf823d @ccgus [NEW] Added support for "External Editors". It's small, but it's someth...
authored
15 - (void) loadExternalEditorPrefs;
ee99867 @ccgus oh geeze
authored
16 @end
17
18 @implementation JSTAppDelegate
19
20 + (void) initialize {
21
22
23 NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
24 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
25
26 [defaultValues setObject:[NSNumber numberWithBool:YES] forKey:@"rememberWorkspace"];
27 [defaultValues setObject:[NSNumber numberWithBool:YES] forKey:@"clearConsoleOnRun"];
bdf823d @ccgus [NEW] Added support for "External Editors". It's small, but it's someth...
authored
28 [defaultValues setObject:@"com.apple.xcode" forKey:@"externalEditor"];
ee99867 @ccgus oh geeze
authored
29
30 [defaults registerDefaults: defaultValues];
31 [[NSUserDefaultsController sharedUserDefaultsController] setInitialValues:defaultValues];
32 }
33
34
35 - (void)awakeFromNib {
36
37 if ([JSTPrefs boolForKey:@"rememberWorkspace"]) {
38 [self restoreWorkspace];
39 }
40
ad40277 @ccgus Exposing and testing JSTalk's setShouldLoadExtras:
authored
41 [JSTalk setShouldLoadExtras:YES];
42 [JSTalk listen];
ee99867 @ccgus oh geeze
authored
43 }
44
45 - (IBAction) showPrefs:(id)sender {
46
bdf823d @ccgus [NEW] Added support for "External Editors". It's small, but it's someth...
authored
47 [self loadExternalEditorPrefs];
48
ee99867 @ccgus oh geeze
authored
49 if (![prefsWindow isVisible]) {
50 [prefsWindow center];
51 }
52
53 [prefsWindow makeKeyAndOrderFront:self];
54 }
55
56 - (void)applicationWillTerminate:(NSNotification *)aNotification {
57 [self saveWorkspace];
58 }
59
60 - (void) restoreWorkspace {
61
62 NSArray *ar = [[NSUserDefaults standardUserDefaults] objectForKey:@"workspaceOpenDocuments"];
63
64 for (NSString *path in ar) {
65 [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:[NSURL fileURLWithPath:path] display:YES error:nil];
66 }
67 }
68
69 - (void) saveWorkspace {
70
71 NSMutableArray *openDocs = [NSMutableArray array];
72
73 for (NSDocument *doc in [[NSDocumentController sharedDocumentController] documents]) {
74
75 if ([doc fileName]) {
76 // saving the file alias would be better.
77 [openDocs addObject:[doc fileName]];
78 }
79 }
80
81 [[NSUserDefaults standardUserDefaults] setObject:openDocs forKey:@"workspaceOpenDocuments"];
82 [[NSUserDefaults standardUserDefaults] synchronize];
83 }
84
bdf823d @ccgus [NEW] Added support for "External Editors". It's small, but it's someth...
authored
85
86 - (void) loadExternalEditorPrefs {
87
88 NSString *editorId = [[NSUserDefaults standardUserDefaults] objectForKey:@"externalEditor"];
89
90 NSWorkspace *ws = [NSWorkspace sharedWorkspace];
91 NSString *appPath = [ws absolutePathForAppBundleWithIdentifier:editorId];
92 NSString *appName = nil;
93
94 if (appPath) {
95
96 NSBundle *appBundle = [NSBundle bundleWithPath:appPath];
97 NSString *bundleName = [appBundle objectForInfoDictionaryKey:@"CFBundleName"];
98
99 if (bundleName) {
100 appName = bundleName;
101 }
102 }
103
104 if (!appName) {
105 appName = @"Unknown";
106 }
107
108 [externalEditorField setStringValue:appName];
109 }
110
111 - (void)openPanelDidEndForExternalEditor:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo {
112 if (returnCode) {
113
114 NSString *path = [sheet filename];
115
116 NSBundle *appBundle = [NSBundle bundleWithPath:path];
117 NSString *bundleId = [appBundle bundleIdentifier];
118
119 if (!bundleId) {
120 NSBeep();
121 NSLog(@"Could not load the bundle info for %@", bundleId);
122 return;
123 }
124
125 [[NSUserDefaults standardUserDefaults] setObject:bundleId forKey:@"externalEditor"];
126
127 [self loadExternalEditorPrefs];
128
129 }
130 }
131
132 - (void) chooseExternalEditor:(id)sender {
133
134 NSOpenPanel *p = [NSOpenPanel openPanel];
135
136 [p setCanChooseFiles:YES];
137 [p setCanChooseDirectories:NO];
138 [p setAllowsMultipleSelection:NO];
139
140 [p beginSheetForDirectory:@"/Applications"
141 file:nil
142 types:[NSArray arrayWithObjects:@"app", @"APPL", nil]
143 modalForWindow:prefsWindow
144 modalDelegate:self
145 didEndSelector:@selector(openPanelDidEndForExternalEditor:returnCode:contextInfo:)
146 contextInfo:nil];
147 }
148
ee99867 @ccgus oh geeze
authored
149 @end
Something went wrong with that request. Please try again.