From ee8c83d433d0351dffda4ce273e3d1278154f769 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sun, 7 Mar 2010 22:07:58 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20to=20CustomQuery's=20CMTextView=20t?= =?UTF-8?q?he=20option=20to=20set=20auto-completion=20on/off,=20settable?= =?UTF-8?q?=20in=20Prefs=20and=20gear=20menu=20-=20if=20inserted=20complet?= =?UTF-8?q?ion=20is=20marked=20as=20function=20it=20inserts=20snippet=20($?= =?UTF-8?q?{}1:)=20so=20far;=20function=20parameters=20as=20snippets=20fol?= =?UTF-8?q?lows=20soon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/DBView.xib | 119 +++++++--- Interfaces/English.lproj/Preferences.xib | 388 ++++++++++++++++++++++++++++++- Resources/PreferenceDefaults.plist | 4 + Source/CMTextView.h | 7 +- Source/CMTextView.m | 56 ++++- Source/CustomQuery.m | 6 +- Source/SPConstants.h | 2 + Source/SPConstants.m | 2 + Source/SPNarrowDownCompletion.h | 3 +- Source/SPNarrowDownCompletion.m | 19 +- 10 files changed, 556 insertions(+), 50 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 47e08691..b425a7c5 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -24,6 +24,7 @@ YES + YES @@ -62,7 +63,7 @@ {3.40282e+38, 3.40282e+38} {780, 480} - + 256 YES @@ -2143,7 +2144,7 @@ content - + 256 YES @@ -2883,7 +2884,6 @@ {{10, 7}, {706, 544}} - Content @@ -2892,7 +2892,7 @@ customQuery - + 256 YES @@ -2919,6 +2919,29 @@ 6418 + + YES + + YES + Apple HTML pasteboard type + Apple PDF pasteboard type + Apple PICT pasteboard type + Apple PNG pasteboard type + Apple URL pasteboard type + CorePasteboardFlavorType 0x6D6F6F76 + NSColor pasteboard type + NSFilenamesPboardType + NSStringPboardType + NeXT Encapsulated PostScript v1.2 pasteboard type + NeXT RTFD pasteboard type + NeXT Rich Text Format v1.0 pasteboard type + NeXT TIFF v4.0 pasteboard type + NeXT font pasteboard type + NeXT ruler pasteboard type + WebURLsWithTitlesPboardType + public.url + + {694, 14} @@ -3640,6 +3663,16 @@ _popUpItemAction: + + + Auto-completion + + 2147483647 + + + _popUpItemAction: + + Update Help while typing @@ -3653,7 +3686,7 @@ YES - 17 + 19 YES 1 YES @@ -3799,6 +3832,7 @@ {{10, 7}, {706, 544}} + Custom Query @@ -5444,14 +5478,14 @@ - + 134217731 YES YES YES - + @@ -5468,6 +5502,7 @@ {944, 550} + {{0, 0}, {1920, 1178}} {780, 502} @@ -11710,6 +11745,12 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 NSView + + YES + CustomQueryAutoComplete + CustomQueryAuto + CustomQueryAutoUppercaseKeywords + YES @@ -14092,22 +14133,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 5859 - - - value: values.CustomQueryAutoUppercaseKeywords - - - - - - value: values.CustomQueryAutoUppercaseKeywords - value - values.CustomQueryAutoUppercaseKeywords - 2 - - - 5860 - selectTableColumn: @@ -16165,6 +16190,38 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 6904 + + + value: values.CustomQueryAutoComplete + + + + + + value: values.CustomQueryAutoComplete + value + values.CustomQueryAutoComplete + 2 + + + 6910 + + + + value: values.CustomQueryAutoUppercaseKeywords + + + + + + value: values.CustomQueryAutoUppercaseKeywords + value + values.CustomQueryAutoUppercaseKeywords + 2 + + + 6912 + @@ -18410,6 +18467,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + @@ -22752,6 +22810,11 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + + 6908 + + + @@ -24131,6 +24194,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 69.ImportedFromIB2 6901.IBPluginDependency 6902.IBPluginDependency + 6908.IBPluginDependency 711.IBPluginDependency 711.ImportedFromIB2 713.IBPluginDependency @@ -24940,11 +25004,11 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{402, -257}, {944, 550}} + {{-1, 152}, {944, 550}} com.apple.InterfaceBuilder.CocoaPlugin - {{402, -257}, {944, 550}} + {{-1, 152}, {944, 550}} {{62, 352}, {845, 504}} @@ -25110,7 +25174,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{110, 61}, {256, 445}} + {{202, 69}, {256, 462}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -26127,6 +26191,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -26269,7 +26334,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - 6907 + 6912 diff --git a/Interfaces/English.lproj/Preferences.xib b/Interfaces/English.lproj/Preferences.xib index 04efb9eb..4d8b75cd 100644 --- a/Interfaces/English.lproj/Preferences.xib +++ b/Interfaces/English.lproj/Preferences.xib @@ -3721,10 +3721,155 @@ AQAAAAA 25 + + + 268 + {{257, 144}, {179, 18}} + + YES + + 67239424 + 0 + Auto-Completion + + + 1211912703 + 2 + + + + + 200 + 25 + + + + + 268 + {{357, 119}, {29, 19}} + + YES + + -1538130368 + -2076048384 + 0.1 + + + + YES + + YES + allowsFloats + alwaysShowsDecimalSeparator + decimalSeparator + formatterBehavior + groupingSeparator + locale + maximum + maximumIntegerDigits + minimum + minimumFractionDigits + positiveFormat + + + YES + + + . + + + + + + + + #.0 + + + #.0 + #.0 + + + + + + NaN + + + + + + 3 + YES + YES + YES + + . + + NO + NO + YES + + + YES + + + + + + + 268 + {{298, 121}, {54, 14}} + + YES + + 605158976 + 71435264 + Delay by: + + + + + + + + + 268 + {{392, 117}, {15, 22}} + + YES + + 604896800 + 131072 + + + 1 + 0.10000000000000001 + 5 + 0.10000000000000001 + YES + + + + + 268 + {{410, 121}, {27, 14}} + + YES + + 605158976 + 272761856 + secs + + + + + + -2147483380 - {{257, 144}, {197, 18}} + {{257, 91}, {197, 18}} YES @@ -3896,7 +4041,8 @@ AQAAAAA YES - CustomQueryEditorTabStopWidth + CustomQueryAutoComplete + CustomQueryAutoCompleteDelay YES @@ -6040,6 +6186,134 @@ AQAAAAA 1516 + + + takeFloatValueFrom: + + + + 1528 + + + + takeFloatValueFrom: + + + + 1529 + + + + enabled: values.CustomQueryUpdateAutoHelp + + + + + + enabled: values.CustomQueryUpdateAutoHelp + enabled + values.CustomQueryUpdateAutoHelp + 2 + + + 1534 + + + + enabled: values.CustomQueryUpdateAutoHelp + + + + + + enabled: values.CustomQueryUpdateAutoHelp + enabled + values.CustomQueryUpdateAutoHelp + 2 + + + 1535 + + + + value: values.CustomQueryAutoComplete + + + + + + value: values.CustomQueryAutoComplete + value + values.CustomQueryAutoComplete + 2 + + + 1537 + + + + value: values.CustomQueryAutoCompleteDelay + + + + + + value: values.CustomQueryAutoCompleteDelay + value + values.CustomQueryAutoCompleteDelay + 2 + + + 1538 + + + + enabled: values.CustomQueryAutoComplete + + + + + + enabled: values.CustomQueryAutoComplete + enabled + values.CustomQueryAutoComplete + 2 + + + 1539 + + + + value: values.CustomQueryAutoCompleteDelay + + + + + + value: values.CustomQueryAutoCompleteDelay + value + values.CustomQueryAutoCompleteDelay + 2 + + + 1540 + + + + enabled: values.CustomQueryAutoComplete + + + + + + enabled: values.CustomQueryAutoComplete + enabled + values.CustomQueryAutoComplete + 2 + + + 1541 + @@ -7058,6 +7332,11 @@ AQAAAAA + + + + + Editor @@ -8578,6 +8857,85 @@ AQAAAAA + + 1517 + + + YES + + + + + + 1518 + + + YES + + + + + + 1519 + + + YES + + + + + + 1520 + + + YES + + + + + + 1521 + + + YES + + + + + + 1522 + + + + + 1523 + + + YES + + + + + + 1524 + + + + + 1525 + + + + + 1526 + + + + + 1527 + + + @@ -8796,6 +9154,18 @@ AQAAAAA 1507.IBNumberFormatterBehaviorMetadataKey 1507.IBNumberFormatterLocalizesFormatMetadataKey 1507.IBPluginDependency + 1517.IBPluginDependency + 1518.IBPluginDependency + 1519.IBPluginDependency + 1520.IBPluginDependency + 1521.IBPluginDependency + 1522.IBPluginDependency + 1523.IBPluginDependency + 1524.IBNumberFormatterLocalizesFormatMetadataKey + 1524.IBPluginDependency + 1525.IBPluginDependency + 1526.IBPluginDependency + 1527.IBPluginDependency 17.IBEditorWindowLastContentRect 17.IBPluginDependency 17.IBUserGuides @@ -9276,6 +9646,18 @@ AQAAAAA com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin {{571, 222}, {500, 280}} com.apple.InterfaceBuilder.CocoaPlugin @@ -9659,7 +10041,7 @@ AQAAAAA - 1516 + 1541 diff --git a/Resources/PreferenceDefaults.plist b/Resources/PreferenceDefaults.plist index dd4a8a59..5b941ba3 100644 --- a/Resources/PreferenceDefaults.plist +++ b/Resources/PreferenceDefaults.plist @@ -86,6 +86,10 @@ CustomQueryEditorTabStopWidth 4 + CustomQueryAutoComplete + + CustomQueryAutoCompleteDelay + 1.5 CustomQueryAutoHelpDelay 1 lastSqlFileEncoding diff --git a/Source/CMTextView.h b/Source/CMTextView.h index 53afe0df..558bc284 100644 --- a/Source/CMTextView.h +++ b/Source/CMTextView.h @@ -73,6 +73,7 @@ static inline id NSMutableAttributedStringAttributeAtIndex (NSMutableAttributedS NSInteger currentSnippetIndex; BOOL snippetWasJustInserted; + BOOL completionIsOpen; NSColor *queryHiliteColor; NSColor *queryEditorBackgroundColor; @@ -99,6 +100,7 @@ static inline id NSMutableAttributedStringAttributeAtIndex (NSMutableAttributedS @property(retain) NSColor* otherTextColor; @property(assign) NSRange queryRange; @property(assign) BOOL shouldHiliteQuery; +@property(assign) BOOL completionIsOpen; - (IBAction)showMySQLHelpForCurrentWord:(id)sender; @@ -128,12 +130,13 @@ static inline id NSMutableAttributedStringAttributeAtIndex (NSMutableAttributedS - (void) doSyntaxHighlighting; - (NSBezierPath*)roundedBezierPathAroundRange:(NSRange)aRange; - (void) setConnection:(MCPConnection *)theConnection withVersion:(NSInteger)majorVersion; -- (void) doCompletionByUsingSpellChecker:(BOOL)isDictMode fuzzyMode:(BOOL)fuzzySearch; +- (void) doCompletionByUsingSpellChecker:(BOOL)isDictMode fuzzyMode:(BOOL)fuzzySearch autoCompleteMode:(BOOL)autoCompleteMode; +- (void) doAutoCompletion; - (NSArray *)suggestionsForSQLCompletionWith:(NSString *)currentWord dictMode:(BOOL)isDictMode browseMode:(BOOL)dbBrowseMode withTableName:(NSString*)aTableName withDbName:(NSString*)aDbName; - (void) selectCurrentQuery; - (BOOL)checkForCaretInsideSnippet; -- (void)insertFavoriteAsSnippet:(NSString*)theSnippet atRange:(NSRange)targetRange; +- (void)insertAsSnippet:(NSString*)theSnippet atRange:(NSRange)targetRange; - (NSUInteger)characterIndexOfPoint:(NSPoint)aPoint; - (void)insertFileContentOfFile:(NSString *)aPath; diff --git a/Source/CMTextView.m b/Source/CMTextView.m index e32e1234..30c4d7a5 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -98,6 +98,7 @@ static inline NSPoint SPPointOnLine(NSPoint a, NSPoint b, CGFloat t) { return NS @synthesize otherTextColor; @synthesize queryRange; @synthesize shouldHiliteQuery; +@synthesize completionIsOpen; /* * Sort function (mainly used to sort the words in the textView) @@ -126,6 +127,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) startListeningToBoundChanges = NO; textBufferSizeIncreased = NO; snippetControlCounter = -1; + completionIsOpen = NO; lineNumberView = [[NoodleLineNumberView alloc] initWithScrollView:scrollView]; [scrollView setVerticalRulerView:lineNumberView]; @@ -177,6 +179,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [prefs addObserver:self forKeyPath:SPCustomQueryEditorVariableColor options:NSKeyValueObservingOptionNew context:NULL]; [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]; } @@ -234,6 +237,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.1]; } else if ([keyPath isEqualToString:SPCustomQueryEditorTabStopWidth]) { [self setTabStops]; + } else if ([keyPath isEqualToString:SPCustomQueryAutoUppercaseKeywords]) { + [self setAutouppercaseKeywords:[prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]]; } } @@ -467,7 +472,21 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) } -- (void) doCompletionByUsingSpellChecker:(BOOL)isDictMode fuzzyMode:(BOOL)fuzzySearch +- (void) doAutoCompletion +{ + NSRange r = [self selectedRange]; + + if(![[self delegate] isKindOfClass:[CustomQuery class]] || r.length || snippetControlCounter > -1) return; + + if(r.location) { + if([[[self textStorage] attribute:kQuote atIndex:r.location-1 effectiveRange:nil] isEqualToString:kQuoteValue]) + return; + if(![[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:[[self string] characterAtIndex:r.location-1]]) + [self doCompletionByUsingSpellChecker:NO fuzzyMode:NO autoCompleteMode:YES]; + } +} + +- (void) doCompletionByUsingSpellChecker:(BOOL)isDictMode fuzzyMode:(BOOL)fuzzySearch autoCompleteMode:(BOOL)autoCompleteMode { if(![self isEditable]) return; @@ -475,7 +494,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [self breakUndoCoalescing]; NSUInteger caretPos = NSMaxRange([self selectedRange]); - // [self setSelectedRange:NSMakeRange(caretPos, 0)]; + BOOL caretMovedLeft = NO; // Check if caret is located after a ` - if so move caret inside @@ -501,14 +520,12 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) // Break for long stuff if(completionRange.length>100000) return; - NSString* allow; // additional chars which not close the popup if(isDictMode) allow= @"_"; else allow= @"_. "; - BOOL dbBrowseMode = NO; NSInteger backtickMode = 0; // 0 none, 1 rigth only, 2 left only, 3 both BOOL caseInsensitive = YES; @@ -669,7 +686,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) withDbName:dbName withTableName:tableName selectedDb:currentDb - caretMovedLeft:caretMovedLeft]; + caretMovedLeft:caretMovedLeft + autoComplete:autoCompleteMode]; //Get the NSPoint of the first character of the current word NSRange glyphRange = [[self layoutManager] glyphRangeForCharacterRange:NSMakeRange(completionRange.location,1) actualCharacterRange:NULL]; @@ -685,6 +703,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) pos.y -= [[self font] pointSize]*1.25; [completionPopUp setCaretPos:pos]; + completionIsOpen = YES; [completionPopUp orderFront:self]; [completionPopUp insertCommonPrefix]; @@ -1083,7 +1102,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) /* * Inserts a chosen query favorite and initialze a snippet session if user defined any */ -- (void)insertFavoriteAsSnippet:(NSString*)theSnippet atRange:(NSRange)targetRange +- (void)insertAsSnippet:(NSString*)theSnippet atRange:(NSRange)targetRange { // Do not allow the insertion of a query favorite if snippets are active @@ -1496,14 +1515,21 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) long curFlags = ([theEvent modifierFlags] & allFlags); if ([theEvent keyCode] == 53 && [self isEditable]){ // ESC key for internal completion + + // Cancel autocompletion trigger + if([prefs boolForKey:SPCustomQueryAutoComplete]) + [NSObject cancelPreviousPerformRequestsWithTarget:self + selector:@selector(doAutoCompletion) + object:nil]; + if(curFlags==(NSControlKeyMask)) - [self doCompletionByUsingSpellChecker:NO fuzzyMode:YES]; + [self doCompletionByUsingSpellChecker:NO fuzzyMode:YES autoCompleteMode:NO]; else - [self doCompletionByUsingSpellChecker:NO fuzzyMode:NO]; + [self doCompletionByUsingSpellChecker:NO fuzzyMode:NO autoCompleteMode:NO]; return; } if (insertedCharacter == NSF5FunctionKey && [self isEditable]){ // F5 for completion based on spell checker - [self doCompletionByUsingSpellChecker:YES fuzzyMode:NO]; + [self doCompletionByUsingSpellChecker:YES fuzzyMode:NO autoCompleteMode:NO]; return; } @@ -1557,7 +1583,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if(snippetControlCounter < 0 && [[[self window] delegate] fileURL]) { NSArray *snippets = [[SPQueryController sharedQueryController] queryFavoritesForFileURL:[[[self window] delegate] fileURL] andTabTrigger:tabTrigger includeGlobals:YES]; if([snippets count] > 0 && [(NSString*)[(NSDictionary*)[snippets objectAtIndex:0] objectForKey:@"query"] length]) { - [self insertFavoriteAsSnippet:[(NSDictionary*)[snippets objectAtIndex:0] objectForKey:@"query"] atRange:targetRange]; + [self insertAsSnippet:[(NSDictionary*)[snippets objectAtIndex:0] objectForKey:@"query"] atRange:targetRange]; return; } } @@ -3391,6 +3417,16 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [self performSelector:@selector(autoHelp) withObject:nil afterDelay:[[[prefs valueForKey:SPCustomQueryAutoHelpDelay] retain] doubleValue]]; } + // Cancel autocompletion trigger + if([prefs boolForKey:SPCustomQueryAutoComplete]) + [NSObject cancelPreviousPerformRequestsWithTarget:self + selector:@selector(doAutoCompletion) + object:nil]; + + // Start autocompletion if enabled + if([prefs boolForKey:SPCustomQueryAutoComplete] && !completionIsOpen && editedMask != 1) + [self performSelector:@selector(doAutoCompletion) withObject:nil afterDelay:[[[prefs valueForKey:SPCustomQueryAutoCompleteDelay] retain] doubleValue]]; + // Cancel calling doSyntaxHighlighting for large text if([[self string] length] > SP_TEXT_SIZE_TRIGGER_FOR_PARTLY_PARSING) [NSObject cancelPreviousPerformRequestsWithTarget:self diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index e586557e..e3d26d74 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -222,7 +222,7 @@ } // The actual query strings have been already stored as tooltip - [textView insertFavoriteAsSnippet:[[queryFavoritesButton selectedItem] toolTip] atRange:NSMakeRange([textView selectedRange].location, 0)]; + [textView insertAsSnippet:[[queryFavoritesButton selectedItem] toolTip] atRange:NSMakeRange([textView selectedRange].location, 0)]; } } @@ -325,9 +325,9 @@ // on normal autocomplete usage. if (sender == completionListMenuItem) { if([[NSApp currentEvent] modifierFlags] & (NSControlKeyMask)) - [textView doCompletionByUsingSpellChecker:NO fuzzyMode:YES]; + [textView doCompletionByUsingSpellChecker:NO fuzzyMode:YES autoCompleteMode:NO]; else - [textView doCompletionByUsingSpellChecker:NO fuzzyMode:NO]; + [textView doCompletionByUsingSpellChecker:NO fuzzyMode:NO autoCompleteMode:NO]; } // "Editor font..." menu item to bring up the font panel diff --git a/Source/SPConstants.h b/Source/SPConstants.h index 12f2a38f..83ce6996 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -135,6 +135,8 @@ extern NSString *SPCustomQueryUpdateAutoHelp; extern NSString *SPCustomQueryAutoHelpDelay; extern NSString *SPCustomQueryHighlightCurrentQuery; extern NSString *SPCustomQueryEditorTabStopWidth; +extern NSString *SPCustomQueryAutoComplete; +extern NSString *SPCustomQueryAutoCompleteDelay; // AutoUpdate Prefpane extern NSString *SPLastUsedVersion; diff --git a/Source/SPConstants.m b/Source/SPConstants.m index bea60f8b..aa2c3508 100644 --- a/Source/SPConstants.m +++ b/Source/SPConstants.m @@ -103,6 +103,8 @@ NSString *SPCustomQueryUpdateAutoHelp = @"CustomQueryUpdateAutoHelp"; NSString *SPCustomQueryAutoHelpDelay = @"CustomQueryAutoHelpDelay"; NSString *SPCustomQueryHighlightCurrentQuery = @"CustomQueryHighlightCurrentQuery"; NSString *SPCustomQueryEditorTabStopWidth = @"CustomQueryEditorTabStopWidth"; +NSString *SPCustomQueryAutoComplete = @"CustomQueryAutoComplete"; +NSString *SPCustomQueryAutoCompleteDelay = @"CustomQueryAutoCompleteDelay"; // AutoUpdate Prefpane NSString *SPLastUsedVersion = @"LastUsedVersion"; diff --git a/Source/SPNarrowDownCompletion.h b/Source/SPNarrowDownCompletion.h index 96558b9d..6901ffa1 100644 --- a/Source/SPNarrowDownCompletion.h +++ b/Source/SPNarrowDownCompletion.h @@ -49,6 +49,7 @@ BOOL noFilterString; BOOL cursorMovedLeft; BOOL commaInsertionMode; + BOOL autoCompletionMode; NSInteger backtickMode; NSFont *tableFont; NSRange theCharRange; @@ -68,7 +69,7 @@ charRange:(NSRange)initRange parseRange:(NSRange)parseRange inView:(id)aView dictMode:(BOOL)mode dbMode:(BOOL)theDbMode tabTriggerMode:(BOOL)tabTriggerMode fuzzySearch:(BOOL)fuzzySearch backtickMode:(NSInteger)theBackTickMode withDbName:(NSString*)dbName withTableName:(NSString*)tableName - selectedDb:(NSString*)selectedDb caretMovedLeft:(BOOL)caretMovedLeft; + selectedDb:(NSString*)selectedDb caretMovedLeft:(BOOL)caretMovedLeft autoComplete:(BOOL)autoComplete; - (void)setCaretPos:(NSPoint)aPos; - (void)insert_text:(NSString* )aString; - (void)insertCommonPrefix; diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m index 032e80b3..8e5bebec 100644 --- a/Source/SPNarrowDownCompletion.m +++ b/Source/SPNarrowDownCompletion.m @@ -136,7 +136,7 @@ charRange:(NSRange)initRange parseRange:(NSRange)parseRange inView:(id)aView dictMode:(BOOL)mode dbMode:(BOOL)theDbMode tabTriggerMode:(BOOL)tabTriggerMode fuzzySearch:(BOOL)fuzzySearch backtickMode:(NSInteger)theBackTickMode withDbName:(NSString*)dbName withTableName:(NSString*)tableName - selectedDb:(NSString*)selectedDb caretMovedLeft:(BOOL)caretMovedLeft + selectedDb:(NSString*)selectedDb caretMovedLeft:(BOOL)caretMovedLeft autoComplete:(BOOL)autoComplete { if(self = [self init]) { @@ -145,6 +145,8 @@ if(aUserString) [mutablePrefix appendString:aUserString]; + autoCompletionMode = autoComplete; + fuzzyMode = fuzzySearch; if(fuzzyMode) [theTableView setBackgroundColor:[NSColor colorWithCalibratedRed:0.9f green:0.9f blue:0.9f alpha:1.0f]]; @@ -371,6 +373,7 @@ - (void)checkSpaceForAllowedCharacter { [textualInputCharacters removeCharactersInString:@" "]; + if(autoCompletionMode) return; if(spaceCounter < 1) for(id w in filtered){ if([[w objectForKey:@"match"] ?: [w objectForKey:@"display"] rangeOfString:@" "].length) { @@ -444,11 +447,16 @@ } if(![newFiltered count]) { - if([[self filterString] hasSuffix:@"."]) { - [theView doCompletionByUsingSpellChecker:dictMode fuzzyMode:fuzzyMode]; + if(autoCompletionMode) { closeMe = YES; + return; + } else { + if([[self filterString] hasSuffix:@"."]) { + [theView doCompletionByUsingSpellChecker:dictMode fuzzyMode:fuzzyMode autoCompleteMode:NO]; + closeMe = YES; + } + [newFiltered addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"No completions found", @"no completions found message"), @"display", @"", @"noCompletion", nil]]; } - [newFiltered addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"No completions found", @"no completions found message"), @"display", @"", @"noCompletion", nil]]; } NSPoint old = NSMakePoint([self frame].origin.x, [self frame].origin.y + [self frame].size.height); @@ -615,6 +623,7 @@ [NSApp sendEvent:event]; } } + [theView setCompletionIsOpen:NO]; [self close]; usleep(70); // tiny delay to suppress while continously pressing of ESC overlapping } @@ -665,6 +674,8 @@ // If completion string contains backticks move caret out of the backticks if(backtickMode && !triggerMode) [theView performSelector:@selector(moveRight:)]; + else if([[[filtered objectAtIndex:[theTableView selectedRow]] objectForKey:@"image"] hasPrefix:@"func"]) + [theView insertAsSnippet:@"(${1:})" atRange:[theView selectedRange]]; } - (void)completeAndInsertSnippet -- cgit v1.2.3