From 6395ddc26e0d2c3fde5b26568b70a390e4b5f152 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 13 Jan 2010 16:28:24 +0000 Subject: =?UTF-8?q?=E2=80=A2=20F5=20compeltion=20-=20fixed=20issues=20if?= =?UTF-8?q?=20no=20db=20is=20selected=20-=20trial:=20=E2=87=A7=E2=86=A9=20?= =?UTF-8?q?inserts=20the=20entire=20path=20db.table=20or=20db.table.field;?= =?UTF-8?q?=20if=20invoked=20inside=20of=20backticks=20backticked?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 12 ++++++++++-- Source/SPNarrowDownCompletion.h | 4 +++- Source/SPNarrowDownCompletion.m | 38 +++++++++++++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 96c3837e..1359b8d8 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -221,7 +221,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if ([[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"tableName"] != nil) currentTable = [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKeyPath:@"tableName"]; - if(aTableName == nil && aDbName == nil) { + if(aTableName == nil && aDbName == nil && [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKeyPath:@"selectedDatabase"]) { // Put current selected db at the top currentDb = [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKeyPath:@"selectedDatabase"]; [sortedDbs removeObject:currentDb]; @@ -360,11 +360,17 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSString* currentWord = [[self string] substringWithRange:completionRange]; NSString* prefix = @""; NSString* allow = @"_. "; // additional chars which not close the popup + NSString *currentDb = nil; BOOL dbBrowseMode = NO; BOOL backtickMode = NO; BOOL caseInsensitive = YES; + if ([[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"selectedDatabase"] != nil) + currentDb = [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKeyPath:@"selectedDatabase"]; + else + currentDb = @""; + // Check if the caret is inside quotes "" or ''; if so // return the normal word suggestion due to the spelling's settings // plus all unique words used in the textView @@ -374,6 +380,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if(!isDictMode) { + // Check if user wants to insert a db/table/field name // currentWord == ` : user invoked completion via `|` dbBrowseMode = ([currentWord isEqualToString:@"`"]) ? YES : NO; @@ -537,7 +544,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) dbMode:dbBrowseMode backtickMode:backtickMode withDbName:dbName - withTableName:tableName]; + withTableName:tableName + selectedDb:currentDb]; //Get the NSPoint of the first character of the current word NSRange range = NSMakeRange(completionRange.location,0); diff --git a/Source/SPNarrowDownCompletion.h b/Source/SPNarrowDownCompletion.h index f1d4e63c..c01c5880 100644 --- a/Source/SPNarrowDownCompletion.h +++ b/Source/SPNarrowDownCompletion.h @@ -35,6 +35,7 @@ NSArray* suggestions; NSMutableString* mutablePrefix; NSString* staticPrefix; + NSString* currentDb; NSArray* filtered; NSTableView* theTableView; NSPoint caretPos; @@ -46,6 +47,7 @@ BOOL backtickMode; NSFont *tableFont; NSRange theCharRange; + NSRange theInitRange; NSArray *words; id theView; @@ -56,7 +58,7 @@ additionalWordCharacters:(NSString*)someAdditionalWordCharacters caseSensitive:(BOOL)isCaseSensitive charRange:(NSRange)initRange inView:(id)aView dictMode:(BOOL)mode dbMode:(BOOL)theDbMode - backtickMode:(BOOL)theBackTickMode withDbName:(NSString*)dbName withTableName:(NSString*)tableName; + backtickMode:(BOOL)theBackTickMode withDbName:(NSString*)dbName withTableName:(NSString*)tableName selectedDb:(NSString*)selectedDb; - (void)setCaretPos:(NSPoint)aPos; - (void)insert_text:(NSString* )aString; diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m index a041315e..a9d9c143 100644 --- a/Source/SPNarrowDownCompletion.m +++ b/Source/SPNarrowDownCompletion.m @@ -128,7 +128,7 @@ additionalWordCharacters:(NSString*)someAdditionalWordCharacters caseSensitive:(BOOL)isCaseSensitive charRange:(NSRange)initRange inView:(id)aView dictMode:(BOOL)mode dbMode:(BOOL)theDbMode - backtickMode:(BOOL)theBackTickMode withDbName:(NSString*)dbName withTableName:(NSString*)tableName + backtickMode:(BOOL)theBackTickMode withDbName:(NSString*)dbName withTableName:(NSString*)tableName selectedDb:(NSString*)selectedDb { if(self = [self init]) { @@ -149,11 +149,14 @@ caseSensitive = isCaseSensitive; theCharRange = initRange; + if(filterStringIsBacktick) { theCharRange.length = 0; theCharRange.location++; } + theInitRange = theCharRange; + theView = aView; dictMode = mode; @@ -162,6 +165,8 @@ words = nil; } + currentDb = selectedDb; + if(someAdditionalWordCharacters) [textualInputCharacters addCharactersInString:someAdditionalWordCharacters]; @@ -563,8 +568,35 @@ } else { NSMutableDictionary* selectedItem = [[[filtered objectAtIndex:[theTableView selectedRow]] mutableCopy] autorelease]; NSString* candidateMatch = [selectedItem objectForKey:@"match"] ?: [selectedItem objectForKey:@"display"]; - if([[self filterString] length] < [candidateMatch length]) - [self insert_text:candidateMatch]; + if([[NSApp currentEvent] modifierFlags] & (NSShiftKeyMask)) { + NSArray *path = [NSArray arrayWithArray:[[selectedItem objectForKey:@"path"] componentsSeparatedByString:@"⇠"]]; + if([path count]) { + NSMutableString *p = [NSMutableString string]; + NSEnumerator *enumerator = [path reverseObjectEnumerator]; + if(backtickMode) + for (id element in enumerator) { + if(![element isEqualToString:currentDb]) { + [p appendString:element]; + [p appendString:@"`.`"]; + } + } + else + for (id element in enumerator) { + if(![element isEqualToString:currentDb]) { + [p appendString:element]; + [p appendString:@"."]; + } + } + [p appendString:candidateMatch]; + [self insert_text:p]; + } else { + if([[self filterString] length] < [candidateMatch length]) + [self insert_text:candidateMatch]; + } + } else { + if([[self filterString] length] < [candidateMatch length]) + [self insert_text:candidateMatch]; + } } closeMe = YES; -- cgit v1.2.3