/
FRAPreferencesController.m
616 lines (494 loc) · 32.2 KB
/
FRAPreferencesController.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
/*
Fraise version 3.7 - Based on Smultron by Peter Borg
Written by Jean-François Moy - jeanfrancois.moy@gmail.com
Find the latest version at http://github.com/jfmoy/Fraise
Copyright 2010 Jean-François Moy
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
#import "FRAStandardHeader.h"
#import "FRAPreferencesController.h"
#import "NSString+Fraise.h"
#import "FRABasicPerformer.h"
#import "FRAVariousPerformer.h"
#import "FRAProjectsController.h"
#import "FRAInterfacePerformer.h"
#import "FRACommandsController.h"
#import "FRASnippetsController.h"
#import "FRAAdvancedFindController.h"
#import "FRAMainController.h"
#import "FRAApplicationDelegate.h"
#import "FRAProject.h"
#import "FRALineNumbers.h"
#import "NSToolbarItem+Fraise.h"
@implementation FRAPreferencesController
@synthesize encodingsArrayController, syntaxDefinitionsArrayController, encodingsPopUp, preferencesWindow;
static id sharedInstance = nil;
+ (FRAPreferencesController *)sharedInstance
{
if (sharedInstance == nil) {
sharedInstance = [[self alloc] init];
}
return sharedInstance;
}
- (id)init
{
if (sharedInstance == nil) {
sharedInstance = [super init];
hasPreparedAdvancedInterface = NO;
}
return sharedInstance;
}
- (void)setDefaults
{
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.97 alpha:1.0]] forKey:@"CommandsColourWell"];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.0 green:0.69 blue:0.001 alpha:1.0]] forKey:@"CommentsColourWell"];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.45 green:0.45 blue:0.45 alpha:1.0]] forKey:@"InstructionsColourWell"];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.84 green:0.41 blue:0.006 alpha:1.0]] forKey:@"KeywordsColourWell"];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.84 green:0.41 blue:0.006 alpha:1.0]] forKey:@"AutocompleteColourWell"];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.73 green:0.0 blue:0.74 alpha:1.0]] forKey:@"VariablesColourWell"];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.95 green:0.0 blue:0.0 alpha:1.0]] forKey:@"StringsColourWell"];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.50 green:0.5 blue:0.2 alpha:1.0]] forKey:@"AttributesColourWell"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"ColourCommands"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"ColourComments"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"ColourInstructions"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"ColourKeywords"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"ColourAutocomplete"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"ColourVariables"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"ColourStrings"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"ColourAttributes"];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor whiteColor]] forKey:@"BackgroundColourWell"];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor blackColor]] forKey:@"TextColourWell"];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor blackColor]] forKey:@"InvisibleCharactersColourWell"];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.96 green:0.96 blue:0.71 alpha:1.0]] forKey:@"HighlightLineColourWell"];
[dictionary setValue:[NSNumber numberWithInteger:0] forKey:@"EncodingsMatrix"];
[dictionary setValue:[NSNumber numberWithInteger:FRAOpenSaveRemember] forKey:@"OpenMatrix"];
[dictionary setValue:[NSNumber numberWithInteger:FRAOpenSaveAlways] forKey:@"SaveMatrix"];
[dictionary setValue:[NSNumber numberWithInteger:NSUTF8StringEncoding] forKey:@"EncodingsPopUp"];
[dictionary setValue:[NSNumber numberWithInteger:0] forKey:@"SizeOfDocumentsListTextPopUp"];
[dictionary setValue:[NSNumber numberWithInteger:5] forKey:@"LineEndingsPopUp"];
[dictionary setValue:[NSNumber numberWithInteger:0] forKey:@"SyntaxColouringMatrix"];
[dictionary setValue:[NSNumber numberWithInteger:12] forKey:@"NSRecentDocumentsLimit"];
[dictionary setValue:[NSNumber numberWithInteger:40] forKey:@"GutterWidth"];
[dictionary setValue:[NSNumber numberWithInteger:4] forKey:@"TabWidth"];
[dictionary setValue:[NSNumber numberWithInteger:4] forKey:@"IndentWidth"];
[dictionary setValue:[NSNumber numberWithInteger:80] forKey:@"ShowPageGuideAtColumn"];
[dictionary setValue:[NSNumber numberWithInteger:5] forKey:@"StatusBarLastSavedFormatPopUp"];
[dictionary setValue:[NSNumber numberWithInteger:32] forKey:@"ViewSize"];
[dictionary setValue:[NSNumber numberWithInteger:FRAListView] forKey:@"View"];
[dictionary setValue:[NSNumber numberWithInteger:FRAPreviewHTML] forKey:@"PreviewParser"];
[dictionary setValue:[NSNumber numberWithInteger:FRACurrentDocumentScope] forKey:@"AdvancedFindScope"];
[dictionary setValue:[NSNumber numberWithDouble:0.5] forKey:@"AutocompleteAfterDelay"];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSFont fontWithName:@"Menlo" size:11]] forKey:@"TextFont"];
[dictionary setValue:[[NSString localizedStringWithFormat:@"%@/%@", NSHomeDirectory(), @"Desktop"] stringByAbbreviatingWithTildeInPath] forKey:@"OpenAlwaysUseTextField"];
[dictionary setValue:[[NSString localizedStringWithFormat:@"%@/%@", NSHomeDirectory(), @"Desktop"] stringByAbbreviatingWithTildeInPath] forKey:@"SaveAsAlwaysUseTextField"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"NewDocumentAtStartup"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"ShowFullPathInWindowTitle"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"ShowLineNumberGutter"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"SyntaxColourNewDocuments"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"LineWrapNewDocuments"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"AssignDocumentToFraiseWhenSaving"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"IndentNewLinesAutomatically"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"OnlyColourTillTheEndOfLine"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"CheckIfDocumentHasBeenUpdated"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"ShowMatchingBraces"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"StatusBarShowEncoding"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"StatusBarShowLength"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"StatusBarShowSelection"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"StatusBarShowPosition"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"StatusBarShowSyntax"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"StatusBarShowWhenLastSaved"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"ShowInvisibleCharacters"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"IndentWithSpaces"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"OpenAllFilesWithinAFolder"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"OpenAllDocumentsIHadOpen"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"OpenAllProjectsIHadOpen"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"ColourMultiLineStrings"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"AutocompleteSuggestAutomatically"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"AutocompleteIncludeStandardWords"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"AutoSpellCheck"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"AutoGrammarCheck"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"KeepRunningAfterMainWindowIsClosed"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"SmartInsertDelete"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"AutomaticLinkDetection"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"AutomaticQuoteSubstitution"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"UseTabStops"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"HighlightCurrentLine"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"OpenAllFilesInAFolderRecursively"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"FilterOutExtensions"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"UseRGBRatherThanHexWhenInsertingColourValues"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"ShowFullPathInDocumentsList"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"AutomaticallyIndentBraces"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"AppendNameInSaveAs"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"AutoInsertAClosingParenthesis"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"AutoInsertAClosingBrace"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"OpenAllDocumentsIHadOpen"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"OpenAllProjectsIHadOpen"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"IgnoreCaseAdvancedFind"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"UseRegularExpressionsAdvancedFind"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"OnlyInSelectionAdvancedFind"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"PrintHeader"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"PrintSyntaxColours"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"OnlyPrintSelection"];
[dictionary setValue:@"jpg gif png swf" forKey:@"FilterOutExtensionsString"];
[dictionary setValue:@"/bin/sh" forKey:@"RunText"];
[dictionary setValue:@".txt" forKey:@"AppendNameInSaveAsWith"];
[dictionary setValue:@"Standard" forKey:@"SyntaxColouringPopUpString"];
[dictionary setValue:[NSNumber numberWithInteger:24] forKey:@"MarginsMin"];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSFont fontWithName:@"Courier" size:10]] forKey:@"PrintFont"];
NSArray *activeEncodings = [[NSArray alloc] initWithObjects:[NSNumber numberWithUnsignedInteger:NSASCIIStringEncoding], [NSNumber numberWithUnsignedInteger:NSJapaneseEUCStringEncoding], [NSNumber numberWithUnsignedInteger:NSUTF8StringEncoding], [NSNumber numberWithUnsignedInteger:NSISOLatin1StringEncoding], [NSNumber numberWithUnsignedInteger:NSSymbolStringEncoding], [NSNumber numberWithUnsignedInteger:NSNonLossyASCIIStringEncoding], [NSNumber numberWithUnsignedInteger:NSShiftJISStringEncoding], [NSNumber numberWithUnsignedInteger:NSISOLatin2StringEncoding], [NSNumber numberWithUnsignedInteger:NSUnicodeStringEncoding], [NSNumber numberWithUnsignedInteger:NSWindowsCP1251StringEncoding], [NSNumber numberWithUnsignedInteger:NSWindowsCP1252StringEncoding], [NSNumber numberWithUnsignedInteger:NSWindowsCP1253StringEncoding], [NSNumber numberWithUnsignedInteger:NSWindowsCP1254StringEncoding], [NSNumber numberWithUnsignedInteger:NSWindowsCP1250StringEncoding], [NSNumber numberWithUnsignedInteger:NSISO2022JPStringEncoding], [NSNumber numberWithUnsignedInteger:NSMacOSRomanStringEncoding], nil];
[dictionary setValue:activeEncodings forKey:@"ActiveEncodings"];
// Users can't set these in Preferences
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"ShowStatusBar"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"ShowTabBar"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"HasInsertedDefaultSnippets"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"HasImportedFromVersion2"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"HasInsertedDefaultCommands3"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"UserHasBeenShownAlertHowToReturnFromFullScreen"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"UpdateDocumentAutomaticallyWithoutWarning"];
[dictionary setValue:[NSNumber numberWithInteger:4] forKey:@"SpacesPerTabEntabDetab"];
[dictionary setValue:[NSNumber numberWithInteger:15] forKey:@"TimeBetweenDocumentUpdateChecks"];
[dictionary setValue:@"yyyy-MM-dd HH:mm 'w:'w 'd:'D" forKey:@"UserDateFormat"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"AlwaysEndFileWithLineFeed"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"SuppressReplaceWarning"];
[dictionary setValue:[NSNumber numberWithInteger:FRAVirtualProject] forKey:@"WhatKindOfProject"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"LiveUpdatePreview"];
[dictionary setValue:[NSNumber numberWithDouble:1.0] forKey:@"LiveUpdatePreviewDelay"];
[dictionary setValue:[NSNumber numberWithDouble:0.2] forKey:@"DividerPosition"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"ShowSizeSlider"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"PutQuotesAroundDirectory"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"FocusOnTextInAdvancedFind"];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:@"KeepEmptyWindowOpen"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"UseQuickLookIcon"];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:@"UpdateIconForEverySave"];
[dictionary setValue:@"" forKey:@"BaseURL"];
NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController];
[defaultsController setInitialValues:dictionary];
[defaultsController addObserver:self forKeyPath:@"values.StatusBarShowEncoding" options:NSKeyValueObservingOptionNew context:@"StatusBarChanged"];
[defaultsController addObserver:self forKeyPath:@"values.StatusBarShowLength" options:NSKeyValueObservingOptionNew context:@"StatusBarChanged"];
[defaultsController addObserver:self forKeyPath:@"values.StatusBarShowSelection" options:NSKeyValueObservingOptionNew context:@"StatusBarChanged"];
[defaultsController addObserver:self forKeyPath:@"values.StatusBarShowPosition" options:NSKeyValueObservingOptionNew context:@"StatusBarChanged"];
[defaultsController addObserver:self forKeyPath:@"values.StatusBarShowSyntax" options:NSKeyValueObservingOptionNew context:@"StatusBarChanged"];
[defaultsController addObserver:self forKeyPath:@"values.StatusBarShowWhenLastSaved" options:NSKeyValueObservingOptionNew context:@"StatusBarChanged"];
[defaultsController addObserver:self forKeyPath:@"values.StatusBarLastSavedFormatPopUp" options:NSKeyValueObservingOptionNew context:@"StatusBarLastSavedFormatChanged"];
[defaultsController addObserver:self forKeyPath:@"values.SizeOfDocumentsListTextPopUp" options:NSKeyValueObservingOptionNew context:@"SizeOfDocumentsListTextPopUpChanged"];
[defaultsController addObserver:self forKeyPath:@"values.ShowFullPathInWindowTitle" options:NSKeyValueObservingOptionNew context:@"ShowFullPathInWindowTitleChanged"];
[defaultsController addObserver:self forKeyPath:@"values.CheckIfDocumentHasBeenUpdated" options:NSKeyValueObservingOptionNew context:@"CheckIfDocumentHasBeenUpdatedChanged"];
[defaultsController addObserver:self forKeyPath:@"values.ShowFullPathInDocumentsList" options:NSKeyValueObservingOptionNew context:@"DocumentsListPathSettingsChanged"];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([(NSString *)context isEqualToString:@"StatusBarChanged"]) {
[FRAInterface updateStatusBar];
} else if ([(NSString *)context isEqualToString:@"StatusBarLastSavedFormatChanged"]) {
NSArray *array = [FRABasic fetchAll:@"Document"];
for (id item in array) {
if ([[item valueForKey:@"isNewDocument"] boolValue] == NO) {
[FRAVarious setLastSavedDateForDocument:item date:[[item valueForKey:@"fileAttributes"] fileModificationDate]];
}
}
[FRAInterface updateStatusBar];
} else if ([(NSString *)context isEqualToString:@"ShowFullPathInWindowTitleChanged"]) {
NSArray *projectsArray = [[FRAProjectsController sharedDocumentController] documents];
for (id project in projectsArray) {
NSArray *documentsArray = [FRABasic fetchAll:@"Document"];
for (id document in documentsArray) {
[project updateWindowTitleBarForDocument:document];
}
}
} else if ([(NSString *)context isEqualToString:@"SizeOfDocumentsListTextPopUpChanged"]) {
NSArray *array = [[FRAProjectsController sharedDocumentController] documents];
for (id item in array) {
[item reloadData];
}
[syntaxDefinitionsTableView reloadData];
[encodingsTableView reloadData];
if ([[FRACommandsController sharedInstance] commandsWindow] != nil) {
[[[FRACommandsController sharedInstance] commandCollectionsTableView] reloadData];
[[[FRACommandsController sharedInstance] commandsTableView] reloadData];
}
if ([[FRASnippetsController sharedInstance] snippetsWindow] != nil) {
[[[FRASnippetsController sharedInstance] snippetCollectionsTableView] reloadData];
[[[FRASnippetsController sharedInstance] snippetsTableView] reloadData];
}
if ([[FRAAdvancedFindController sharedInstance] advancedFindWindow] != nil) {
[[[FRAAdvancedFindController sharedInstance] findResultsOutlineView] reloadData];
}
} else if ([(NSString *)context isEqualToString:@"CheckIfDocumentHasBeenUpdatedChanged"]) {
[FRAVarious updateCheckIfAnotherApplicationHasChangedDocumentsTimer];
} else if ([(NSString *)context isEqualToString:@"DocumentsListPathSettingsChanged"]) {
NSArray *array = [[FRAProjectsController sharedDocumentController] documents];
for (id item in array) {
[item reloadData];
}
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
- (void)showPreferencesWindow
{
if (preferencesWindow == nil) {
[NSBundle loadNibNamed:@"FRAPreferences.nib" owner:self];
[preferencesWindow setShowsToolbarButton:NO];
preferencesToolbar = [[NSToolbar alloc] initWithIdentifier:@"PreferencesToolbarIdentifier"];
[preferencesToolbar setAllowsUserCustomization:NO];
[preferencesToolbar setAutosavesConfiguration:NO];
[preferencesToolbar setShowsBaselineSeparator:YES];
[preferencesToolbar setDelegate:self];
[preferencesWindow setToolbar:preferencesToolbar];
[preferencesWindow setTitle:NSLocalizedStringFromTable(@"Preferences - Fraise", @"Localizable3", @"Preferences - Fraise")];
}
if ([preferencesToolbar selectedItemIdentifier] == nil) {
if (generalView == nil) {
[NSBundle loadNibNamed:@"FRAPreferencesGeneral.nib" owner:self];
}
[preferencesToolbar setSelectedItemIdentifier:@"GeneralPreferencesToolbarItem"];
if ([FRADefaults valueForKey:@"PreferencesGeneralViewSavedFrame"] == nil) {
[preferencesWindow setFrame:[self getRectForView:generalView] display:YES animate:NO];
} else { // It sometimes get the frame wrong after it has been resized so use the own saved version
NSRect temporaryRect = NSRectFromString([FRADefaults valueForKey:@"PreferencesGeneralViewSavedFrame"]);
[preferencesWindow setFrame:NSMakeRect(temporaryRect.origin.x, temporaryRect.origin.y, temporaryRect.size.width * [preferencesWindow userSpaceScaleFactor], temporaryRect.size.height * [preferencesWindow userSpaceScaleFactor]) display:YES animate:NO];
}
[[preferencesWindow contentView] addSubview:generalView];
currentView = generalView;
[preferencesWindow setDelegate:self]; // So that it catches the changeFont action
}
[preferencesWindow makeKeyAndOrderFront:self];
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects:@"GeneralPreferencesToolbarItem",
@"AppearancePreferencesToolbarItem",
@"SyntaxColoursPreferencesToolbarItem",
@"SyntaxDefinitionsPreferencesToolbarItem",
@"OpenSavePreferencesToolbarItem",
@"AdvancedPreferencesToolbarItem",
nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
{
return [NSArray arrayWithObjects:@"GeneralPreferencesToolbarItem",
@"AppearancePreferencesToolbarItem",
@"SyntaxColoursPreferencesToolbarItem",
@"SyntaxDefinitionsPreferencesToolbarItem",
@"OpenSavePreferencesToolbarItem",
@"AdvancedPreferencesToolbarItem",
nil];
}
- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
{
return [NSArray arrayWithObjects:@"GeneralPreferencesToolbarItem",
@"AppearancePreferencesToolbarItem",
@"SyntaxColoursPreferencesToolbarItem",
@"SyntaxDefinitionsPreferencesToolbarItem",
@"OpenSavePreferencesToolbarItem",
@"AdvancedPreferencesToolbarItem",
nil];
}
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)willBeInserted
{
if ([itemIdentifier isEqualToString:@"GeneralPreferencesToolbarItem"]) {
NSImage *generalImage = [NSImage imageNamed:NSImageNamePreferencesGeneral];
[generalImage setSize:NSMakeSize(32.0, 32.0)];
return [NSToolbarItem createPreferencesToolbarItemWithIdentifier:itemIdentifier name:NSLocalizedString(@"General", @"General preferences toolbar item Label") image:generalImage action:@selector(changeTabInPreferences:) target:self];
} else if ([itemIdentifier isEqualToString:@"AppearancePreferencesToolbarItem"]) {
NSImage *appearanceImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FRAAppearanceIcon" ofType:@"pdf" inDirectory:@"Preferences Icons"]];
[[[appearanceImage representations] objectAtIndex:0] setAlpha:YES];
return [NSToolbarItem createPreferencesToolbarItemWithIdentifier:itemIdentifier name:NSLocalizedString(@"Appearance", @"Appearance preferences toolbar item Label") image:appearanceImage action:@selector(changeTabInPreferences:) target:self];
} else if ([itemIdentifier isEqualToString:@"OpenSavePreferencesToolbarItem"]) {
NSImage *openSaveImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FRAOpenSaveIcon" ofType:@"pdf" inDirectory:@"Preferences Icons"]];
[[[openSaveImage representations] objectAtIndex:0] setAlpha:YES];
return [NSToolbarItem createPreferencesToolbarItemWithIdentifier:itemIdentifier name:NSLocalizedString(@"Open & Save", @"OpenSave preferences toolbar item Label") image:openSaveImage action:@selector(changeTabInPreferences:) target:self];
} else if ([itemIdentifier isEqualToString:@"AdvancedPreferencesToolbarItem"]) {
NSImage *advancedImage = [NSImage imageNamed:NSImageNameAdvanced];
[advancedImage setSize:NSMakeSize(32.0, 32.0)];
return [NSToolbarItem createPreferencesToolbarItemWithIdentifier:itemIdentifier name:NSLocalizedString(@"Advanced", @"Advanced preferences toolbar item Label") image:advancedImage action:@selector(changeTabInPreferences:) target:self];
}
return nil;
}
- (void)changeTabInPreferences:(id)sender
{
NSString *identifier = [sender itemIdentifier];
if ([identifier isEqualToString:@"GeneralPreferencesToolbarItem"]) {
if (generalView == nil) {
[NSBundle loadNibNamed:@"FRAPreferencesGeneral.nib" owner:self];
}
if (currentView == generalView) {
return;
}
[[preferencesWindow contentView] addSubview:generalView];
[FRAInterface changeViewWithAnimationForWindow:preferencesWindow oldView:currentView newView:generalView newRect:[self getRectForView:generalView]];
[currentView removeFromSuperviewWithoutNeedingDisplay];
currentView = generalView;
} else if ([identifier isEqualToString:@"AppearancePreferencesToolbarItem"]) {
if (appearanceView == nil) {
[NSBundle loadNibNamed:@"FRAPreferencesAppearance.nib" owner:self];
}
NSCalendarDate *now = [NSCalendarDate calendarDate];
NSMenu *lastSavedFormatMenu = [lastSavedFormatPopUp menu];
NSInteger index;
for (index = 0; index < 9; index++) {
[[lastSavedFormatMenu itemWithTag:index] setTitle:[NSString dateStringForDate:now formatIndex:index]];
}
if (currentView == appearanceView) {
return;
}
[[preferencesWindow contentView] addSubview:appearanceView];
[FRAInterface changeViewWithAnimationForWindow:preferencesWindow oldView:currentView newView:appearanceView newRect:[self getRectForView:appearanceView]];
[currentView removeFromSuperviewWithoutNeedingDisplay];
currentView = appearanceView;
} else if ([identifier isEqualToString:@"OpenSavePreferencesToolbarItem"]) {
if (openSaveView == nil) {
[NSBundle loadNibNamed:@"FRAPreferencesOpenSave.nib" owner:self];
}
if (currentView == openSaveView) {
return;
}
[[preferencesWindow contentView] addSubview:openSaveView];
[FRAInterface changeViewWithAnimationForWindow:preferencesWindow oldView:currentView newView:openSaveView newRect:[self getRectForView:openSaveView]];
[currentView removeFromSuperviewWithoutNeedingDisplay];
currentView = openSaveView;
} else if ([identifier isEqualToString:@"AdvancedPreferencesToolbarItem"]) {
if (advancedView == nil) {
[NSBundle loadNibNamed:@"FRAPreferencesAdvanced.nib" owner:self];
}
if (currentView == advancedView) {
return;
}
if (hasPreparedAdvancedInterface == NO) {
[FRABasic removeAllItemsFromMenu:[encodingsPopUp menu]];
[self buildEncodingsMenu];
// Build syntax definitions menu
[FRABasic removeAllItemsFromMenu:[syntaxColouringPopUp menu]];
NSEnumerator *enumerator = [[FRABasic fetchAll:@"SyntaxDefinitionSortKeySortOrder"] reverseObjectEnumerator];
NSMenuItem *menuItem;
for (id item in enumerator) {
menuItem = [[NSMenuItem alloc] initWithTitle:[item valueForKey:@"name"] action:nil keyEquivalent:@""];
[[syntaxColouringPopUp menu] insertItem:menuItem atIndex:0];
}
// Bind values here rather than in IB because otherwise there is no menu yet
[encodingsPopUp bind:@"selectedTag" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:@"values.EncodingsPopUp" options:nil];
[syntaxColouringPopUp bind:@"selectedValue" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:@"values.SyntaxColouringPopUpString" options:nil];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
[encodingsArrayController setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"sortOrder" ascending:YES];
[syntaxDefinitionsArrayController setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
hasPreparedAdvancedInterface = YES;
}
[[preferencesWindow contentView] addSubview:advancedView];
[FRAInterface changeViewWithAnimationForWindow:preferencesWindow oldView:currentView newView:advancedView newRect:[self getRectForView:advancedView]];
[currentView removeFromSuperviewWithoutNeedingDisplay];
currentView = advancedView;
}
[preferencesToolbar setSelectedItemIdentifier:identifier]; // Needed to make the selection "stick" in the toolbar
NSRect generalViewFrame = [self getRectForView:generalView];
[FRADefaults setValue:NSStringFromRect(NSMakeRect(generalViewFrame.origin.x, generalViewFrame.origin.y, (generalViewFrame.size.width / [preferencesWindow userSpaceScaleFactor]), (generalViewFrame.size.height / [preferencesWindow userSpaceScaleFactor]))) forKey:@"PreferencesGeneralViewSavedFrame"]; // It sometimes get the frame wrong after it has been resized so save a version to be used when displayed the next time
}
- (NSRect)getRectForView:(NSView *)view
{
NSPoint windowOrigin = [preferencesWindow frame].origin;
NSSize windowSize = [preferencesWindow frame].size;
NSSize viewSize = [view bounds].size;
CGFloat newY = windowOrigin.y + (windowSize.height - viewSize.height - [self toolbarHeight]);
NSRect rectWithoutTitleBar = NSMakeRect(windowOrigin.x, newY, viewSize.width, viewSize.height);
NSRect rectWithTitleBar = [NSWindow frameRectForContentRect:rectWithoutTitleBar styleMask:NSTitledWindowMask];
CGFloat titleBarHeight = rectWithTitleBar.size.height - rectWithoutTitleBar.size.height;
return NSMakeRect(windowOrigin.x, newY - titleBarHeight, viewSize.width * [preferencesWindow userSpaceScaleFactor], (viewSize.height + [self toolbarHeight] + titleBarHeight));
}
- (CGFloat)toolbarHeight
{
CGFloat toolbarHeight = 0.0;
NSRect windowFrame;
if (preferencesToolbar && [preferencesToolbar isVisible]) {
windowFrame = [NSWindow contentRectForFrameRect:[preferencesWindow frame] styleMask:[preferencesWindow styleMask]];
toolbarHeight = NSHeight(windowFrame) - NSHeight([[preferencesWindow contentView] frame]);
}
return toolbarHeight * [[NSScreen mainScreen] userSpaceScaleFactor];
}
- (IBAction)setFontAction:(id)sender
{
NSFontManager *fontManager = [NSFontManager sharedFontManager];
[fontManager setSelectedFont:[NSUnarchiver unarchiveObjectWithData:[FRADefaults valueForKey:@"TextFont"]] isMultiple:NO];
[fontManager orderFrontFontPanel:nil];
}
- (void)changeFont:(id)sender
{
NSFontManager *fontManager = [NSFontManager sharedFontManager];
NSFont *panelFont = [fontManager convertFont:[fontManager selectedFont]];
[FRADefaults setValue:[NSArchiver archivedDataWithRootObject:panelFont] forKey:@"TextFont"];
}
- (IBAction)revertToStandardSettingsAction:(id)sender
{
[[NSUserDefaultsController sharedUserDefaultsController] revertToInitialValues:nil];
[FRADefaults setValue:nil forKey:@"ChangedSyntaxDefinitions"];
[FRADefaults setValue:[NSNumber numberWithBool:YES] forKey:@"HasImportedFromVersion2"];
[FRABasic removeAllObjectsForEntity:@"SyntaxDefinition"];
[FRAVarious insertSyntaxDefinitions];
}
- (void)buildEncodingsMenu
{
[FRABasic removeAllItemsFromMenu:[encodingsPopUp menu]];
NSEnumerator *enumerator = [[FRABasic fetchAll:@"EncodingSortKeyName"] reverseObjectEnumerator];
NSMenuItem *menuItem;
for (id item in enumerator) {
if ([[item valueForKey:@"active"] boolValue] == YES) {
NSUInteger encoding = [[item valueForKey:@"encoding"] unsignedIntegerValue];
menuItem = [[NSMenuItem alloc] initWithTitle:[NSString localizedNameOfStringEncoding:encoding] action:nil keyEquivalent:@""];
[menuItem setTag:encoding];
[menuItem setTarget:self];
[[encodingsPopUp menu] insertItem:menuItem atIndex:0];
}
}
}
- (IBAction)openSetFolderAction:(id)sender
{
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseDirectories:YES];
[openPanel setCanChooseFiles:NO];
[openPanel beginSheetForDirectory:NSHomeDirectory()
file:nil
types:nil
modalForWindow:preferencesWindow
modalDelegate:self
didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
if (returnCode == NSOKButton) {
[FRADefaults setValue:[[sheet filename] stringByAbbreviatingWithTildeInPath] forKey:@"OpenAlwaysUseTextField"];
}
}
- (IBAction)saveAsSetFolderAction:(id)sender
{
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseDirectories:YES];
[openPanel setCanChooseFiles:NO];
[openPanel beginSheetForDirectory:NSHomeDirectory()
file:nil
types:nil
modalForWindow:preferencesWindow
modalDelegate:self
didEndSelector:@selector(saveAsPanelDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
- (void)saveAsPanelDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
if (returnCode == NSOKButton) {
[FRADefaults setValue:[[sheet filename] stringByAbbreviatingWithTildeInPath] forKey:@"SaveAsAlwaysUseTextField"];
}
}
- (IBAction)changeGutterWidth:(id)sender {
NSEnumerator *documentEnumerator = [[[FRACurrentProject documentsArrayController] arrangedObjects] objectEnumerator];
for (id document in documentEnumerator) {
[FRAInterface updateGutterViewForDocument:document];
[[document valueForKey:@"lineNumbers"] updateLineNumbersCheckWidth:YES recolour:YES];
}
}
- (NSManagedObjectContext *)managedObjectContext
{
return FRAManagedObjectContext;
}
@end