aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPNarrowDownCompletion.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-03-08 13:02:05 +0000
committerBibiko <bibiko@eva.mpg.de>2010-03-08 13:02:05 +0000
commit7f8b4675de74f7b43057d21d445f0ddca59f95b8 (patch)
tree69402383bf87177e40d58a0824f6721be226e96b /Source/SPNarrowDownCompletion.m
parentc10728213ede7dbdd37493aca9657ab4010edbdc (diff)
downloadsequelpro-7f8b4675de74f7b43057d21d445f0ddca59f95b8.tar.gz
sequelpro-7f8b4675de74f7b43057d21d445f0ddca59f95b8.tar.bz2
sequelpro-7f8b4675de74f7b43057d21d445f0ddca59f95b8.zip
• outsourced keyword completion and function completion lists to CompletionTokens.plist
• SPQueryController manages keyword and function completion lists now; this reduces the memory usage a bit and the list is easier to edit • added pre-defined function argument snippets to CompletionTokens.plist (auto-generated from mysql's HELP) • added Preference option for Editor whether a function completion should insert () and if found the function argument snippets automatically or not - last ) will be linked as autopaired then • changed behaviour for wrapping a selection into `"'() etc. - now it re-selects the original selection after wrapping and in addition last wrap character is now marked as autopair-linked • improved logic for popping up the auto-completion list
Diffstat (limited to 'Source/SPNarrowDownCompletion.m')
-rw-r--r--Source/SPNarrowDownCompletion.m38
1 files changed, 23 insertions, 15 deletions
diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m
index 3df3d7b6..10d4c1f7 100644
--- a/Source/SPNarrowDownCompletion.m
+++ b/Source/SPNarrowDownCompletion.m
@@ -33,6 +33,7 @@
#import "SPStringAdditions.h"
#import "ImageAndTextCell.h"
#import "SPConstants.h"
+#import "SPQueryController.h"
#import "RegexKitLite.h"
#import "CMTextView.h"
#include <tgmath.h>
@@ -112,6 +113,8 @@
filtered = nil;
spaceCounter = 0;
+ prefs = [NSUserDefaults standardUserDefaults];
+
tableFont = [NSUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:SPCustomQueryEditorFont]];
[self setupInterface];
}
@@ -451,11 +454,15 @@
closeMe = YES;
return;
} else {
+ if([theView completionWasReinvokedAutomatically]) return;
if([[self filterString] hasSuffix:@"."]) {
+ [theView setCompletionWasReinvokedAutomatically:YES];
[theView doCompletionByUsingSpellChecker:dictMode fuzzyMode:fuzzyMode autoCompleteMode:NO];
closeMe = YES;
+ return;
+ } else {
+ [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]];
}
}
@@ -656,15 +663,15 @@
[commonPrefix setString:tempPrefix];
}
- // if(![commonPrefix length]) return;
-
- NSString* toInsert = [commonPrefix substringFromIndex:[[self filterString] length]];
- [mutablePrefix appendString:toInsert];
- theCharRange.length += [toInsert length];
- theParseRange.length += [toInsert length];
- [theView insertText:[toInsert lowercaseString]];
- [self checkSpaceForAllowedCharacter];
-
+ // Insert common prefix automatically
+ if([[self filterString] length] < [commonPrefix length]) {
+ NSString* toInsert = [commonPrefix substringFromIndex:[[self filterString] length]];
+ [mutablePrefix appendString:toInsert];
+ theCharRange.length += [toInsert length];
+ theParseRange.length += [toInsert length];
+ [theView insertText:[toInsert lowercaseString]];
+ [self checkSpaceForAllowedCharacter];
+ }
}
- (void)insert_text:(NSString* )aString
@@ -675,11 +682,12 @@
// If completion string contains backticks move caret out of the backticks
if(backtickMode && !triggerMode)
[theView performSelector:@selector(moveRight:)];
- // If it's a function insert () snippet
- else if([[[filtered objectAtIndex:[theTableView selectedRow]] objectForKey:@"image"] hasPrefix:@"func"] && ![aString hasSuffix:@")"]) {
- [theView insertText:@"()"];
- [theView performSelector:@selector(moveLeft:)];
- // [theView insertAsSnippet:@"(${1:})" atRange:[theView selectedRange]];
+ // If it's a function insert () and if given arguments as snippets
+ else if([prefs boolForKey:SPCustomQueryFunctionCompletionInsertsArguments] && [[[filtered objectAtIndex:[theTableView selectedRow]] objectForKey:@"image"] hasPrefix:@"func"] && ![aString hasSuffix:@")"]) {
+ NSString *functionArgumentSnippet = [NSString stringWithFormat:@"(%@)", [[SPQueryController sharedQueryController] argumentSnippetForFunction:aString]];
+ [theView insertAsSnippet:functionArgumentSnippet atRange:[theView selectedRange]];
+ if([functionArgumentSnippet length] == 2)
+ [theView performSelector:@selector(moveLeft:)];
}
}