forked from pmougin/F-Script
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFScriptAppController.m
More file actions
549 lines (460 loc) · 21.2 KB
/
FScriptAppController.m
File metadata and controls
549 lines (460 loc) · 21.2 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
/* FScriptAppController.m Copyright 1998-2009 Philippe Mougin. */
/* This software is open source. See the license. */
#import "FScriptAppController.h"
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#import "FSInterpreter.h"
#import "FSInterpreterView.h"
#import "FSSystem.h"
#import "FSBlock.h"
#import "FSArray.h"
#import "FSNSString.h"
#import <ExceptionHandling/NSExceptionHandler.h>
#import "FSServicesProvider.h"
#import "FSMiscTools.h"
#import "FSDemoAssistant.h"
#import <spawn.h>
#import <crt_externs.h>
extern char **environ;
void RestartWithCorrectGarbageCollectionSettingIfNecessary()
{
/* Inspired by code provided by Scotty of the Mac Developer Network. */
/* See http://www.mac-developer-network.com/podcasts/lnc/lnc036/ */
// NSLog(@"Entering in RestartWithCorrectGarbageCollectionSettingIfNecessary()");
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSDictionary* garbageCollectionUserDefaults = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"FScriptRunWithObjCAutomaticGarbageCollection", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:garbageCollectionUserDefaults];
BOOL requireRestart = NO;
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptRunWithObjCAutomaticGarbageCollection"] == YES && [NSGarbageCollector defaultCollector] == nil)
{
// NSLog(@"unsetenv OBJC_DISABLE_GC");
unsetenv("OBJC_DISABLE_GC");
requireRestart = YES;
}
else if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptRunWithObjCAutomaticGarbageCollection"] == NO && [NSGarbageCollector defaultCollector])
{
// NSLog(@"setenv OBJC_DISABLE_GC");
setenv("OBJC_DISABLE_GC", "YES", 1);
requireRestart = YES;
}
if (requireRestart)
{
// NSLog(@"Require restart");
cpu_type_t cpuTypes[2];
#ifdef __ppc__
// 32-bit PowerPC code
cpuTypes[0] = CPU_TYPE_POWERPC;
#else
#ifdef __ppc64__
cpuTypes[0] = CPU_TYPE_POWERPC64;
#else
#ifdef __i386__
// 32-bit Intel code
cpuTypes[0] = CPU_TYPE_I386;
#else
#ifdef __x86_64__
// 64-bit Intel code
cpuTypes[0] = CPU_TYPE_X86_64;
#else
#error UNKNOWN ARCHITECTURE
#endif
#endif
#endif
#endif
cpuTypes[1] = CPU_TYPE_ANY; // Things should work without this entry, but we use it just in case of an unforeseen problem
size_t ocount;
posix_spawnattr_t attribute;
posix_spawnattr_init(&attribute);
posix_spawnattr_setbinpref_np(&attribute, 2, cpuTypes, &ocount);
const int spawnReturnValue = posix_spawn(NULL, (*_NSGetArgv())[0], NULL, &attribute, *_NSGetArgv(), environ);
if(spawnReturnValue == 0)
{
exit(0);
}
else
{
perror("posix_spawn() failed, continuing...");
}
}
[pool release];
}
NSString *findPathToFileInLibraryWithinUserDomain(NSString *fileName)
/*" Returns the path to the first occurrence of fileName in a Library directory within the User domain. "*/
{
NSString *result = nil; // the returned path
NSString *candidate; // candidate paths
NSArray *pathArray; // array of standard locations
NSEnumerator *pathEnumerator; // used to enumerate pathArray
pathArray = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
pathEnumerator = [pathArray objectEnumerator];
while(nil == result && (nil != (candidate = [pathEnumerator nextObject])))
{
result = [candidate stringByAppendingPathComponent:fileName];
if(![[NSFileManager defaultManager] fileExistsAtPath:result])
{
result = nil;
}
}
return result;
}
NSString *findPathToFileInLibraryWithinSystemDomain(NSString *fileName)
/*" Returns the path to the first occurrence of fileName in a Library directory within the System domain. "*/
{
NSString *result = nil; // the returned path
NSString *candidate; // candidate paths
NSArray *pathArray; // array of standard locations
NSEnumerator *pathEnumerator; // used to enumerate pathArray
pathArray = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSSystemDomainMask, YES);
pathEnumerator = [pathArray objectEnumerator];
while(nil == result && (nil != (candidate = [pathEnumerator nextObject])))
{
result = [candidate stringByAppendingPathComponent:fileName];
if(![[NSFileManager defaultManager] fileExistsAtPath:result])
{
result = nil;
}
}
return result;
}
@interface NSUserDefaults(FSNSUserDefaults)
- (void)setObject:(id)value forKey:(NSString *)defaultName inDomain:(NSString *)domainName;
@end
@implementation FScriptAppController
+ (void)initialize
{
NSMutableDictionary *registrationDict = [NSMutableDictionary dictionary];
[registrationDict setObject:[NSNumber numberWithDouble:[[NSFont userFixedPitchFontOfSize:-1] pointSize]] forKey:@"FScriptFontSize"];
[registrationDict setObject:@"NO" forKey:@"FScriptShouldJournal"];
[registrationDict setObject:@"NO" forKey:@"FScriptConfirmWhenQuitting"];
[registrationDict setObject:@"YES" forKey:@"FScriptDisplayObjectBrowserAtLaunchTime"];
[registrationDict setObject:@"YES" forKey:@"FScriptRunWithObjCAutomaticGarbageCollection"];
[registrationDict setObject:@"YES" forKey:@"FScriptAutomaticallyIntrospectDeclaredProperties"];
[registrationDict setObject:@"NO" forKey:@"FScriptShowDemoAssistant"];
[registrationDict setObject:@"NO" forKey:@"FScriptLoadSystemFrameworks"];
[registrationDict setObject:@"NO" forKey:@"FScriptLoadPrivateSystemFrameworks"];
[[NSUserDefaults standardUserDefaults] registerDefaults:registrationDict];
}
- (void)loadSystemFrameworks // Contributed by Cedric Luthi
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *systemFrameworksPaths = [NSMutableArray arrayWithObject:@"/System/Library/Frameworks"];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptLoadPrivateSystemFrameworks"])
[systemFrameworksPaths addObject:@"/System/Library/PrivateFrameworks"];
for (NSString *systemFrameworksPath in systemFrameworksPaths)
{
for (NSString *framework in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:systemFrameworksPath error:NULL])
{
NSBundle *frameworkBundle = [NSBundle bundleWithPath:[systemFrameworksPath stringByAppendingPathComponent:framework]];
if ([frameworkBundle preflightAndReturnError:nil])
[frameworkBundle load];
}
}
[pool drain];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL b = NO;
NSString *latent;
NSString *latentPath;
NSString *repositoryPath = [[NSUserDefaults standardUserDefaults] stringForKey:@"FScriptRepositoryPath"];
FSServicesProvider *servicesProvider;
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptLoadSystemFrameworks"])
[self loadSystemFrameworks];
if (floor(NSAppKitVersionNumber) > 949)
{
// 10.6 or later system
NSString *systemFrameworksDirectoryPath;
NSString *path;
systemFrameworksDirectoryPath = findPathToFileInLibraryWithinSystemDomain(@"Frameworks");
if (systemFrameworksDirectoryPath)
{
path = [systemFrameworksDirectoryPath stringByAppendingPathComponent:@"PreferencePanes.framework"]; [[NSBundle bundleWithPath:path] load];
path = [systemFrameworksDirectoryPath stringByAppendingPathComponent:@"ScreenSaver.framework"]; [[NSBundle bundleWithPath:path] load];
path = [systemFrameworksDirectoryPath stringByAppendingPathComponent:@"CoreLocation.framework"]; [[NSBundle bundleWithPath:path] load];
path = [systemFrameworksDirectoryPath stringByAppendingPathComponent:@"CoreWLAN.framework"]; [[NSBundle bundleWithPath:path] load];
path = [systemFrameworksDirectoryPath stringByAppendingPathComponent:@"ImageCaptureCore.framework"]; [[NSBundle bundleWithPath:path] load];
path = [systemFrameworksDirectoryPath stringByAppendingPathComponent:@"OpenDirectory.framework"]; [[NSBundle bundleWithPath:path] load];
path = [systemFrameworksDirectoryPath stringByAppendingPathComponent:@"ServerNotification.framework"]; [[NSBundle bundleWithPath:path] load];
}
}
if (!repositoryPath || ![fileManager fileExistsAtPath:repositoryPath isDirectory:&b])
{
NSError *error = nil;
NSString *applicationSupportDirectoryPath = findPathToFileInLibraryWithinUserDomain(@"Application Support");
BOOL repositoryCreated = NO;
if (!applicationSupportDirectoryPath)
{
NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
if ([pathArray count] > 0)
[fileManager createDirectoryAtPath:[[pathArray objectAtIndex:0] stringByAppendingPathComponent:@"Application Support"] withIntermediateDirectories:NO attributes:nil error:NULL];
}
applicationSupportDirectoryPath = findPathToFileInLibraryWithinUserDomain(@"Application Support");
if (applicationSupportDirectoryPath)
{
repositoryPath = [applicationSupportDirectoryPath stringByAppendingPathComponent:@"F-Script"];
[fileManager createDirectoryAtPath:[repositoryPath stringByAppendingPathComponent:@"classes"] withIntermediateDirectories:YES attributes:nil error:&error];
if (error)
NSLog(@"Failed to create the repository: %@", error);
else
{
repositoryCreated = YES;
if ([[NSUserDefaults standardUserDefaults] respondsToSelector:@selector(setObject:forKey:inDomain:)])
[[NSUserDefaults standardUserDefaults] setObject:repositoryPath forKey:@"FScriptRepositoryPath" inDomain:NSGlobalDomain]; // This is an undocumented Cocoa API in Mac OS X 10.1
else
[[NSUserDefaults standardUserDefaults] setObject:repositoryPath forKey:@"FScriptRepositoryPath"];
[[NSUserDefaults standardUserDefaults] setObject:[repositoryPath stringByAppendingPathComponent:@"journal.txt"] forKey:@"FScriptJournalName"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
else
{
NSLog(@"Failed to create the repository in the user's \"Application Support\" directory.");
}
if (!repositoryCreated)
{
NSInteger choice = NSRunAlertPanel(@"Instalation" , @"F-Script is about to create a directory named \"FScriptRepository\" in your home directory. This directory will be used as a repository for things like extension bundles for F-Script and a journal file.", @"create the repository", @"don't create the repository", @"create the repository elsewhere...");
if (choice == NSAlertOtherReturn || choice == NSAlertDefaultReturn)
{
if (choice == NSAlertOtherReturn)
{
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseFiles:NO];
[openPanel setCanChooseDirectories:YES];
[openPanel setTitle:@"Choose the directory that will become the F-Script repository"];
if([openPanel runModal] == NSOKButton) repositoryPath = [openPanel filename];
else repositoryPath = nil;
}
else repositoryPath = [NSHomeDirectory() stringByAppendingPathComponent:@"FScriptRepository"];
error = nil;
[fileManager createDirectoryAtPath:[repositoryPath stringByAppendingPathComponent:@"classes"] withIntermediateDirectories:YES attributes:nil error:&error];
if (error)
NSLog(@"Failed to create the repository: %@", error);
else
{
repositoryCreated = YES;
if ([[NSUserDefaults standardUserDefaults] respondsToSelector:@selector(setObject:forKey:inDomain:)])
[[NSUserDefaults standardUserDefaults] setObject:repositoryPath forKey:@"FScriptRepositoryPath" inDomain:NSGlobalDomain]; // This is an undocumented Cocoa API in Mac OS X 10.1
else
[[NSUserDefaults standardUserDefaults] setObject:repositoryPath forKey:@"FScriptRepositoryPath"];
[[NSUserDefaults standardUserDefaults] setObject:[repositoryPath stringByAppendingPathComponent:@"journal.txt"] forKey:@"FScriptJournalName"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
}
}
else if (!(b && [fileManager isWritableFileAtPath:repositoryPath])) // partial consistency check
{
NSLog(@"fatal problem: the repository file \"%@\" is not a directory or is not writable", repositoryPath);
exit(1);
}
// Initialize the random number generator with random seeds
srandomdev();
srand48(random());
// We will catch most unhandled run-time error with this.
[[NSExceptionHandler defaultExceptionHandler] setExceptionHandlingMask:63];
// We initialize the journaling system
[[interpreterView interpreter] setShouldJournal:[[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptShouldJournal"]];
if (repositoryPath) [[NSUserDefaults standardUserDefaults] setObject:[repositoryPath stringByAppendingPathComponent:@"journal.txt"] forKey:@"FScriptJournalName"];
[[interpreterView interpreter] setJournalName:[[NSUserDefaults standardUserDefaults] stringForKey:@"FScriptJournalName"]];
// JG
servicesProvider = [[FSServicesProvider alloc] initWithFScriptInterpreterViewProvider:self];
[servicesProvider registerExports];
// Latent block processing
latentPath = [[[NSUserDefaults standardUserDefaults] stringForKey:@"FScriptRepositoryPath"] stringByAppendingPathComponent:@"fs_latent"];
if (latentPath && [[NSFileManager defaultManager] fileExistsAtPath:latentPath])
{
NSStringEncoding usedEncoding;
NSError *error;
latent = [NSString stringWithContentsOfFile:latentPath usedEncoding:&usedEncoding error:&error];
if (!latent)
{
NSLog(@"Unable to read the latent block: %@", [error localizedDescription]);
}
else
{
BOOL found;
FSInterpreter *interpreter = [interpreterView interpreter];
FSSystem *sys = [interpreter objectForIdentifier:@"sys" found:&found];
FSBlock *bl;
NSAssert(found,@"F-Script internal error: symbol \"sys\" not defined");
@try
{
bl = [sys blockFromString:latent];
[bl value];
}
@catch (id exception)
{
[interpreterView notifyUser:[NSString stringWithFormat:@"Error in the latent block (file %@): %@",latentPath, FSErrorMessageFromException(exception)]];
}
}
}
//----------
[[interpreterView window] makeKeyAndOrderFront:nil];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptDisplayObjectBrowserAtLaunchTime"])
[[interpreterView interpreter] browse];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptShowDemoAssistant"])
[[[FSDemoAssistant alloc] initWithInterpreterView:interpreterView] activate];
}
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
[self performSelector:@selector(openFile:) withObject:filename afterDelay:0];
return YES;
}
- (void)openFile:(NSString *)filename
{
{ // generates a filename with a unix style path separator
FSArray *elems = [filename asArray];
NSUInteger i, nb;
for (i = 0, nb = [elems count]; i < nb; i++)
if ([[elems objectAtIndex:i] isEqual:@"\\"]) [elems replaceObjectAtIndex:i withObject:@"/"];
filename = [elems operator_backslash:[@"#++" asBlock]];
}
if ([[filename pathExtension] isEqualToString:@"space"])
[interpreterView putCommand:[NSString stringWithFormat:@"sys loadSpace:%@\n",filename]];
else
{
NSString *fname = [filename lastPathComponent];
NSUInteger nb = [fname length];
while (nb != ([fname = [fname stringByDeletingPathExtension] length]))
nb = [fname length]; // remove all the extentions
[interpreterView putCommand:[NSString stringWithFormat:@"%@ := sys load:%@",fname,filename]];
}
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptConfirmWhenQuitting"] && !quitConfirmed)
{
NSInteger choice = NSRunAlertPanel(@"QUIT", @"Are you sure you want to quit F-Script?", @"Quit", @"Cancel", nil,nil);
if (choice == NSAlertDefaultReturn) return NSTerminateNow;
else return NSTerminateCancel; // don't quit
}
else return NSTerminateNow;
}
- (void)dealloc
{
if ((id)[[NSApplication sharedApplication] delegate] == self)
[[NSApplication sharedApplication] setDelegate:nil];
// since we don't retain outlets infoPanel and interpreterView, we don't have to release them here.
[showConsoleMenuItem release];
[super dealloc];
}
- (id) init
{
self = [super init];
if (self != nil)
{
showConsoleMenuItem = [[NSMenuItem alloc] initWithTitle:@"F-Script" action:@selector(showConsole:) keyEquivalent:@""];
quitConfirmed = NO;
}
return self;
}
- (id)interpreterView // For use by JG FSServiceProvider
{
return interpreterView;
}
- (void)newDemoAssistant:(id)sender
{
[[[FSDemoAssistant alloc] initWithInterpreterView:interpreterView] activate];
}
- (void)newObjectBrowser:sender
{
[[interpreterView interpreter] browse];
}
- (void)showConsole:(id)sender
{
NSMenu *windowMenu = [[[NSApp mainMenu] itemWithTitle:@"Window"] submenu];
[[interpreterView window] makeKeyAndOrderFront:nil];
[windowMenu removeItem:showConsoleMenuItem];
}
- (void)showInfoPanel:(id)sender
{
/*if (!infoPanel)
{
if (![NSBundle loadNibNamed:@"FScriptAppInfo" owner:self]) {
NSLog(@"Failed to load FScriptAppInfo.nib");
NSBeep();
return;
}
[infoPanel center];
}
[infoPanel makeKeyAndOrderFront:nil];
*/
NSMutableAttributedString *s = [[[NSMutableAttributedString alloc] initWithString:@"http://www.fscript.org" attributes:[NSDictionary dictionaryWithObject:@"http://www.fscript.org" forKey:NSLinkAttributeName]] autorelease];
[NSApp orderFrontStandardAboutPanelWithOptions:[NSDictionary dictionaryWithObject:s forKey:@"Credits"]];
}
- (void)showPreferencePanel:(id)sender
{
if (!preferencePanel)
{
if (![NSBundle loadNibNamed:@"FScriptAppPreference" owner:self])
{
NSLog(@"Failed to load FScriptAppPreference.nib");
NSBeep();
return;
}
[preferencePanel center];
}
[fontSizeUI setDoubleValue:[interpreterView fontSize]];
[shouldJournalUI setState:[[interpreterView interpreter] shouldJournal]];
[confirmWhenQuittingUI setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptConfirmWhenQuitting"]];
[runWithObjCAutomaticGarbageCollectionUI setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptRunWithObjCAutomaticGarbageCollection"]];
[displayObjectBrowserAtLaunchTimeUI setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptDisplayObjectBrowserAtLaunchTime"]];
[automaticallyIntrospectDeclaredPropertiesUI setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptAutomaticallyIntrospectDeclaredProperties"]];
[preferencePanel makeKeyAndOrderFront:nil];
}
- (void)updatePreference:(id)sender // action
{
//NSLog(@"** updatePreference");
if (sender == fontSizeUI)
{
[[NSUserDefaults standardUserDefaults] setDouble:[fontSizeUI doubleValue] forKey:@"FScriptFontSize"];
[interpreterView setFontSize:[fontSizeUI doubleValue]];
}
else if (sender == shouldJournalUI)
{
[[NSUserDefaults standardUserDefaults] setBool:[shouldJournalUI state] forKey:@"FScriptShouldJournal"];
[[interpreterView interpreter] setShouldJournal:[shouldJournalUI state]];
}
else if (sender == confirmWhenQuittingUI)
{
[[NSUserDefaults standardUserDefaults] setBool:[confirmWhenQuittingUI state] forKey:@"FScriptConfirmWhenQuitting"];
}
else if (sender == displayObjectBrowserAtLaunchTimeUI)
{
[[NSUserDefaults standardUserDefaults] setBool:[displayObjectBrowserAtLaunchTimeUI state] forKey:@"FScriptDisplayObjectBrowserAtLaunchTime"];
}
else if (sender == automaticallyIntrospectDeclaredPropertiesUI)
{
[[NSUserDefaults standardUserDefaults] setBool:[automaticallyIntrospectDeclaredPropertiesUI state] forKey:@"FScriptAutomaticallyIntrospectDeclaredProperties"];
}
else if (sender == runWithObjCAutomaticGarbageCollectionUI)
{
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Restart"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:@"Restart F-Script?"];
[alert setInformativeText:@"F-Script needs to be restarted to change the memory management mode"];
[alert setAlertStyle:NSWarningAlertStyle];
if ([alert runModal] == NSAlertFirstButtonReturn)
{
// Restart clicked
[[NSUserDefaults standardUserDefaults] setBool:[runWithObjCAutomaticGarbageCollectionUI state] forKey:@"FScriptRunWithObjCAutomaticGarbageCollection"];
[[NSUserDefaults standardUserDefaults] synchronize];
RestartWithCorrectGarbageCollectionSettingIfNecessary();
}
else
{
// Cancel clicked
[runWithObjCAutomaticGarbageCollectionUI setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"FScriptRunWithObjCAutomaticGarbageCollection"]];
}
[alert release];
}
}
////////// Window delegate methods (I'm the delegate of the the console window)
- (void)windowWillClose:(NSNotification *)aNotification
{
NSMenu *windowMenu = [[[NSApp mainMenu] itemWithTitle:@"Window"] submenu];
[windowMenu insertItem:showConsoleMenuItem atIndex:[windowMenu numberOfItems]];
}
@end