aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-01-13 16:28:24 +0000
committerBibiko <bibiko@eva.mpg.de>2010-01-13 16:28:24 +0000
commit6395ddc26e0d2c3fde5b26568b70a390e4b5f152 (patch)
treef3db8d0d49c078504e2758dcd0e1a8f17c2a1b47
parent79c5e1f2d102ffa9d5121ee1f32aee8ca00c2a72 (diff)
downloadsequelpro-6395ddc26e0d2c3fde5b26568b70a390e4b5f152.tar.gz
sequelpro-6395ddc26e0d2c3fde5b26568b70a390e4b5f152.tar.bz2
sequelpro-6395ddc26e0d2c3fde5b26568b70a390e4b5f152.zip
• F5 compeltion
- fixed issues if no db is selected - trial: ⇧↩ inserts the entire path db.table or db.table.field; if invoked inside of backticks backticked
-rw-r--r--Source/CMTextView.m12
-rw-r--r--Source/SPNarrowDownCompletion.h4
-rw-r--r--Source/SPNarrowDownCompletion.m38
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;