aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravenjamin <avenjamin@gmail.com>2008-12-22 12:01:04 +0000
committeravenjamin <avenjamin@gmail.com>2008-12-22 12:01:04 +0000
commit48ea6a3e1333f612e9f3e76b7fca7ddec64b6291 (patch)
tree1967e88dce584664199d153291b18767904a412f
parent17ee678d8b552693f45a9d38cdf0684aed6dabf6 (diff)
downloadsequelpro-48ea6a3e1333f612e9f3e76b7fca7ddec64b6291.tar.gz
sequelpro-48ea6a3e1333f612e9f3e76b7fca7ddec64b6291.tar.bz2
sequelpro-48ea6a3e1333f612e9f3e76b7fca7ddec64b6291.zip
• CMTextView.m : added new auto-complete keywords
• TableSource.m : fixed spelling error
-rw-r--r--Source/CMTextView.m133
-rw-r--r--Source/TableSource.m2
2 files changed, 90 insertions, 45 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index 0542ffa8..369e9a43 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -28,54 +28,35 @@
- (NSArray *)completionsForPartialWordRange:(NSRange)charRange indexOfSelectedItem:(int *)index
{
+ NSCharacterSet *separators = [NSCharacterSet characterSetWithCharactersInString:@" \t\r\n,()\"'`-!"];
+ NSArray *textViewWords = [[self string] componentsSeparatedByCharactersInSet:separators];
NSString *partialString = [[self string] substringWithRange:charRange];
unsigned int partialLength = [partialString length];
- unsigned int options = NSCaseInsensitiveSearch | NSAnchoredSearch;
- unsigned int i;
- NSRange partialRange = NSMakeRange(0, partialLength);
+ id tableNames = [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"tables"];
+ //unsigned int options = NSCaseInsensitiveSearch | NSAnchoredSearch;
+ //NSRange partialRange = NSMakeRange(0, partialLength);
NSMutableArray *compl = [[NSMutableArray alloc] initWithCapacity:32];
- NSArray *keywords = [self keywords];
-
- // Get the document
-// id tableDocument = [[[self window] windowController] document];
- id tableDocument = [[self window] delegate];
-
-//NSLog(@"doc: %@", [[[self window] windowController] document]);
-
- // Get an array of table names for the current database
- id tableNames = [[tableDocument valueForKeyPath:@"tablesListInstance"] valueForKey:@"tables"];
-
- // Add matching table names to compl
- for (i = 0; i < [tableNames count]; i ++)
+ NSArray *possibleCompletions = [[tableNames arrayByAddingObjectsFromArray:[self keywords]]
+ arrayByAddingObjectsFromArray:textViewWords];
+ NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[cd] %@ AND length > %d", partialString, partialLength];
+ NSArray *matchingCompletions = [[possibleCompletions filteredArrayUsingPredicate:predicate] sortedArrayUsingSelector:@selector(compare:)];
+ unsigned i, insindex;
+
+ insindex = 0;
+ for (i = 0; i < [matchingCompletions count]; i ++)
{
- if ([[tableNames objectAtIndex:i] length] > partialLength)
+ if ([partialString isEqualToString:[[matchingCompletions objectAtIndex:i] substringToIndex:partialLength]])
{
- NSRange range = [[tableNames objectAtIndex:i] rangeOfString:partialString
- options:options
- range:partialRange];
- if (range.location != NSNotFound)
- {
- [compl addObject:[tableNames objectAtIndex:i]];
- }
+ // Matches case --> Insert at beginning of completion list
+ [compl insertObject:[matchingCompletions objectAtIndex:i] atIndex:insindex++];
}
-
- }
-
- // Add matching keywords to compl
- for (i = 0; i < [keywords count]; i ++)
- {
- if ([[keywords objectAtIndex:i] length] > partialLength)
+ else
{
- NSRange range = [[keywords objectAtIndex:i] rangeOfString:partialString
- options:options
- range:partialRange];
- if (range.location != NSNotFound)
- {
- [compl addObject:[keywords objectAtIndex:i]];
- }
+ // Not matching case --> Insert at end of completion list
+ [compl addObject:[matchingCompletions objectAtIndex:i]];
}
}
-
+
return [compl autorelease];
}
@@ -85,7 +66,14 @@
return [NSArray arrayWithObjects:
@"ADD",
@"ALL",
- @"ALTER",
+ @"ALTER TABLE",
+ @"ALTER VIEW",
+ @"ALTER SCHEMA",
+ @"ALTER SCHEMA",
+ @"ALTER FUNCTION",
+ @"ALTER COLUMN",
+ @"ALTER DATABASE",
+ @"ALTER PROCEDURE",
@"ANALYZE",
@"AND",
@"ASC",
@@ -111,7 +99,15 @@
@"CONSTRAINT",
@"CONTINUE",
@"CONVERT",
- @"CREATE",
+ @"CREATE VIEW",
+ @"CREATE INDEX",
+ @"CREATE FUNCTION",
+ @"CREATE DATABASE",
+ @"CREATE PROCEDURE",
+ @"CREATE SCHEMA",
+ @"CREATE TRIGGER",
+ @"CREATE TABLE",
+ @"CREATE USER",
@"CROSS",
@"CURRENT_DATE",
@"CURRENT_TIME",
@@ -137,7 +133,18 @@
@"DISTINCTROW",
@"DIV",
@"DOUBLE",
- @"DROP",
+ @"DROP TABLE",
+ @"DROP TRIGGER",
+ @"DROP VIEW",
+ @"DROP SCHEMA",
+ @"DROP USER",
+ @"DROP PROCEDURE",
+ @"DROP FUNCTION",
+ @"DROP FOREIGN KEY",
+ @"DROP INDEX",
+ @"DROP PREPARE",
+ @"DROP PRIMARY KEY",
+ @"DROP DATABASE",
@"DUAL",
@"EACH",
@"ELSE",
@@ -153,7 +160,7 @@
@"FLOAT",
@"FOR",
@"FORCE",
- @"FOREIGN",
+ @"FOREIGN KEY",
@"FOUND",
@"FROM",
@"FULLTEXT",
@@ -240,7 +247,45 @@
@"SENSITIVE",
@"SEPARATOR",
@"SET",
- @"SHOW",
+ @"SHOW PROCEDURE STATUS",
+ @"SHOW PROCESSLIST",
+ @"SHOW SCHEMAS",
+ @"SHOW SLAVE HOSTS",
+ @"SHOW PRIVILEGES",
+ @"SHOW OPEN TABLES",
+ @"SHOW MASTER STATUS",
+ @"SHOW SLAVE STATUS",
+ @"SHOW PLUGIN",
+ @"SHOW STORAGE ENGINES",
+ @"SHOW VARIABLES",
+ @"SHOW WARNINGS",
+ @"SHOW TRIGGERS",
+ @"SHOW TABLES",
+ @"SHOW MASTER LOGS",
+ @"SHOW TABLE STATUS",
+ @"SHOW TABLE TYPES",
+ @"SHOW STATUS",
+ @"SHOW INNODB STATUS",
+ @"SHOW CREATE DATABASE",
+ @"SHOW CREATE FUNCTION",
+ @"SHOW CREATE PROCEDURE",
+ @"SHOW CREATE SCHEMA",
+ @"SHOW COLUMNS",
+ @"SHOW COLLATION",
+ @"SHOW BINARY LOGS",
+ @"SHOW BINLOG EVENTS",
+ @"SHOW CHARACTER SET",
+ @"SHOW CREATE TABLE",
+ @"SHOW CREATE VIEW",
+ @"SHOW FUNCTION STATUS",
+ @"SHOW GRANTS",
+ @"SHOW INDEX",
+ @"SHOW FIELDS",
+ @"SHOW ERRORS",
+ @"SHOW DATABASES",
+ @"SHOW ENGINE",
+ @"SHOW ENGINES",
+ @"SHOW KEYS",
@"SMALLINT",
@"SONAME",
@"SPATIAL",
diff --git a/Source/TableSource.m b/Source/TableSource.m
index 3c91f76c..51ef01cc 100644
--- a/Source/TableSource.m
+++ b/Source/TableSource.m
@@ -938,7 +938,7 @@ Having validated a drop, perform the field/column reordering to match.
return YES;
}
-#pragma mark TtableView delegate methods
+#pragma mark TableView delegate methods
- (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView
{