forked from KosmicTask/Fragaria
-
Notifications
You must be signed in to change notification settings - Fork 3
/
MGSFragariaPreferences.m
241 lines (197 loc) · 13.2 KB
/
MGSFragariaPreferences.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
//
// MGSFragariaPreferences.m
// Fragaria
//
// Created by Jonathan on 14/09/2012.
//
//
#import "MGSFragariaPreferences.h"
// colour prefs
// persisted as [NSArchiver archivedDataWithRootObject:[NSColor whiteColor]]
NSString * const MGSFragariaPrefsCommandsColourWell = @"FragariaCommandsColourWell";
NSString * const MGSFragariaPrefsCommentsColourWell = @"FragariaCommentsColourWell";
NSString * const MGSFragariaPrefsInstructionsColourWell = @"FragariaInstructionsColourWell";
NSString * const MGSFragariaPrefsKeywordsColourWell = @"FragariaKeywordsColourWell";
NSString * const MGSFragariaPrefsAutocompleteColourWell = @"FragariaAutocompleteColourWell";
NSString * const MGSFragariaPrefsVariablesColourWell = @"FragariaVariablesColourWell";
NSString * const MGSFragariaPrefsStringsColourWell = @"FragariaStringsColourWell";
NSString * const MGSFragariaPrefsAttributesColourWell = @"FragariaAttributesColourWell";
NSString * const MGSFragariaPrefsNumbersColourWell = @"FragariaNumbersColourWell";
NSString * const MGSFragariaPrefsBackgroundColourWell = @"FragariaBackgroundColourWell";
NSString * const MGSFragariaPrefsTextColourWell = @"FragariaTextColourWell";
NSString * const MGSFragariaPrefsGutterTextColourWell = @"FragariaGutterTextColourWell";
NSString * const MGSFragariaPrefsInvisibleCharactersColourWell = @"FragariaInvisibleCharactersColourWell";
NSString * const MGSFragariaPrefsHighlightLineColourWell = @"FragariaHighlightLineColourWell";
// bool
NSString * const MGSFragariaPrefsColourNumbers = @"FragariaColourNumbers";
NSString * const MGSFragariaPrefsColourCommands = @"FragariaColourCommands";
NSString * const MGSFragariaPrefsColourComments = @"FragariaColourComments";
NSString * const MGSFragariaPrefsColourInstructions = @"FragariaColourInstructions";
NSString * const MGSFragariaPrefsColourKeywords = @"FragariaColourKeywords";
NSString * const MGSFragariaPrefsColourAutocomplete = @"FragariaColourAutocomplete";
NSString * const MGSFragariaPrefsColourVariables = @"FragariaColourVariables";
NSString * const MGSFragariaPrefsColourStrings = @"FragariaColourStrings";
NSString * const MGSFragariaPrefsColourAttributes = @"FragariaColourAttributes";
NSString * const MGSFragariaPrefsShowFullPathInWindowTitle = @"FragariaShowFullPathInWindowTitle";
NSString * const MGSFragariaPrefsShowLineNumberGutter = @"FragariaShowLineNumberGutter";
NSString * const MGSFragariaPrefsSyntaxColourNewDocuments = @"FragariaSyntaxColourNewDocuments";
NSString * const MGSFragariaPrefsLineWrapNewDocuments = @"FragariaLineWrapNewDocuments";
NSString * const MGSFragariaPrefsIndentNewLinesAutomatically = @"FragariaIndentNewLinesAutomatically";
NSString * const MGSFragariaPrefsOnlyColourTillTheEndOfLine = @"FragariaOnlyColourTillTheEndOfLine";
NSString * const MGSFragariaPrefsShowMatchingBraces = @"FragariaShowMatchingBraces";
NSString * const MGSFragariaPrefsShowInvisibleCharacters = @"FragariaShowInvisibleCharacters";
NSString * const MGSFragariaPrefsIndentWithSpaces = @"FragariaIndentWithSpaces";
NSString * const MGSFragariaPrefsColourMultiLineStrings = @"FragariaColourMultiLineStrings";
NSString * const MGSFragariaPrefsAutocompleteSuggestAutomatically = @"FragariaAutocompleteSuggestAutomatically";
NSString * const MGSFragariaPrefsAutocompleteIncludeStandardWords = @"FragariaAutocompleteIncludeStandardWords";
NSString * const MGSFragariaPrefsAutoSpellCheck = @"FragariaAutoSpellCheck";
NSString * const MGSFragariaPrefsAutoGrammarCheck = @"FragariaAutoGrammarCheck";
NSString * const MGSFragariaPrefsSmartInsertDelete = @"FragariaSmartInsertDelete";
NSString * const MGSFragariaPrefsAutomaticLinkDetection = @"FragariaAutomaticLinkDetection";
NSString * const MGSFragariaPrefsAutomaticQuoteSubstitution = @"FragariaAutomaticQuoteSubstitution";
NSString * const MGSFragariaPrefsUseTabStops = @"FragariaUseTabStops";
NSString * const MGSFragariaPrefsHighlightCurrentLine = @"FragariaHighlightCurrentLine";
NSString * const MGSFragariaPrefsAutomaticallyIndentBraces = @"FragariaAutomaticallyIndentBraces";
NSString * const MGSFragariaPrefsAutoInsertAClosingParenthesis = @"FragariaAutoInsertAClosingParenthesis";
NSString * const MGSFragariaPrefsAutoInsertAClosingBrace = @"FragariaAutoInsertAClosingBrace";
NSString * const MGSFragariaPrefsShowPageGuide = @"FragariaShowPageGuide";
// integer
NSString * const MGSFragariaPrefsGutterWidth = @"FragariaGutterWidth";
NSString * const MGSFragariaPrefsTabWidth = @"FragariaTabWidth";
NSString * const MGSFragariaPrefsIndentWidth = @"FragariaIndentWidth";
NSString * const MGSFragariaPrefsShowPageGuideAtColumn = @"FragariaShowPageGuideAtColumn";
NSString * const MGSFragariaPrefsSpacesPerTabEntabDetab = @"FragariaSpacesPerTabEntabDetab";
// float
NSString * const MGSFragariaPrefsAutocompleteAfterDelay = @"FragariaAutocompleteAfterDelay";
// font
// persisted as [NSArchiver archivedDataWithRootObject:[NSFont fontWithName:@"Menlo" size:11]]
NSString * const MGSFragariaPrefsTextFont = @"FragariaTextFont";
// string
NSString * const MGSFragariaPrefsSyntaxColouringPopUpString = @"FragariaSyntaxColouringPopUpString";
static BOOL MGS_preferencesInitialized = NO;
static id sharedInstance = nil;
@implementation MGSFragariaPreferences
@synthesize fontsAndColoursPrefsViewController, textEditingPrefsViewController;
/*
- initializeValues
*/
+ (void)initializeValues
{
if (MGS_preferencesInitialized) {
return;
}
// add to initial values
NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithDictionary:[defaultsController initialValues]];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.031f green:0.0f blue:0.855f alpha:1.0f]] forKey:MGSFragariaPrefsCommandsColourWell];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.0f green:0.45f blue:0.0f alpha:1.0f]] forKey:MGSFragariaPrefsCommentsColourWell];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.45f green:0.45f blue:0.45f alpha:1.0f]] forKey:MGSFragariaPrefsInstructionsColourWell];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.737f green:0.0f blue:0.647f alpha:1.0f]] forKey:MGSFragariaPrefsKeywordsColourWell];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.84f green:0.41f blue:0.006f alpha:1.0f]] forKey:MGSFragariaPrefsAutocompleteColourWell];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.73f green:0.0f blue:0.74f alpha:1.0f]] forKey:MGSFragariaPrefsVariablesColourWell];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.804f green:0.071f blue:0.153f alpha:1.0f]] forKey:MGSFragariaPrefsStringsColourWell];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.50f green:0.5f blue:0.2f alpha:1.0f]] forKey:MGSFragariaPrefsAttributesColourWell];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.031f green:0.0f blue:0.855f alpha:1.0f]] forKey:MGSFragariaPrefsNumbersColourWell];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsColourNumbers];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsColourCommands];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsColourInstructions];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsColourKeywords];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsColourAutocomplete];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsColourVariables];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsColourStrings];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsColourAttributes];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsColourComments];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor whiteColor]] forKey:MGSFragariaPrefsBackgroundColourWell];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor textColor]] forKey:MGSFragariaPrefsTextColourWell];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedWhite:0.42f alpha:1.0f]] forKey:MGSFragariaPrefsGutterTextColourWell];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor orangeColor]] forKey:MGSFragariaPrefsInvisibleCharactersColourWell];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.96f green:0.96f blue:0.71f alpha:1.0f]] forKey:MGSFragariaPrefsHighlightLineColourWell];
[dictionary setValue:[NSNumber numberWithInteger:40] forKey:MGSFragariaPrefsGutterWidth];
[dictionary setValue:[NSNumber numberWithInteger:4] forKey:MGSFragariaPrefsTabWidth];
[dictionary setValue:[NSNumber numberWithInteger:4] forKey:MGSFragariaPrefsIndentWidth];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsShowPageGuide];
[dictionary setValue:[NSNumber numberWithInteger:80] forKey:MGSFragariaPrefsShowPageGuideAtColumn];
[dictionary setValue:[NSNumber numberWithFloat:1.0f] forKey:MGSFragariaPrefsAutocompleteAfterDelay];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSFont fontWithName:@"Menlo" size:11]] forKey:MGSFragariaPrefsTextFont];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsShowFullPathInWindowTitle];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsShowLineNumberGutter];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsSyntaxColourNewDocuments];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsLineWrapNewDocuments];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsIndentNewLinesAutomatically];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsOnlyColourTillTheEndOfLine];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsShowMatchingBraces];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsShowInvisibleCharacters];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsIndentWithSpaces];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsColourMultiLineStrings];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsAutocompleteSuggestAutomatically];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsAutocompleteIncludeStandardWords];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsAutoSpellCheck];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsAutoGrammarCheck];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsSmartInsertDelete];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsAutomaticLinkDetection];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsAutomaticQuoteSubstitution];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsUseTabStops];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsHighlightCurrentLine];
[dictionary setValue:[NSNumber numberWithInteger:4] forKey:MGSFragariaPrefsSpacesPerTabEntabDetab];
[dictionary setValue:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsAutomaticallyIndentBraces];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsAutoInsertAClosingParenthesis];
[dictionary setValue:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsAutoInsertAClosingBrace];
[dictionary setValue:@"Standard" forKey:MGSFragariaPrefsSyntaxColouringPopUpString];
[dictionary setValue:[NSArchiver archivedDataWithRootObject:[NSColor controlTextColor]] forKeyPath:MGSFragariaPrefsInvisibleCharactersColourWell];
[defaultsController setInitialValues:dictionary];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
MGS_preferencesInitialized = YES;
}
/*
+ sharedInstance
*/
+ (MGSFragariaPreferences *)sharedInstance
{
if (sharedInstance == nil) {
sharedInstance = [[super allocWithZone:NULL] init];
}
return sharedInstance;
}
/*
+ allocWithZone:
alloc with zone for singleton
*/
+ (id)allocWithZone:(NSZone *)zone
{
#pragma unused(zone)
return [[self sharedInstance] retain];
}
#pragma mark -
#pragma mark Instance methods
/*
- init
*/
- (id)init
{
if (sharedInstance) return sharedInstance;
self = [super init];
if (self) {
// load view controllers
textEditingPrefsViewController = [[MGSFragariaTextEditingPrefsViewController alloc] init];
fontsAndColoursPrefsViewController = [[MGSFragariaFontsAndColoursPrefsViewController alloc] init];
}
sharedInstance = self;
return self;
}
/*
- changeFont:
*/
- (void)changeFont:(id)sender
{
/* NSFontManager will send this method up the responder chain */
[fontsAndColoursPrefsViewController changeFont:sender];
}
/*
- revertToStandardSettings:
*/
- (void)revertToStandardSettings:(id)sender
{
#pragma unused(sender)
[[NSUserDefaultsController sharedUserDefaultsController] revertToInitialValues:nil];
}
@end