From 2b1111d26762ad18f2b758872e774335ac314d7c Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 25 May 2009 19:33:23 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20narrow-down=20completion=20-=20f?= =?UTF-8?q?irst=20trial=20to=20use=20images=20for=20suggestions=20(up=20to?= =?UTF-8?q?=20now=20supported:=20=20tables/views,=20funcs,=20procs,=20dbs,?= =?UTF-8?q?=20otherwise=20show=20a=20transparent=20dummy)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.h | 1 + Source/CMTextView.m | 65 ++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 51 insertions(+), 15 deletions(-) (limited to 'Source') diff --git a/Source/CMTextView.h b/Source/CMTextView.h index 0ada18ed..152ddbc9 100644 --- a/Source/CMTextView.h +++ b/Source/CMTextView.h @@ -62,6 +62,7 @@ - (BOOL) shiftSelectionLeft; - (NSArray *) completionsForPartialWordRange:(NSRange)charRange indexOfSelectedItem:(int *)index; - (NSArray *) keywords; +- (NSArray *) functions; - (void) setAutoindent:(BOOL)enableAutoindent; - (BOOL) autoindent; - (void) setAutoindentIgnoresEnter:(BOOL)enableAutoindentIgnoresEnter; diff --git a/Source/CMTextView.m b/Source/CMTextView.m index c147678a..9b5fb9aa 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -138,13 +138,17 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [queryResult dataSeek:0]; for (i = 0 ; i < [queryResult numOfRows] ; i++) { - [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:0]]; + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[queryResult fetchRowAsArray] objectAtIndex:0], @"display", @"table-small-square", @"image", nil]]; + //[possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:0]]; } // Add field names to completions list for currently selected table if ([[[self window] delegate] table] != nil) { id columnNames = [[[[self window] delegate] valueForKeyPath:@"tableDataInstance"] valueForKey:@"columnNames"]; - [possibleCompletions addObjectsFromArray:columnNames]; + // [possibleCompletions addObjectsFromArray:columnNames]; + NSString *s; + enumerate(columnNames, s) + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:s, @"display", @"dummy-small", @"image", nil]]; } // Add all database names to completions list @@ -153,7 +157,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [queryResult dataSeek:0]; for (i = 0 ; i < [queryResult numOfRows] ; i++) { - [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:0]]; + // [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:0]]; + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[queryResult fetchRowAsArray] objectAtIndex:0], @"display", @"database-small", @"image", nil]]; } // Add proc/func only for MySQL version 5 or higher @@ -164,7 +169,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [queryResult dataSeek:0]; for (i = 0 ; i < [queryResult numOfRows] ; i++) { - [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:1]]; + // [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:1]]; + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[queryResult fetchRowAsArray] objectAtIndex:1], @"display", @"proc-small", @"image", nil]]; } // Add all function to completions list for currently selected table @@ -173,7 +179,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [queryResult dataSeek:0]; for (i = 0 ; i < [queryResult numOfRows] ; i++) { - [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:1]]; + // [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:1]]; + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[queryResult fetchRowAsArray] objectAtIndex:1], @"display", @"func-small", @"image", nil]]; } } @@ -192,19 +199,39 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) enumerate(textViewWords, s) if(![uniqueArray containsObject:s]) [uniqueArray addObject:s]; - + + // Remove current word from list + [uniqueArray removeObject:currentWord]; + int reverseSort = NO; NSArray *sortedArray = [[[uniqueArray mutableCopy] autorelease] sortedArrayUsingFunction:alphabeticSort context:&reverseSort]; - [possibleCompletions addObjectsFromArray:sortedArray]; + // [possibleCompletions addObjectsFromArray:sortedArray]; + NSString *w; + enumerate(sortedArray, w) + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:w, @"display", @"dummy-small", @"image", nil]]; + + + // Remove the current word + // [possibleCompletions removeObject:currentWord]; } } // Add predefined keywords - if(!isDictMode) - [possibleCompletions addObjectsFromArray:[self keywords]]; - - // Remove the current word - [possibleCompletions removeObject:currentWord]; + if(!isDictMode) { + // [possibleCompletions addObjectsFromArray:[self keywords]]; + NSString *s; + enumerate([self keywords], s) + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:s, @"display", @"dummy-small", @"image", nil]]; + } + + + // Add predefined functions + if(!isDictMode) { + // [possibleCompletions addObjectsFromArray:[self functions]]; + NSString *s; + enumerate([self functions], s) + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:s, @"display", @"func-small", @"image", nil]]; + } // Build array of dictionaries as e.g.: // [NSDictionary dictionaryWithObjectsAndKeys:@"foo", @"display", @"`foo`", @"insert", @"func-small", @"image", nil] @@ -212,7 +239,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) enumerate(possibleCompletions, candidate) { if(![compl containsObject:candidate]) - [compl addObject:[NSDictionary dictionaryWithObjectsAndKeys:candidate, @"display", nil]]; + [compl addObject:candidate]; } [possibleCompletions release]; @@ -1646,8 +1673,16 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) @"YEAR_MONTH", @"ZEROFILL", - //functions - + nil]; +} + +/* + * List of fucntions for autocompletion. If you add a keyword here, + * it should also be added to the flex file SPEditorTokens.l + */ +-(NSArray *)functions +{ + return [NSArray arrayWithObjects: @"ABS", @"ACOS", @"ADDDATE", -- cgit v1.2.3