From 0ebdbeb0201580e5abcded23dd37b6b3516cbb84 Mon Sep 17 00:00:00 2001 From: avenjamin Date: Thu, 5 Mar 2009 02:39:03 +0000 Subject: Added column names to completion list for for currently selected table. --- Source/CMTextView.m | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'Source') diff --git a/Source/CMTextView.m b/Source/CMTextView.m index bce2bd4a..7ca2f782 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -2,7 +2,7 @@ // CMTextView.m // sequel-pro // -// Created by Carsten BlŸm. +// Created by Carsten Blüm. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -34,11 +34,22 @@ NSString *partialString = [[self string] substringWithRange:charRange]; unsigned int partialLength = [partialString length]; 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 *possibleCompletions = [[tableNames arrayByAddingObjectsFromArray:[self keywords]] - arrayByAddingObjectsFromArray:textViewWords]; + + NSMutableArray *possibleCompletions = [NSMutableArray arrayWithArray:textViewWords]; + [possibleCompletions addObjectsFromArray:[self keywords]]; + [possibleCompletions addObjectsFromArray:tableNames]; + + // Add column 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]; + } + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[cd] %@ AND length > %d", partialString, partialLength]; NSArray *matchingCompletions = [[possibleCompletions filteredArrayUsingPredicate:predicate] sortedArrayUsingSelector:@selector(compare:)]; unsigned i, insindex; -- cgit v1.2.3