forked from erkyrath/Inform7-IDE-Mac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIFProjectController.m
3643 lines (2874 loc) · 117 KB
/
IFProjectController.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
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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// IFProjectController.m
// Inform
//
// Created by Andrew Hunter on Wed Aug 27 2003.
// Copyright (c) 2003 Andrew Hunter. All rights reserved.
//
#import "IFProject.h"
#import "IFAppDelegate.h"
#import "IFProjectController.h"
#import "IFProjectPane.h"
#import "IFInspectorWindow.h"
#import "IFNewProjectFile.h"
#import "IFIsIndex.h"
#import "IFWelcomeWindow.h"
#import "IFInform7MutableString.h"
#import "IFPreferences.h"
#import "IFSingleFile.h"
#import "IFNaturalIntel.h"
#import "IFIsFiles.h"
#import "IFIsWatch.h"
#import "IFIsBreakpoints.h"
#import "IFSearchResultsController.h"
#import "IFExtensionsManager.h"
#import "IFOutputSettings.h"
#import "IFCustomPopup.h"
// = Preferences =
NSString* IFSplitViewSizes = @"IFSplitViewSizes";
NSString* IFSourceSpellChecking = @"IFSourceSpellChecking";
// = Private methods =
@interface IFProjectController(Private)
- (void) refreshIndexTabs;
- (void) runCompilerOutput;
- (void) runCompilerOutputAndReplay;
- (IFGamePage*) gamePage;
@end
@implementation IFProjectController
// == Toolbar items ==
static NSToolbarItem* compileItem = nil;
static NSToolbarItem* compileAndRunItem = nil;
static NSToolbarItem* replayItem = nil;
static NSToolbarItem* compileAndDebugItem = nil;
static NSToolbarItem* releaseItem = nil;
static NSToolbarItem* refreshIndexItem = nil;
static NSToolbarItem* stopItem = nil;
static NSToolbarItem* pauseItem = nil;
static NSToolbarItem* continueItem = nil;
static NSToolbarItem* stepItem = nil;
static NSToolbarItem* stepOverItem = nil;
static NSToolbarItem* stepOutItem = nil;
static NSToolbarItem* indexItem = nil;
static NSToolbarItem* watchItem = nil;
static NSToolbarItem* breakpointItem = nil;
static NSToolbarItem* searchDocsItem = nil;
static NSToolbarItem* searchProjectItem = nil;
static NSDictionary* itemDictionary = nil;
+ (void) initialize {
// Register our preferences
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults registerDefaults: [NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObjects: [NSNumber numberWithFloat: 0.625], [NSNumber numberWithFloat: 0.375], nil], IFSplitViewSizes,
[NSNumber numberWithBool: NO], IFSourceSpellChecking,
nil]];
// Create the toolbar items
compileItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"compileItem"];
compileAndRunItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"compileAndRunItem"];
compileAndDebugItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"compileAndDebugItem"];
releaseItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"releaseItem"];
replayItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"replayItem"];
refreshIndexItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"refreshIndexItem"];
stopItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"stopItem"];
continueItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"continueItem"];
pauseItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"pauseItem"];
stepItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"stepItem"];
stepOverItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"stepOverItem"];
stepOutItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"stepOutItem"];
indexItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"indexItem"];
watchItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"watchItem"];
breakpointItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"breakpointItem"];
searchDocsItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"searchDocsItem"];
searchProjectItem = [[NSToolbarItem alloc] initWithItemIdentifier: @"searchProjectItem"];
itemDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
compileItem, @"compileItem",
compileAndRunItem, @"compileAndRunItem",
replayItem, @"replayItem",
refreshIndexItem, @"refreshIndexItem",
compileAndDebugItem, @"compileAndDebugItem",
releaseItem, @"releaseItem",
stopItem, @"stopItem",
pauseItem, @"pauseItem",
continueItem, @"continueItem",
stepItem, @"stepItem",
stepOverItem, @"stepOverItem",
stepOutItem, @"stepOutItem",
indexItem, @"indexItem",
watchItem, @"watchItem",
breakpointItem, @"breakpointItem",
searchDocsItem, @"searchDocsItem",
searchProjectItem, @"searchProjectItem",
nil];
// Images
[compileItem setImage: [NSImage imageNamed: @"compile"]];
[compileAndRunItem setImage: [NSImage imageNamed: @"run"]];
[compileAndDebugItem setImage: [NSImage imageNamed: @"debug"]];
[releaseItem setImage: [NSImage imageNamed: @"release"]];
[replayItem setImage: [NSImage imageNamed: @"replay"]];
[refreshIndexItem setImage: [NSImage imageNamed: @"refresh_index"]];
[stopItem setImage: [NSImage imageNamed: @"stop"]];
[pauseItem setImage: [NSImage imageNamed: @"pause"]];
[continueItem setImage: [NSImage imageNamed: @"continue"]];
[stepItem setImage: [NSImage imageNamed: @"step"]];
[stepOverItem setImage: [NSImage imageNamed: @"stepover"]];
[stepOutItem setImage: [NSImage imageNamed: @"stepout"]];
[indexItem setImage: [NSImage imageNamed: @"index"]];
[watchItem setImage: [NSImage imageNamed: @"watch"]];
[breakpointItem setImage: [NSImage imageNamed: @"breakpoint"]];
// Labels
[compileItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Compile"
value: @"Compile"
table: nil]];
[compileAndRunItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Go!"
value: @"Go!"
table: nil]];
[compileAndDebugItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Debug"
value: @"Debug"
table: nil]];
[releaseItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Release"
value: @"Release"
table: nil]];
[replayItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Replay"
value: @"Replay"
table: nil]];
[refreshIndexItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Refresh Index"
value: @"Refresh Index"
table: nil]];
[stepItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Step"
value: @"Step"
table: nil]];
[stepOverItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Step over"
value: @"Step over"
table: nil]];
[stepOutItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Step out"
value: @"Step out"
table: nil]];
[stopItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Stop"
value: @"Stop"
table: nil]];
[pauseItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Pause"
value: @"Pause"
table: nil]];
[continueItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Continue"
value: @"Continue"
table: nil]];
[indexItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Index"
value: @"Index"
table: nil]];
[watchItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Watch"
value: @"Watch"
table: nil]];
[breakpointItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Breakpoints"
value: @"Breakpoints"
table: nil]];
[searchDocsItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Search Documentation"
value: @"Search Documentation"
table: nil]];
[searchProjectItem setLabel: [[NSBundle mainBundle] localizedStringForKey: @"Search Project"
value: @"Search Project"
table: nil]];
// The tooltips
[compileItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"CompileTip"
value: nil
table: nil]];
[compileAndRunItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"GoTip"
value: nil
table: nil]];
[compileAndDebugItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"DebugTip"
value: nil
table: nil]];
[releaseItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"ReleaseTip"
value: nil
table: nil]];
[replayItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"ReplayTip"
value: nil
table: nil]];
[stepItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"StepTip"
value: nil
table: nil]];
[stepOverItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"StepOverTip"
value: nil
table: nil]];
[stepOutItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"StepOutTip"
value: nil
table: nil]];
[stopItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"StopTip"
value: nil
table: nil]];
[pauseItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"PauseTip"
value: nil
table: nil]];
[continueItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"ContinueTip"
value: nil
table: nil]];
[indexItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"IndexTip"
value: nil
table: nil]];
[watchItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"WatchTip"
value: nil
table: nil]];
[breakpointItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"BreakpointsTip"
value: nil
table: nil]];
[searchDocsItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"SearchDocsTip"
value: nil
table: nil]];
[searchProjectItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"SearchProjectTip"
value: nil
table: nil]];
[refreshIndexItem setToolTip: [[NSBundle mainBundle] localizedStringForKey: @"RefreshIndexTip"
value: nil
table: nil]];
// The action heroes
[compileItem setAction: @selector(compile:)];
[compileAndRunItem setAction: @selector(compileAndRun:)];
[compileAndDebugItem setAction: @selector(compileAndDebug:)];
[releaseItem setAction: @selector(release:)];
[replayItem setAction: @selector(replayUsingSkein:)];
[refreshIndexItem setAction: @selector(compileAndRefresh:)];
[indexItem setAction: @selector(docIndex:)];
[stopItem setAction: @selector(stopProcess:)];
[pauseItem setAction: @selector(pauseProcess:)];
[continueItem setAction: @selector(continueProcess:)];
[stepItem setAction: @selector(stepIntoProcess:)];
[stepOverItem setAction: @selector(stepOverProcess:)];
[stepOutItem setAction: @selector(stepOutProcess:)];
[watchItem setAction: @selector(showWatchpoints:)];
[breakpointItem setAction: @selector(showBreakpoints:)];
}
// == Initialistion ==
- (id) init {
self = [super initWithWindowNibName:@"Project"];
if (self) {
toolbar = nil;
projectPanes = [[NSMutableArray allocWithZone: [self zone]] init];
splitViews = [[NSMutableArray allocWithZone: [self zone]] init];
lineHighlighting = [[NSMutableDictionary allocWithZone: [self zone]] init];
[self setShouldCloseDocument: YES];
generalPolicy = [[IFProjectPolicy alloc] initWithProjectController: self];
docPolicy = [[IFProjectPolicy alloc] initWithProjectController: self];
[docPolicy setRedirectToDocs: YES];
progressIndicators = [[NSMutableArray alloc] init];
progressing = NO;
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(extensionsUpdated:)
name: IFExtensionsUpdatedNotification
object: nil];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(intelFileChanged:)
name: IFIntelFileHasChangedNotification
object: nil];
headerController = [[IFHeaderController alloc] init];
}
return self;
}
- (void) dealloc {
[progressIndicators makeObjectsPerformSelector: @selector(setDelegate:)
withObject: nil];
[[NSNotificationCenter defaultCenter] removeObserver: self];
if (toolbar) [toolbar release];
[projectPanes release];
[splitViews release];
[lastFilename release];
[lineHighlighting release];
[generalPolicy release];
[docPolicy release];
[progressIndicators release];
[processingSyntax release];
[skeinNodeStack release];
[headerController release];
[super dealloc];
}
- (void) updateSettings {
// Update the toolbar if required
NSString* toolbarIdentifier;
if ([[[self document] settings] usingNaturalInform]) {
toolbarIdentifier = @"ProjectNiToolbar";
} else {
toolbarIdentifier = @"ProjectToolbar";
}
if (![[toolbar identifier] isEqualToString: toolbarIdentifier]) {
[toolbar autorelease];
toolbar = [[NSToolbar allocWithZone: [self zone]] initWithIdentifier: toolbarIdentifier];
[toolbar setDelegate: self];
[toolbar setAllowsUserCustomization: YES];
[toolbar setAutosavesConfiguration: YES];
[[self window] setToolbar: toolbar];
}
}
- (void) windowDidLoad {
[self setWindowFrameAutosaveName: @"ProjectWindow"];
[[self window] setFrameAutosaveName: @"ProjectWindow"];
[IFWelcomeWindow hideWelcomeWindow];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(willNeedRecompile:)
name: NSUndoManagerCheckpointNotification
object: [[self document] undoManager]];
}
- (void)windowDidBecomeMain:(NSNotification *)notification {
if (NSAppKitVersionNumber >= 949) {
// In OS X 10.5 or later we can hide the debug menu if we're not making a project where debugging is available
[[[NSApp delegate] debugMenu] setHidden: ![self canDebug]];
}
}
- (void) willNeedRecompile: (NSNotification*) not {
noChangesSinceLastCompile = noChangesSinceLastRefresh = NO;
}
- (BOOL)windowShouldClose:(id)sender {
// Clean the project if the settings have asked for it, and if it's unmodified
if (![[self document] isDocumentEdited] && [[IFPreferences sharedPreferences] cleanProjectOnClose]) {
[[self document] cleanOutUnnecessaryFiles: [[IFPreferences sharedPreferences] alsoCleanIndexFiles]];
// Note: this may fail if the document has not got anywhere to be saved to
[[self document] saveDocument: self];
}
return YES;
}
- (void) windowWillClose: (NSNotification*) not {
// Perform shutdown
[[self gamePage] stopRunningGame];
NSEnumerator* paneEnum = [projectPanes objectEnumerator];
IFProjectPane* pane;
while (pane = [paneEnum nextObject]) {
[pane willClose];
}
[projectPanes release]; projectPanes = nil;
[splitViews release]; splitViews = nil;
[panesView removeFromSuperview]; panesView = nil;
}
- (void) awakeFromNib {
// [self setWindowFrameAutosaveName: @"ProjectWindow"];
// Work out whether or not we should use spell-checking in the source views
sourceSpellChecking = [[NSUserDefaults standardUserDefaults] boolForKey: IFSourceSpellChecking];
// Register for settings updates
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(updateSettings)
name: IFSettingNotification
object: [[self document] settings]];
// Register for breakpoints updates
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(updatedBreakpoints:)
name: IFProjectBreakpointsChangedNotification
object: [self document]];
[self updatedBreakpoints: nil];
// Register for syntax reading events
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(syntaxUpdateStarted:)
name: IFProjectStartedBuildingSyntaxNotification
object: [self document]];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(syntaxUpdateFinished:)
name: IFProjectFinishedBuildingSyntaxNotification
object: [self document]];
// Setup the default panes
[projectPanes removeAllObjects];
[projectPanes addObject: [IFProjectPane standardPane]];
[projectPanes addObject: [IFProjectPane standardPane]];
[self layoutPanes];
[[projectPanes objectAtIndex: 0] selectView: IFSourcePane];
[[projectPanes objectAtIndex: 1] selectView: IFDocumentationPane];
[[[projectPanes objectAtIndex: 0] sourcePage] setSpellChecking: sourceSpellChecking];
[[[projectPanes objectAtIndex: 1] sourcePage] setSpellChecking: sourceSpellChecking];
// Monitor for compiler finished notifications
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(compilerFinished:)
name: IFCompilerFinishedNotification
object: [[self document] compiler]];
// Monitor for skein changed notifications
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(skeinChanged:)
name: ZoomSkeinChangedNotification
object: [[self document] skein]];
// Create the view switch toolbar
if ([[[self document] settings] usingNaturalInform]) {
toolbar = [[NSToolbar allocWithZone: [self zone]] initWithIdentifier: @"ProjectNiToolbar"];
} else {
toolbar = [[NSToolbar allocWithZone: [self zone]] initWithIdentifier: @"ProjectToolbar"];
}
[toolbar setDelegate: self];
[toolbar setAllowsUserCustomization: YES];
[toolbar setAutosavesConfiguration: YES];
[[self window] setToolbar: toolbar];
[statusInfo setStringValue: @""];
// Tell the document to reload its syntax
[[self document] rebuildSyntaxMatchers];
}
// == Project pane layout ==
- (void) layoutPanes {
if ([projectPanes count] == 0) {
return;
}
[projectPanes makeObjectsPerformSelector: @selector(removeFromSuperview)];
[splitViews makeObjectsPerformSelector: @selector(removeFromSuperview)];
[splitViews removeAllObjects];
[[panesView subviews] makeObjectsPerformSelector:
@selector(removeFromSuperview)];
if ([projectPanes count] == 1) {
// Just one pane
IFProjectPane* firstPane = [projectPanes objectAtIndex: 0];
[firstPane setController: self];
[[firstPane paneView] setFrame: [panesView bounds]];
[panesView addSubview: [firstPane paneView]];
} else {
// Create the splitViews
int view, nviews;
double dividerWidth = 5;
nviews = [projectPanes count];
for (view=0; view<nviews-1; view++) {
NSSplitView* newView = [[NSSplitView allocWithZone: [self zone]] init];
[newView setVertical: YES];
[newView setIsPaneSplitter: YES];
[newView setDelegate: self];
[newView setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
[newView setIsPaneSplitter: YES];
dividerWidth = [newView dividerThickness];
[splitViews addObject: [newView autorelease]];
}
// Remaining space for other dividers
double remaining = [panesView bounds].size.width - dividerWidth*(double)(nviews-1);
double totalRemaining = [panesView bounds].size.width;
double viewWidth = floor(remaining / (double)nviews);
// Work out the widths of the dividers using the preferences
NSMutableArray* realDividerWidths = [NSMutableArray array];
NSArray* dividerProportions = [[NSUserDefaults standardUserDefaults] objectForKey: IFSplitViewSizes];
if (![dividerProportions isKindOfClass: [NSArray class]] || [dividerProportions count] <= 0)
dividerProportions = [NSArray arrayWithObject: [NSNumber numberWithFloat: 1.0]];
float totalWidth = 0;
for (view=0; view<nviews; view++) {
float width;
if (view >= [dividerProportions count]) {
width = [[dividerProportions objectAtIndex: [dividerProportions count]-1] floatValue];
} else {
width = [[dividerProportions objectAtIndex: view] floatValue];
}
if (width <= 0) width = 1.0;
[realDividerWidths addObject: [NSNumber numberWithFloat: width]];
totalWidth += width;
}
// Work out the actual widths to use, and size and add the views appropriately
float proportion = remaining / totalWidth;
//NSRect paneBounds = [panesView bounds];
// Insert the views
NSSplitView* lastView = nil;
for (view=0; view<nviews-1; view++) {
// Garner some information about the views we're dealing with
NSSplitView* thisView = [splitViews objectAtIndex: view];
IFProjectPane* pane = [projectPanes objectAtIndex: view];
NSView* thisPane = [[projectPanes objectAtIndex: view] paneView];
[pane setController: self];
viewWidth = floorf(proportion * [[realDividerWidths objectAtIndex: view] floatValue]);
// Resize the splitview
NSRect splitFrame;
if (lastView != nil) {
splitFrame = [lastView bounds];
splitFrame.origin.x += viewWidth + dividerWidth;
splitFrame.size.width = totalRemaining;
} else {
splitFrame = [panesView bounds];
}
[thisView setFrame: splitFrame];
// Add it as a subview
if (lastView != nil) {
[lastView addSubview: thisView];
//[lastView adjustSubviews];
} else {
[panesView addSubview: thisView];
}
// Add the leftmost view
NSRect paneFrame = [thisView bounds];
paneFrame.size.width = viewWidth;
[thisPane setFrame: paneFrame];
[thisView addSubview: thisPane];
[thisView setDelegate: self];
lastView = thisView;
// Update the amount of space remaining
remaining -= viewWidth;
totalRemaining -= viewWidth + dividerWidth;
}
// Final view
NSView* finalPane = [[projectPanes lastObject] paneView];
NSRect finalFrame = [lastView bounds];
[[projectPanes lastObject] setController: self];
finalFrame.origin.x += viewWidth + dividerWidth;
finalFrame.size.width = totalRemaining;
[finalPane setFrame: finalFrame];
[lastView addSubview: finalPane];
[lastView adjustSubviews];
}
}
- (void)splitViewDidResizeSubviews:(NSNotification *)aNotification {
// Update the preferences with the view widths
int nviews = [projectPanes count];
int view;
NSMutableArray* viewSizes = [NSMutableArray array];
float totalWidth = [[self window] frame].size.width;
for (view=0; view<nviews; view++) {
IFProjectPane* pane = [projectPanes objectAtIndex: view];
NSRect paneFrame = [[pane paneView] frame];
[viewSizes addObject: [NSNumber numberWithFloat: paneFrame.size.width/totalWidth]];
}
[[NSUserDefaults standardUserDefaults] setObject: viewSizes
forKey: IFSplitViewSizes];
}
// == Toolbar delegate functions ==
- (NSToolbarItem *)toolbar: (NSToolbar *) toolbar
itemForItemIdentifier: (NSString *) itemIdentifier
willBeInsertedIntoToolbar: (BOOL) flag {
// Cheat!
// Actually, I thought you could share NSToolbarItems between windows, but you can't (the images disappear,
// weirdly). However, copying the item is just as good as creating a new one here, and makes the code
// somewhat more readable.
NSToolbarItem* item = [[[itemDictionary objectForKey: itemIdentifier] copy] autorelease];
[item setPaletteLabel: [item label]];
// The search views need to be set up here
if ([itemIdentifier isEqualToString: @"searchDocsItem"]) {
NSSearchField* searchDocs = [[NSSearchField alloc] initWithFrame: NSMakeRect(0,0,150,22)];
[[searchDocs cell] setPlaceholderString: [[NSBundle mainBundle] localizedStringForKey: @"Documentation"
value: @"Documentation"
table: nil]];
[item setMinSize: NSMakeSize(100, 22)];
[item setMaxSize: NSMakeSize(150, 22)];
[item setView: [searchDocs autorelease]];
[searchDocs sizeToFit];
[searchDocs setContinuous: NO];
[[searchDocs cell] setSendsWholeSearchString: YES];
[searchDocs setTarget: self];
[searchDocs setAction: @selector(searchDocs:)];
[item setLabel: nil];
return item;
} else if ([itemIdentifier isEqualToString: @"searchProjectItem"]) {
NSSearchField* searchProject = [[NSSearchField alloc] initWithFrame: NSMakeRect(0,0,150,22)];
[[searchProject cell] setPlaceholderString: [[NSBundle mainBundle] localizedStringForKey: @"Project"
value: @"Project"
table: nil]];
[item setMinSize: NSMakeSize(100, 22)];
[item setMaxSize: NSMakeSize(150, 22)];
[item setView: [searchProject autorelease]];
[searchProject sizeToFit];
[searchProject setContinuous: NO];
[[searchProject cell] setSendsWholeSearchString: YES];
[searchProject setTarget: self];
[searchProject setAction: @selector(searchProject:)];
[item setLabel: nil];
return item;
}
return item;
}
- (void) doNothing: (id) sender { }
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar {
return [NSArray arrayWithObjects:
@"compileItem", @"compileAndRunItem", @"replayItem", @"compileAndDebugItem", @"refreshIndexItem", @"pauseItem", @"continueItem", @"stepItem",
@"stepOverItem", @"stepOutItem", @"stopItem", @"watchItem", @"breakpointItem", @"indexItem", @"searchDocsItem", @"searchProjectItem",
NSToolbarSpaceItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier, NSToolbarSeparatorItemIdentifier,
@"releaseItem",
nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)tb {
if ([[tb identifier] isEqualToString: @"ProjectNiToolbar"]) {
return [NSArray arrayWithObjects: @"compileAndRunItem", @"replayItem", @"stopItem", NSToolbarSeparatorItemIdentifier,
@"releaseItem", NSToolbarFlexibleSpaceItemIdentifier, @"searchDocsItem", NSToolbarSeparatorItemIdentifier, @"indexItem", nil];
} else {
return [NSArray arrayWithObjects: @"compileAndRunItem", @"replayItem", @"compileAndDebugItem",
NSToolbarSeparatorItemIdentifier, @"stopItem", @"pauseItem", NSToolbarSeparatorItemIdentifier,
@"continueItem", @"stepOutItem", @"stepOverItem", @"stepItem", NSToolbarSeparatorItemIdentifier,
@"releaseItem", NSToolbarFlexibleSpaceItemIdentifier, @"indexItem", NSToolbarSeparatorItemIdentifier,
@"breakpointItem", @"watchItem", nil];
}
}
// == Toolbar item validation ==
- (BOOL) canDebug {
// Can only debug Z-Code Inform 6 games
return ![[[self document] settings] usingNaturalInform] && [[[self document] settings] zcodeVersion] < 16;
}
- (BOOL) validateToolbarItem: (NSToolbarItem*) item {
BOOL isRunning = [[self gamePage] isRunningGame];
if ([[item itemIdentifier] isEqualToString: [pauseItem itemIdentifier]] &&
![self canDebug]) {
return NO;
}
if ([[item itemIdentifier] isEqualToString: [stopItem itemIdentifier]] ||
[[item itemIdentifier] isEqualToString: [pauseItem itemIdentifier]]) {
return isRunning;
}
if ([[item itemIdentifier] isEqualToString: [continueItem itemIdentifier]] ||
[[item itemIdentifier] isEqualToString: [stepOutItem itemIdentifier]] ||
[[item itemIdentifier] isEqualToString: [stepOverItem itemIdentifier]] ||
[[item itemIdentifier] isEqualToString: [stepItem itemIdentifier]]) {
return isRunning?waitingAtBreakpoint:NO;
}
SEL itemSelector = [item action];
if (itemSelector == @selector(compileAndDebug:) &&
![self canDebug]) {
return NO;
}
if (itemSelector == @selector(compile:) ||
itemSelector == @selector(release:) ||
itemSelector == @selector(compileAndRun:) ||
itemSelector == @selector(compileAndDebug:) ||
itemSelector == @selector(replayUsingSkein:) ||
itemSelector == @selector(compileAndRefresh:)) {
return ![[[self document] compiler] isRunning];
}
return YES;
}
- (void) changeFirstResponder: (NSResponder*) first {
if ([first isKindOfClass: [NSView class]]) {
NSView* firstView = (NSView*)first;
IFProjectPane* pane = nil;
while (firstView != nil) {
if ([firstView isKindOfClass: [NSTabView class]]) {
// See if this is the tab view for a specific pane
NSEnumerator* paneEnum = [projectPanes objectEnumerator];
BOOL found = NO;
while (pane = [paneEnum nextObject]) {
if ([pane tabView] == firstView) {
found = YES;
break;
}
}
// Keep this view, if it's a suitable candidate
if (found) break;
pane = nil;
}
// Continue up the tree
firstView = [firstView superview];
}
[currentPane setIsActive: NO];
[pane setIsActive: YES];
currentPane = pane;
currentTabView = (NSTabView*)firstView;
}
}
- (NSTabView*) currentTabView {
return currentTabView;
}
- (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem {
SEL itemSelector = [menuItem action];
BOOL isRunning = [[self gamePage] isRunningGame];
if (itemSelector == @selector(continueProcess:) ||
itemSelector == @selector(stepOverProcess:) ||
itemSelector == @selector(stepIntoProcess:) ||
itemSelector == @selector(stepOutProcess:)) {
return isRunning?waitingAtBreakpoint:NO;
}
if (itemSelector == @selector(pauseProcess:) &&
![self canDebug]) {
return NO;
}
if (itemSelector == @selector(stopProcess:) ||
itemSelector == @selector(pauseProcess:)) {
return isRunning;
}
if (itemSelector == @selector(compileAndDebug:) ||
itemSelector == @selector(setBreakpoint:) ||
itemSelector == @selector(deleteBreakpoint:)) {
if (![self canDebug]) {
if (NSAppKitVersionNumber >= 949) {
[menuItem setHidden: YES]; // Menu item hiding is only available on OS X 10.5 or later
}
return NO;
} else {
if (NSAppKitVersionNumber >= 949) {
[menuItem setHidden: NO];
}
}
}
if (itemSelector == @selector(compile:) ||
itemSelector == @selector(release:) ||
itemSelector == @selector(compileAndRun:) ||
itemSelector == @selector(compileAndDebug:) ||
itemSelector == @selector(replayUsingSkein:) ||
itemSelector == @selector(compileAndRefresh:)) {
return ![[[self document] compiler] isRunning];
}
// Format options
if (itemSelector == @selector(shiftLeft:) ||
itemSelector == @selector(shiftRight:) ||
itemSelector == @selector(renumberSections:)) {
// First responder must be an NSTextView object
if (![[[self window] firstResponder] isKindOfClass: [NSTextView class]])
return NO;
}
if (itemSelector == @selector(commentOutSelection:)
|| itemSelector == @selector(uncommentSelection:)) {
// Must be an Inform 7 project (not supporting this for I6 unless someone asks or implements themselves :-)
if (![[[self document] settings] usingNaturalInform])
return NO;
// First responder must be a NSTextView object
if (![[[self window] firstResponder] isKindOfClass: [NSTextView class]])
return NO;
// There must be a non-zero length selection
if ([(NSTextView*)[[self window] firstResponder] selectedRange].length == 0)
return 0;
}
if (itemSelector == @selector(enableElasticTabs:)) {
[menuItem setState: [[[self document] settings] elasticTabs]?NSOnState:NSOffState];
return YES;
}
if (itemSelector == @selector(renumberSections:)) {
// Intelligence must be on
if (![[IFPreferences sharedPreferences] enableIntelligence])
return NO;
// First responder must be an NSTextView object containing a IFSyntaxStorage with some intel data
if (![[[self window] firstResponder] isKindOfClass: [NSTextView class]])
return NO;
if (![[(NSTextView*)[[self window] firstResponder] textStorage] isKindOfClass: [IFSyntaxStorage class]])
return NO;
IFSyntaxStorage* storage = (IFSyntaxStorage*)[(NSTextView*)[[self window] firstResponder] textStorage];
if ([storage highlighting]) return NO;
if ([storage intelligenceData] == nil) return NO;
}
if (itemSelector == @selector(lastCommand:) ||
itemSelector == @selector(lastCommandInSkein:)) {
return [[[[[self skeinPane] skeinPage] skeinView] skein] activeItem] != nil;
}
// Tabbing options
if (itemSelector == @selector(tabSource:)
|| itemSelector == @selector(tabErrors:)
|| itemSelector == @selector(tabIndex:)
|| itemSelector == @selector(tabSkein:)
|| itemSelector == @selector(tabTranscript:)
|| itemSelector == @selector(tabGame:)
|| itemSelector == @selector(tabDocumentation:)
|| itemSelector == @selector(tabSettings:)
|| itemSelector == @selector(switchPanes:)) {
return [self currentTabView] != nil;
}
if (itemSelector == @selector(showIndexTab:)) {
return [[[projectPanes objectAtIndex: 0] indexPage] canSelectIndexTab: [menuItem tag]];
}
// Heading options
if (itemSelector == @selector(showNextSection:)
|| itemSelector == @selector(showPreviousSection:)
|| itemSelector == @selector(showCurrentSectionOnly:)
|| itemSelector == @selector(showEntireSource:)
|| itemSelector == @selector(showFewerHeadings:)
|| itemSelector == @selector(showMoreHeadings:)) {
// For any of these to work, the source page must be visible
if (![[[self window] firstResponder] isKindOfClass: [NSTextView class]])
return NO;
if ([currentPane currentView] != IFSourcePane)
return NO;
}
if (itemSelector == @selector(exportIFiction:)) {
return [[[self document] settings] usingNaturalInform];
}
// Spell checking
if (itemSelector == @selector(toggleSourceSpellChecking:)) {
[menuItem setState: sourceSpellChecking?NSOnState:NSOffState];
return YES;
}
return YES;
}
// == View selection functions ==
- (void) performCompileWithRelease: (BOOL) release
refreshOnly: (BOOL) onlyRefresh {
IFProject* doc = [self document];
IFOutputSettings* outputSettings = (IFOutputSettings*)[[doc settings] settingForClass: [IFOutputSettings class]];
BOOL buildBlorb = [outputSettings createBlorbForRelease] && release;
[self removeHighlightsOfStyle: IFLineStyleError];
[self removeHighlightsOfStyle: IFLineStyleExecutionPoint];
// Save the document
[doc saveDocument: self];
[projectPanes makeObjectsPerformSelector: @selector(stopRunningGame)];
// Set up the compiler
IFCompiler* theCompiler = [doc compiler];
[theCompiler setBuildForRelease: release];
[theCompiler setSettings: [doc settings]];
if (![doc singleFile]) {
[theCompiler setOutputFile: [NSString stringWithFormat: @"%@/Build/output.%@",
[doc fileName],
[[doc settings] zcodeVersion]>=256?@"ulx":[NSString stringWithFormat: @"z%i", [[doc settings] zcodeVersion]]]];
if ([[doc settings] usingNaturalInform]) {
[theCompiler setInputFile: [NSString stringWithFormat: @"%@",
[doc fileName]]];
} else {
[theCompiler setInputFile: [NSString stringWithFormat: @"%@/Source/%@",
[doc fileName], [doc mainSourceFile]]];
}
[theCompiler setDirectory: [NSString stringWithFormat: @"%@/Build", [doc fileName]]];
} else {
[theCompiler setInputFile: [NSString stringWithFormat: @"%@",