@@ -85,6 +85,7 @@ @interface SPTextView (Private_API)
85
85
86
86
NSInteger _alphabeticSort (id string1, id string2, void *reverse);
87
87
#ifndef SP_CODA
88
+ - (void )_setTextSelectionColor : (NSColor *)newSelectionColor ;
88
89
- (void )_setTextSelectionColor : (NSColor *)newSelectionColor onBackgroundColor : (NSColor *)aBackgroundColor ;
89
90
#endif
90
91
- (void )_positionCompletionPopup : (SPNarrowDownCompletion *)aPopup relativeToTextAtLocation : (NSUInteger )aLocation ;
@@ -185,27 +186,56 @@ - (void) awakeFromNib
185
186
[[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (boundsDidChangeNotification: ) name: NSViewBoundsDidChangeNotification object: [scrollView contentView ]];
186
187
187
188
#ifndef SP_CODA
188
- [self setQueryHiliteColor: [NSUnarchiver unarchiveObjectWithData: [prefs dataForKey: SPCustomQueryEditorHighlightQueryColor]]];
189
- NSColor *backgroundColor = [NSUnarchiver unarchiveObjectWithData: [prefs dataForKey: SPCustomQueryEditorBackgroundColor]];
190
- [self setQueryEditorBackgroundColor: backgroundColor];
191
- [self setBackgroundColor: backgroundColor];
192
- [self setCommentColor: [NSUnarchiver unarchiveObjectWithData: [prefs dataForKey: SPCustomQueryEditorCommentColor]]];
193
- [self setQuoteColor: [NSUnarchiver unarchiveObjectWithData: [prefs dataForKey: SPCustomQueryEditorQuoteColor]]];
194
- [self setKeywordColor: [NSUnarchiver unarchiveObjectWithData: [prefs dataForKey: SPCustomQueryEditorSQLKeywordColor]]];
195
- [self setBacktickColor: [NSUnarchiver unarchiveObjectWithData: [prefs dataForKey: SPCustomQueryEditorBacktickColor]]];
196
- [self setNumericColor: [NSUnarchiver unarchiveObjectWithData: [prefs dataForKey: SPCustomQueryEditorNumericColor]]];
197
- [self setVariableColor: [NSUnarchiver unarchiveObjectWithData: [prefs dataForKey: SPCustomQueryEditorVariableColor]]];
198
- [self setOtherTextColor: [NSUnarchiver unarchiveObjectWithData: [prefs dataForKey: SPCustomQueryEditorTextColor]]];
199
- [self setTextColor: otherTextColor];
200
- [self setInsertionPointColor: [NSUnarchiver unarchiveObjectWithData: [prefs dataForKey: SPCustomQueryEditorCaretColor]]];
189
+ {
190
+ struct csItem {
191
+ NSString *p;
192
+ SEL m;
193
+ } colorSetup[] = {
194
+ { .p = SPCustomQueryEditorHighlightQueryColor, .m = @selector (setQueryHiliteColor: ) },
195
+ { .p = SPCustomQueryEditorBackgroundColor, .m = @selector (setQueryEditorBackgroundColor: ) },
196
+ { .p = SPCustomQueryEditorBackgroundColor, .m = @selector (setBackgroundColor: ) },
197
+ { .p = SPCustomQueryEditorCommentColor, .m = @selector (setCommentColor: ) },
198
+ { .p = SPCustomQueryEditorQuoteColor, .m = @selector (setQuoteColor: ) },
199
+ { .p = SPCustomQueryEditorSQLKeywordColor, .m = @selector (setKeywordColor: ) },
200
+ { .p = SPCustomQueryEditorBacktickColor, .m = @selector (setBacktickColor: ) },
201
+ { .p = SPCustomQueryEditorNumericColor, .m = @selector (setNumericColor: ) },
202
+ { .p = SPCustomQueryEditorVariableColor, .m = @selector (setVariableColor: ) },
203
+ { .p = SPCustomQueryEditorTextColor, .m = @selector (setOtherTextColor: ) },
204
+ { .p = SPCustomQueryEditorTextColor, .m = @selector (setTextColor: ) },
205
+ { .p = SPCustomQueryEditorCaretColor, .m = @selector (setInsertionPointColor: ) },
206
+ { .p = SPCustomQueryEditorSelectionColor, .m = @selector (_setTextSelectionColor: ) },
207
+ { .p = nil , .m = NULL } // stop key
208
+ };
209
+
210
+ struct csItem *item = &colorSetup[0 ];
211
+
212
+ NSDictionary *vendorDefaults = [prefs volatileDomainForName: NSRegistrationDomain ]; // prefs from -registerDefaults: in app controller
213
+
214
+ do {
215
+ NSData *colorData = [prefs dataForKey: item->p];
216
+ NSColor *color;
217
+ BOOL canRetry = YES ;
218
+ retry:
219
+ if (colorData && (color = [NSUnarchiver unarchiveObjectWithData: colorData])) {
220
+ [self performSelector: item->m withObject: color];
221
+ }
222
+ else if (canRetry) {
223
+ // #2963: previous versions of SP would accept invalid data (resulting in `nil`) and store it in prefs,
224
+ // so if loading failed use the default color instead (`nil` would cause exceptions later on)
225
+ colorData = [vendorDefaults objectForKey: item->p];
226
+ canRetry = NO ;
227
+ SPLog (@" user defaults contains invalid value for theme color '%@ '! (retrying with default value)" , item->p );
228
+ goto retry;
229
+ }
230
+ } while ((++item)->p );
231
+ }
232
+
201
233
[self setShouldHiliteQuery: [prefs boolForKey: SPCustomQueryHighlightCurrentQuery]];
202
234
203
- [self _setTextSelectionColor: [NSUnarchiver unarchiveObjectWithData: [prefs dataForKey: SPCustomQueryEditorSelectionColor]] onBackgroundColor: backgroundColor];
204
-
205
235
[self setAutomaticDashSubstitutionEnabled: NO ]; // prevents -- from becoming —, the em dash.
206
236
[self setAutomaticQuoteSubstitutionEnabled: NO ]; // prevents ' and " from becoming ‘, ’ and “, ” respectively.
207
237
208
- // Register observers for the when editor background colors preference changes
238
+ // Register observers for the when editor colors preference changes
209
239
[prefs addObserver: self forKeyPath: SPCustomQueryEditorSelectionColor options: NSKeyValueObservingOptionNew context: NULL ];
210
240
[prefs addObserver: self forKeyPath: SPCustomQueryEditorCaretColor options: NSKeyValueObservingOptionNew context: NULL ];
211
241
[prefs addObserver: self forKeyPath: SPCustomQueryEditorFont options: NSKeyValueObservingOptionNew context: NULL ];
@@ -3736,6 +3766,11 @@ - (void)_setTextSelectionColor:(NSColor *)newSelectionColor onBackgroundColor:(N
3736
3766
// Set the selection colour
3737
3767
[self setSelectedTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: newSelectionColor, NSBackgroundColorAttributeName , nil ]];
3738
3768
}
3769
+
3770
+ - (void )_setTextSelectionColor : (NSColor *)newSelectionColor
3771
+ {
3772
+ [self _setTextSelectionColor: newSelectionColor onBackgroundColor: [self backgroundColor ]];
3773
+ }
3739
3774
#endif
3740
3775
3741
3776
/* *
0 commit comments