From 0ce916eb0583ec6b062786f91bee0133906671ce Mon Sep 17 00:00:00 2001 From: sqlprodev Date: Mon, 11 Apr 2011 20:29:49 +0000 Subject: initial commit of SP_REFACTOR ifdefs, the start of a long quest to separate UI code from functional code --- Source/SPTextView.m | 152 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 137 insertions(+), 15 deletions(-) (limited to 'Source/SPTextView.m') diff --git a/Source/SPTextView.m b/Source/SPTextView.m index 4fef6ee3..5e04ff2b 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -112,9 +112,10 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) - (void) awakeFromNib { - +#ifndef SP_REFACTOR prefs = [[NSUserDefaults standardUserDefaults] retain]; [self setFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorFont]]]; +#endif // Set self as delegate for the textView's textStorage to enable syntax highlighting, [[self textStorage] setDelegate:self]; @@ -124,7 +125,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) autopairEnabled = YES; autoindentIgnoresEnter = NO; autouppercaseKeywordsEnabled = NO; +#ifndef SP_REFACTOR autohelpEnabled = NO; +#endif delBackwardsWasPressed = NO; startListeningToBoundChanges = NO; textBufferSizeIncreased = NO; @@ -142,11 +145,20 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) [scrollView setRulersVisible:YES]; [self setAllowsDocumentBackgroundColorChange:YES]; [self setContinuousSpellCheckingEnabled:NO]; +#ifndef SP_REFACTOR [self setAutoindent:[prefs boolForKey:SPCustomQueryAutoIndent]]; +#else + [self setAutoindent:YES]; +#endif [self setAutoindentIgnoresEnter:YES]; +#ifndef SP_REFACTOR [self setAutopair:[prefs boolForKey:SPCustomQueryAutoPairCharacters]]; [self setAutohelp:[prefs boolForKey:SPCustomQueryUpdateAutoHelp]]; [self setAutouppercaseKeywords:[prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]]; +#else + [self setAutopair:YES]; + [self setAutouppercaseKeywords:YES]; +#endif [self setCompletionWasReinvokedAutomatically:NO]; // Re-define tab stops for a better editing @@ -159,6 +171,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) [scrollView setPostsBoundsChangedNotifications:YES]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(boundsDidChangeNotification:) name:NSViewBoundsDidChangeNotification object:[scrollView contentView]]; +#ifndef SP_REFACTOR [self setQueryHiliteColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorHighlightQueryColor]]]; [self setQueryEditorBackgroundColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBackgroundColor]]]; [self setCommentColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCommentColor]]]; @@ -189,7 +202,22 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) [prefs addObserver:self forKeyPath:SPCustomQueryEditorTextColor options:NSKeyValueObservingOptionNew context:NULL]; [prefs addObserver:self forKeyPath:SPCustomQueryEditorTabStopWidth options:NSKeyValueObservingOptionNew context:NULL]; [prefs addObserver:self forKeyPath:SPCustomQueryAutoUppercaseKeywords options:NSKeyValueObservingOptionNew context:NULL]; +#else + [self setQueryHiliteColor:[NSColor whiteColor]]; + [self setQueryEditorBackgroundColor:[NSColor whiteColor]]; + [self setCommentColor:[NSColor darkGrayColor]]; + [self setQuoteColor:[NSColor blueColor]]; + [self setKeywordColor:[NSColor redColor]]; + [self setBacktickColor:[NSColor purpleColor]]; + [self setNumericColor:[NSColor blueColor]]; + [self setVariableColor:[NSColor yellowColor]]; + [self setOtherTextColor:[NSColor blackColor]]; + [self setTextColor:otherTextColor]; + [self setInsertionPointColor:[NSColor blackColor]]; + [self setShouldHiliteQuery:YES]; + [self setSelectedTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSColor lightGrayColor], NSBackgroundColorAttributeName, nil]]; +#endif } - (void) setConnection:(MCPConnection *)theConnection withVersion:(NSInteger)majorVersion @@ -203,6 +231,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) */ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { +#ifndef SP_REFACTOR if ([keyPath isEqualToString:SPCustomQueryEditorBackgroundColor]) { [self setQueryEditorBackgroundColor:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]]; [self setNeedsDisplay:YES]; @@ -255,6 +284,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) } else if ([keyPath isEqualToString:SPCustomQueryAutoUppercaseKeywords]) { [self setAutouppercaseKeywords:[prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]]; } +#endif } /** @@ -375,7 +405,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) if(!aDbName) { // Try to suggest only items which are uniquely valid for the parsed string - NSArray *uniqueSchema = [[SPNavigatorController sharedNavigatorController] getUniqueDbIdentifierFor:[aTableName lowercaseString] andConnection:[[[self delegate] valueForKeyPath:@"tableDocumentInstance"] connectionID] ignoreFields:YES]; + NSArray *uniqueSchema = [[SPNavigatorController sharedNavigatorController] getUniqueDbIdentifierFor:[aTableName lowercaseString] andConnection:[[(NSObject*)[self delegate] valueForKeyPath:@"tableDocumentInstance"] connectionID] ignoreFields:YES]; NSInteger uniqueSchemaKind = [[uniqueSchema objectAtIndex:0] intValue]; // If no db name but table name check if table name is a valid name in the current selected db @@ -535,7 +565,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) if(completionIsOpen || !self || ![self delegate]) return; // Cancel autocompletion trigger +#ifndef SP_REFACTOR if([prefs boolForKey:SPCustomQueryAutoComplete]) +#endif [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doAutoCompletion) object:nil]; @@ -577,7 +609,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) { // Cancel autocompletion trigger +#ifndef SP_REFACTOR if([prefs boolForKey:SPCustomQueryAutoComplete]) +#endif [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doAutoCompletion) object:nil]; @@ -770,7 +804,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) } // Cancel autocompletion trigger again if user typed something in while parsing +#ifndef SP_REFACTOR if([prefs boolForKey:SPCustomQueryAutoComplete]) +#endif [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doAutoCompletion) object:nil]; @@ -982,7 +1018,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) // If Extended Table Info tab is active delegate the print call to the SPPrintController // if the user doesn't select anything in self if([[[[self delegate] class] description] isEqualToString:@"SPExtendedTableInfo"] && ![self selectedRange].length) { - [[[self delegate] valueForKeyPath:@"tableDocumentInstance"] printDocument:sender]; + [[(NSObject*)[self delegate] valueForKeyPath:@"tableDocumentInstance"] printDocument:sender]; return; } @@ -1020,6 +1056,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) [self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.01]; } +#ifndef SP_REFACTOR /** * Search for the current selection or current word in the MySQL Help */ @@ -1027,6 +1064,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) { [customQueryInstance showHelpForCurrentWord:self]; } +#endif /** * If the textview has a selection, wrap it with the supplied prefix and suffix strings; @@ -1051,7 +1089,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) [self setSelectedRange:innerSelectionRange]; // If autopair is enabled mark last autopair character as autopair-linked +#ifndef SP_REFACTOR if([prefs boolForKey:SPCustomQueryAutoPairCharacters]) +#endif [[self textStorage] addAttribute:kAPlinked value:kAPval range:NSMakeRange(NSMaxRange(innerSelectionRange), 1)]; return YES; @@ -1133,6 +1173,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) if (selectedRange.location == NSNotFound || ![self isEditable]) return NO; NSString *indentString = @"\t"; +#ifndef SP_REFACTOR if ([prefs boolForKey:SPCustomQuerySoftIndent]) { NSUInteger numberOfSpaces = [prefs integerForKey:SPCustomQuerySoftIndentWidth]; if(numberOfSpaces < 1) numberOfSpaces = 1; @@ -1142,6 +1183,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) [spaces appendString:@" "]; indentString = [NSString stringWithString:spaces]; } +#endif // Indent the currently selected line if the caret is within a single line if (selectedRange.length == 0) { @@ -1222,6 +1264,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) // Check for soft indention NSUInteger indentStringLength = 1; +#ifndef SP_REFACTOR if ([prefs boolForKey:SPCustomQuerySoftIndent]) { NSUInteger numberOfSpaces = [prefs integerForKey:SPCustomQuerySoftIndentWidth]; if(numberOfSpaces < 1) numberOfSpaces = 1; @@ -1234,8 +1277,11 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) if(numberOfLeadingWhiteSpaces == NSNotFound) numberOfLeadingWhiteSpaces = 0; replaceRange = NSMakeRange(currentLineRange.location, numberOfLeadingWhiteSpaces); } else { +#endif replaceRange = NSMakeRange(currentLineRange.location, indentStringLength); +#ifndef SP_REFACTOR } +#endif // Register the undent for undo [self shouldChangeTextInRange:replaceRange replacementString:@""]; @@ -1258,6 +1304,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) // Check for soft or hard indention NSString *indentString = @"\t"; NSUInteger indentStringLength = 1; +#ifndef SP_REFACTOR if ([prefs boolForKey:SPCustomQuerySoftIndent]) { indentStringLength = [prefs integerForKey:SPCustomQuerySoftIndentWidth]; if(indentStringLength < 1) indentStringLength = 1; @@ -1267,6 +1314,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) [spaces appendString:@" "]; indentString = [NSString stringWithString:spaces]; } +#endif // Check if blockRange starts with SPACE or TAB // (this also catches the first line of the entire text buffer or @@ -1321,7 +1369,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) { // Cancel auto-completion timer +#ifndef SP_REFACTOR if([prefs boolForKey:SPCustomQueryAutoComplete]) +#endif [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doAutoCompletion) object:nil]; @@ -1362,7 +1412,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) // } // } // } else { - arr = [NSArray arrayWithArray:[[[self delegate] valueForKeyPath:@"tablesListInstance"] allTableAndViewNames]]; + arr = [NSArray arrayWithArray:[[(NSObject*)[self delegate] valueForKeyPath:@"tablesListInstance"] allTableAndViewNames]]; if(arr == nil) { arr = [NSArray array]; } @@ -1371,13 +1421,13 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) // } } else if([kind isEqualToString:@"$SP_ASLIST_ALL_DATABASES"]) { - arr = [NSArray arrayWithArray:[[[self delegate] valueForKeyPath:@"tablesListInstance"] allDatabaseNames]]; + arr = [NSArray arrayWithArray:[[(NSObject*)[self delegate] valueForKeyPath:@"tablesListInstance"] allDatabaseNames]]; if(arr == nil) { arr = [NSArray array]; } for(id w in arr) [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:w, @"display", @"database-small", @"image", @"", @"isRef", nil]]; - arr = [NSArray arrayWithArray:[[[self delegate] valueForKeyPath:@"tablesListInstance"] allSystemDatabaseNames]]; + arr = [NSArray arrayWithArray:[[(NSObject*)[self delegate] valueForKeyPath:@"tablesListInstance"] allSystemDatabaseNames]]; if(arr == nil) { arr = [NSArray array]; } @@ -1733,6 +1783,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) if (tablesListInstance && [tablesListInstance selectedDatabase]) currentDb = [tablesListInstance selectedDatabase]; +#ifndef SP_REFACTOR while([theHintString isMatchedByRegex:@"(? SP_TEXT_SIZE_TRIGGER_FOR_PARTLY_PARSING) @@ -3488,6 +3604,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) - (void)changeFont:(id)sender { +#ifndef SP_REFACTOR if (prefs && [self font] != nil) { [prefs setObject:[NSArchiver archivedDataWithRootObject:[self font]] forKey:SPCustomQueryEditorFont]; NSFont *nf = [[NSFontPanel sharedFontPanel] panelConvertFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorFont]]]; @@ -3498,6 +3615,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) [self setNeedsDisplay:YES]; [prefs setObject:[NSArchiver archivedDataWithRootObject:nf] forKey:SPCustomQueryEditorFont]; } +#endif } #pragma mark - @@ -3513,6 +3631,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) // Remove observers [[NSNotificationCenter defaultCenter] removeObserver:self]; +#ifndef SP_REFACTOR [prefs removeObserver:self forKeyPath:SPCustomQueryEditorFont]; [prefs removeObserver:self forKeyPath:SPCustomQueryEditorBackgroundColor]; [prefs removeObserver:self forKeyPath:SPCustomQueryEditorHighlightQueryColor]; @@ -3526,9 +3645,12 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse) [prefs removeObserver:self forKeyPath:SPCustomQueryEditorTextColor]; [prefs removeObserver:self forKeyPath:SPCustomQueryEditorTabStopWidth]; [prefs removeObserver:self forKeyPath:SPCustomQueryAutoUppercaseKeywords]; +#endif if (completionIsOpen) [completionPopup close], completionIsOpen = NO; +#ifndef SP_REFACTOR [prefs release]; +#endif [lineNumberView release]; if(queryHiliteColor) [queryHiliteColor release]; if(queryEditorBackgroundColor) [queryEditorBackgroundColor release]; -- cgit v1.2.3