aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPQueryController.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/SPQueryController.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/SPQueryController.m')
-rw-r--r--Source/SPQueryController.m67
1 files changed, 66 insertions, 1 deletions
diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m
index 911923bd..fec04630 100644
--- a/Source/SPQueryController.m
+++ b/Source/SPQueryController.m
@@ -103,6 +103,44 @@ static SPQueryController *sharedQueryController = nil;
favoritesContainer = [[NSMutableDictionary alloc] init];
historyContainer = [[NSMutableDictionary alloc] init];
contentFilterContainer = [[NSMutableDictionary alloc] init];
+ completionKeywordList = nil;
+ completionFunctionList = nil;
+ functionArgumentSnippets = nil;
+
+ NSError *readError = nil;
+ NSString *convError = nil;
+ NSPropertyListFormat format;
+ NSDictionary *completionPlist;
+ NSData *completionTokensData = [NSData dataWithContentsOfFile:[NSBundle pathForResource:@"CompletionTokens.plist" ofType:nil inDirectory:[[NSBundle mainBundle] bundlePath]]
+ options:NSMappedRead error:&readError];
+
+
+ completionPlist = [NSDictionary dictionaryWithDictionary:[NSPropertyListSerialization propertyListFromData:completionTokensData
+ mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&convError]];
+
+ if(completionPlist == nil || readError != nil || convError != nil) {
+ NSLog(@"Error while reading “CompletionTokens.plist”:\n%@\n%@", [readError localizedDescription], convError);
+ NSBeep();
+ } else {
+ if([completionPlist objectForKey:@"core_keywords"]) {
+ completionKeywordList = [[NSArray arrayWithArray:[completionPlist objectForKey:@"core_keywords"]] retain];
+ } else {
+ NSLog(@"No “core_keywords” array found.");
+ NSBeep();
+ }
+ if([completionPlist objectForKey:@"core_builtin_functions"]) {
+ completionFunctionList = [[NSArray arrayWithArray:[completionPlist objectForKey:@"core_builtin_functions"]] retain];
+ } else {
+ NSLog(@"No “core_builtin_functions” array found.");
+ NSBeep();
+ }
+ if([completionPlist objectForKey:@"function_argument_snippets"]) {
+ functionArgumentSnippets = [[NSDictionary dictionaryWithDictionary:[completionPlist objectForKey:@"function_argument_snippets"]] retain];
+ } else {
+ NSLog(@"No “function_argument_snippets” dictionary found.");
+ NSBeep();
+ }
+ }
}
@@ -463,6 +501,30 @@ static SPQueryController *sharedQueryController = nil;
}
#pragma mark -
+#pragma mark Completion List Controller
+
+- (NSArray*)functionList
+{
+ if(completionFunctionList != nil && [completionFunctionList count])
+ return completionFunctionList;
+ return [NSArray array];
+}
+
+- (NSArray*)keywordList
+{
+ if(completionKeywordList != nil && [completionKeywordList count])
+ return completionKeywordList;
+ return [NSArray array];
+}
+
+- (NSString*)argumentSnippetForFunction:(NSString*)func
+{
+ if(functionArgumentSnippets && [functionArgumentSnippets objectForKey:[func uppercaseString]])
+ return [functionArgumentSnippets objectForKey:[func uppercaseString]];
+ return @"";
+}
+
+#pragma mark -
#pragma mark DocumentsController
- (NSURL *)registerDocumentWithFileURL:(NSURL *)fileURL andContextInfo:(NSMutableDictionary *)contextInfo
@@ -735,7 +797,10 @@ static SPQueryController *sharedQueryController = nil;
[favoritesContainer release], favoritesContainer = nil;
[historyContainer release], historyContainer = nil;
[contentFilterContainer release], contentFilterContainer = nil;
-
+
+ if(completionKeywordList) [completionKeywordList release];
+ if(completionFunctionList) [completionFunctionList release];
+ if(functionArgumentSnippets) [functionArgumentSnippets release];
[super dealloc];
}