aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMax <dmoagx@users.noreply.github.com>2017-12-29 22:37:50 +0100
committerMax <dmoagx@users.noreply.github.com>2018-01-20 02:42:36 +0100
commit2602f2abd70c2e83a50099fca0141c241552f68f (patch)
tree9b3aee49a0417effbd4d3a95147c399838ae7221 /Source
parent0b096429fee59f72d0191a05d56d3b06229afd4e (diff)
downloadsequelpro-2602f2abd70c2e83a50099fca0141c241552f68f.tar.gz
sequelpro-2602f2abd70c2e83a50099fca0141c241552f68f.tar.bz2
sequelpro-2602f2abd70c2e83a50099fca0141c241552f68f.zip
merge SPQueryController (part of #2789)
Diffstat (limited to 'Source')
-rw-r--r--Source/SPContentFilterManager.m1
-rw-r--r--Source/SPCustomQuery.m1
-rw-r--r--Source/SPDatabaseDocument.m1
-rw-r--r--Source/SPNarrowDownCompletion.m1
-rw-r--r--Source/SPQueryConsoleDataSource.h35
-rw-r--r--Source/SPQueryConsoleDataSource.m111
-rw-r--r--Source/SPQueryController.h32
-rw-r--r--Source/SPQueryController.m564
-rw-r--r--Source/SPQueryControllerInitializer.h37
-rw-r--r--Source/SPQueryControllerInitializer.m145
-rw-r--r--Source/SPQueryDocumentsController.h61
-rw-r--r--Source/SPQueryDocumentsController.m414
-rw-r--r--Source/SPQueryFavoriteManager.m1
-rw-r--r--Source/SPTableContent.m1
-rw-r--r--Source/SPTextView.m1
15 files changed, 595 insertions, 811 deletions
diff --git a/Source/SPContentFilterManager.m b/Source/SPContentFilterManager.m
index 512e19d8..bf29d15a 100644
--- a/Source/SPContentFilterManager.m
+++ b/Source/SPContentFilterManager.m
@@ -32,7 +32,6 @@
#import "ImageAndTextCell.h"
#import "RegexKitLite.h"
#import "SPQueryController.h"
-#import "SPQueryDocumentsController.h"
#import "SPDatabaseDocument.h"
#import "SPTableContent.h"
#import "SPConnectionController.h"
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index a1e14a1f..0f880e8c 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -46,7 +46,6 @@
#import "SPQueryFavoriteManager.h"
#endif
#import "SPQueryController.h"
-#import "SPQueryDocumentsController.h"
#import "SPEncodingPopupAccessory.h"
#import "SPDataStorage.h"
#import "SPAlertSheets.h"
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 1961cbe7..dd781992 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -43,7 +43,6 @@
#import "SPExportController.h"
#import "SPSplitView.h"
#import "SPQueryController.h"
-#import "SPQueryDocumentsController.h"
#import "SPWindowController.h"
#import "SPNavigatorController.h"
#import "SPSQLParser.h"
diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m
index c2158299..ad355c26 100644
--- a/Source/SPNarrowDownCompletion.m
+++ b/Source/SPNarrowDownCompletion.m
@@ -38,7 +38,6 @@
#import "SPQueryController.h"
#import "RegexKitLite.h"
#import "SPTextView.h"
-#import "SPQueryDocumentsController.h"
#import "SPDatabaseStructure.h"
#pragma mark -
diff --git a/Source/SPQueryConsoleDataSource.h b/Source/SPQueryConsoleDataSource.h
deleted file mode 100644
index ac0ce88b..00000000
--- a/Source/SPQueryConsoleDataSource.h
+++ /dev/null
@@ -1,35 +0,0 @@
-//
-// SPQueryConsoleDataSource.h
-// sequel-pro
-//
-// Created by Stuart Connolly (stuconnolly.com) on August 30, 2011.
-// Copyright (c) 2011 Stuart Connolly. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// More info at <https://github.com/sequelpro/sequelpro>
-
-#import "SPQueryController.h"
-
-@interface SPQueryController (SPQueryConsoleDataSource)
-
-@end
diff --git a/Source/SPQueryConsoleDataSource.m b/Source/SPQueryConsoleDataSource.m
deleted file mode 100644
index eb669051..00000000
--- a/Source/SPQueryConsoleDataSource.m
+++ /dev/null
@@ -1,111 +0,0 @@
-//
-// SPQueryConsoleDataSource.m
-// sequel-pro
-//
-// Created by Stuart Connolly (stuconnolly.com) on August 30, 2011.
-// Copyright (c) 2011 Stuart Connolly. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// More info at <https://github.com/sequelpro/sequelpro>
-
-#import "SPQueryConsoleDataSource.h"
-#import "SPConsoleMessage.h"
-
-static NSUInteger SPMessageTruncateCharacterLength = 256;
-
-@implementation SPQueryController (SPQueryConsoleDataSource)
-
-/**
- * Table view delegate method. Returns the number of rows in the table veiw.
- */
-- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
-{
-#ifndef SP_CODA
- return [messagesVisibleSet count];
-#else
- return 0;
-#endif
-}
-
-/**
- * Table view delegate method. Returns the specific object for the requested column and row.
- */
-- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
-{
-#ifndef SP_CODA
- NSString *returnValue = nil;
-
- NSString *identifier = [tableColumn identifier];
-
- if (!identifier) return returnValue;
-
- id object = [[messagesVisibleSet objectAtIndex:row] valueForKey:identifier];
-
- if ([[tableColumn identifier] isEqualToString:SPTableViewDateColumnID]) {
-
- returnValue = [dateFormatter stringFromDate:(NSDate *)object];
- }
- else {
- if ([(NSString *)object length] > SPMessageTruncateCharacterLength) {
- object = [NSString stringWithFormat:@"%@...", [object substringToIndex:SPMessageTruncateCharacterLength]];
- }
-
- returnValue = object;
- }
-
- if (!returnValue) return returnValue;
-
- NSMutableDictionary *stringAtributes = nil;
-
- if (consoleFont) {
- stringAtributes = [NSMutableDictionary dictionaryWithObject:consoleFont forKey:NSFontAttributeName];
- }
-
- // If this is an error message give it a red colour
- if ([(SPConsoleMessage *)[messagesVisibleSet objectAtIndex:row] isError]) {
- if (stringAtributes) {
- [stringAtributes setObject:[NSColor redColor] forKey:NSForegroundColorAttributeName];
- }
- else {
- stringAtributes = [NSMutableDictionary dictionaryWithObject:[NSColor redColor] forKey:NSForegroundColorAttributeName];
- }
- }
-
- return [[[NSAttributedString alloc] initWithString:returnValue attributes:stringAtributes] autorelease];
-#else
- return nil;
-#endif
-}
-
-- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
-{
- NSString *string = [self sqlStringForRowIndexes:rowIndexes];
- if([string length]) {
- [pboard declareTypes:@[NSStringPboardType] owner:self];
- return [pboard setString:string forType:NSStringPboardType];
- }
-
- return NO;
-}
-
-@end
diff --git a/Source/SPQueryController.h b/Source/SPQueryController.h
index 12ff6d7b..ea292dd9 100644
--- a/Source/SPQueryController.h
+++ b/Source/SPQueryController.h
@@ -120,4 +120,36 @@ extern NSString *SPTableViewDatabaseColumnID;
*/
- (NSString *)sqlStringForRowIndexes:(NSIndexSet *)indexes;
+#pragma mark - SPQueryControllerInitializer
+
+- (NSError *)loadCompletionLists;
+
+#pragma mark - SPQueryDocumentsController
+
+- (NSURL *)registerDocumentWithFileURL:(NSURL *)fileURL andContextInfo:(NSMutableDictionary *)contextInfo;
+- (void)removeRegisteredDocumentWithFileURL:(NSURL *)fileURL;
+
+- (void)addFavorite:(NSDictionary *)favorite forFileURL:(NSURL *)fileURL;
+- (void)replaceFavoritesByArray:(NSArray *)favoritesArray forFileURL:(NSURL *)fileURL;
+- (void)removeFavoriteAtIndex:(NSUInteger)index forFileURL:(NSURL *)fileURL;
+- (void)insertFavorite:(NSDictionary *)favorite atIndex:(NSUInteger)index forFileURL:(NSURL *)fileURL;
+
+- (void)addHistory:(NSString *)history forFileURL:(NSURL *)fileURL;
+- (void)replaceHistoryByArray:(NSArray *)historyArray forFileURL:(NSURL *)fileURL;
+
+- (void)replaceContentFilterByArray:(NSArray *)contentFilterArray ofType:(NSString *)filterType forFileURL:(NSURL *)fileURL;
+
+- (NSMutableArray *)favoritesForFileURL:(NSURL *)fileURL;
+- (NSMutableArray *)historyForFileURL:(NSURL *)fileURL;
+- (NSArray *)historyMenuItemsForFileURL:(NSURL *)fileURL;
+- (NSUInteger)numberOfHistoryItemsForFileURL:(NSURL *)fileURL;
+- (NSMutableDictionary *)contentFilterForFileURL:(NSURL *)fileURL;
+
+- (NSArray *)queryFavoritesForFileURL:(NSURL *)fileURL andTabTrigger:(NSString *)tabTrigger includeGlobals:(BOOL)includeGlobals;
+
+// Completion list controller
+- (NSArray*)functionList;
+- (NSArray*)keywordList;
+- (NSString*)argumentSnippetForFunction:(NSString*)func;
+
@end
diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m
index 41d71154..87709949 100644
--- a/Source/SPQueryController.m
+++ b/Source/SPQueryController.m
@@ -31,7 +31,7 @@
#import "SPQueryController.h"
#import "SPConsoleMessage.h"
#import "SPCustomQuery.h"
-#import "SPQueryControllerInitializer.h"
+#import "SPAppController.h"
#import "pthread.h"
@@ -40,8 +40,16 @@ NSString *SPQueryConsoleWindowAutoSaveName = @"QueryConsole";
NSString *SPTableViewDateColumnID = @"messageDate";
NSString *SPTableViewConnectionColumnID = @"messageConnection";
NSString *SPTableViewDatabaseColumnID = @"messageDatabase";
+
+static NSString *SPCompletionTokensFilename = @"CompletionTokens.plist";
+
+static NSString *SPCompletionTokensKeywordsKey = @"core_keywords";
+static NSString *SPCompletionTokensFunctionsKey = @"core_builtin_functions";
+static NSString *SPCompletionTokensSnippetsKey = @"function_argument_snippets";
#endif
+static NSUInteger SPMessageTruncateCharacterLength = 256;
+
@interface SPQueryController ()
- (void)_updateFilterState;
@@ -640,6 +648,560 @@ static SPQueryController *sharedQueryController = nil;
#endif
}
+#pragma mark - SPQueryControllerInitializer
+
+/**
+ * Set the window's auto save name and initialise display.
+ */
+- (void)awakeFromNib
+{
+#ifndef SP_CODA /* init ivars */
+ prefs = [NSUserDefaults standardUserDefaults];
+
+ [self setWindowFrameAutosaveName:SPQueryConsoleWindowAutoSaveName];
+
+ // Show/hide table columns
+ [[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] setHidden:![prefs boolForKey:SPConsoleShowTimestamps]];
+ [[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] setHidden:![prefs boolForKey:SPConsoleShowConnections]];
+ [[consoleTableView tableColumnWithIdentifier:SPTableViewDatabaseColumnID] setHidden:![prefs boolForKey:SPConsoleShowDatabases]];
+
+ showSelectStatementsAreDisabled = ![prefs boolForKey:SPConsoleShowSelectsAndShows];
+ showHelpStatementsAreDisabled = ![prefs boolForKey:SPConsoleShowHelps];
+
+ [self _updateFilterState];
+
+ [loggingDisabledTextField setStringValue:([prefs boolForKey:SPConsoleEnableLogging]) ? @"" : NSLocalizedString(@"Query logging is currently disabled", @"query logging disabled label")];
+
+ // Setup data formatter
+ dateFormatter = [[NSDateFormatter alloc] init];
+
+ [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
+
+ [dateFormatter setDateStyle:NSDateFormatterNoStyle];
+ [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
+
+ // Set the process table view's vertical gridlines if required
+ [consoleTableView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
+
+ // Set the strutcture and index view's font
+ BOOL useMonospacedFont = [prefs boolForKey:SPUseMonospacedFonts];
+ CGFloat monospacedFontSize = [prefs floatForKey:SPMonospacedFontSize] > 0 ? [prefs floatForKey:SPMonospacedFontSize] : [NSFont smallSystemFontSize];
+
+ for (NSTableColumn *column in [consoleTableView tableColumns])
+ {
+ [[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:monospacedFontSize] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+ }
+
+ //allow drag-out copying of selected rows
+ [consoleTableView setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
+#endif
+}
+
+/**
+ * Loads the query controller's completion tokens data.
+ */
+- (NSError *)loadCompletionLists
+{
+ NSError *readError = nil;
+ NSString *convError = nil;
+ NSString *errorDescription = nil;
+
+ NSPropertyListFormat format;
+ NSData *completionTokensData = [NSData dataWithContentsOfFile:
+ [NSBundle pathForResource:SPCompletionTokensFilename
+ ofType:nil
+ inDirectory:[[NSBundle mainBundle] bundlePath]]
+ options:NSMappedRead error:&readError];
+
+ NSDictionary *completionPlist = [NSDictionary dictionaryWithDictionary:
+ [NSPropertyListSerialization propertyListFromData:completionTokensData
+ mutabilityOption:NSPropertyListMutableContainersAndLeaves
+ format:&format
+ errorDescription:&convError]];
+
+ if (completionPlist == nil || readError != nil || convError != nil) {
+ errorDescription = [NSString stringWithFormat:@"Error reading '%@': %@, %@", SPCompletionTokensFilename, [readError localizedDescription], convError];
+ }
+ else {
+ if ([completionPlist objectForKey:SPCompletionTokensKeywordsKey]) {
+ completionKeywordList = [[NSArray arrayWithArray:[completionPlist objectForKey:SPCompletionTokensKeywordsKey]] retain];
+ }
+ else {
+ errorDescription = [NSString stringWithFormat:@"No '%@' array found.", SPCompletionTokensKeywordsKey];
+ }
+
+ if ([completionPlist objectForKey:SPCompletionTokensFunctionsKey]) {
+ completionFunctionList = [[NSArray arrayWithArray:[completionPlist objectForKey:SPCompletionTokensFunctionsKey]] retain];
+ }
+ else {
+ errorDescription = [NSString stringWithFormat:@"No '%@' array found.", SPCompletionTokensFunctionsKey];
+ }
+
+ if ([completionPlist objectForKey:SPCompletionTokensSnippetsKey]) {
+ functionArgumentSnippets = [[NSDictionary dictionaryWithDictionary:[completionPlist objectForKey:SPCompletionTokensSnippetsKey]] retain];
+ }
+ else {
+ errorDescription = [NSString stringWithFormat:@"No '%@' dictionary found.", SPCompletionTokensSnippetsKey];
+ }
+ }
+
+ return errorDescription ? [NSError errorWithDomain:NSCocoaErrorDomain code:1 userInfo:@{NSLocalizedDescriptionKey : errorDescription}] : nil;
+}
+
+#pragma mark - SPQueryConsoleDataSource
+
+/**
+ * Table view delegate method. Returns the number of rows in the table veiw.
+ */
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
+{
+#ifndef SP_CODA
+ return [messagesVisibleSet count];
+#else
+ return 0;
+#endif
+}
+
+/**
+ * Table view delegate method. Returns the specific object for the requested column and row.
+ */
+- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
+{
+#ifndef SP_CODA
+ NSString *returnValue = nil;
+
+ NSString *identifier = [tableColumn identifier];
+
+ if (!identifier) return returnValue;
+
+ id object = [[messagesVisibleSet objectAtIndex:row] valueForKey:identifier];
+
+ if ([[tableColumn identifier] isEqualToString:SPTableViewDateColumnID]) {
+
+ returnValue = [dateFormatter stringFromDate:(NSDate *)object];
+ }
+ else {
+ if ([(NSString *)object length] > SPMessageTruncateCharacterLength) {
+ object = [NSString stringWithFormat:@"%@...", [object substringToIndex:SPMessageTruncateCharacterLength]];
+ }
+
+ returnValue = object;
+ }
+
+ if (!returnValue) return returnValue;
+
+ NSMutableDictionary *stringAtributes = nil;
+
+ if (consoleFont) {
+ stringAtributes = [NSMutableDictionary dictionaryWithObject:consoleFont forKey:NSFontAttributeName];
+ }
+
+ // If this is an error message give it a red colour
+ if ([(SPConsoleMessage *)[messagesVisibleSet objectAtIndex:row] isError]) {
+ if (stringAtributes) {
+ [stringAtributes setObject:[NSColor redColor] forKey:NSForegroundColorAttributeName];
+ }
+ else {
+ stringAtributes = [NSMutableDictionary dictionaryWithObject:[NSColor redColor] forKey:NSForegroundColorAttributeName];
+ }
+ }
+
+ return [[[NSAttributedString alloc] initWithString:returnValue attributes:stringAtributes] autorelease];
+#else
+ return nil;
+#endif
+}
+
+- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
+{
+ NSString *string = [self sqlStringForRowIndexes:rowIndexes];
+ if([string length]) {
+ [pboard declareTypes:@[NSStringPboardType] owner:self];
+ return [pboard setString:string forType:NSStringPboardType];
+ }
+
+ return NO;
+}
+
+#pragma mark - SPQueryDocumentsController
+
+- (NSURL *)registerDocumentWithFileURL:(NSURL *)fileURL andContextInfo:(NSMutableDictionary *)contextInfo
+{
+#ifndef SP_CODA
+ // Register a new untiled document and return its URL
+ if (fileURL == nil) {
+ NSURL *new = [NSURL URLWithString:[[NSString stringWithFormat:NSLocalizedString(@"Untitled %ld",@"Title of a new Sequel Pro Document"), (unsigned long)untitledDocumentCounter] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
+ untitledDocumentCounter++;
+
+ if (![favoritesContainer objectForKey:[new absoluteString]]) {
+ NSMutableArray *arr = [[NSMutableArray alloc] init];
+ [favoritesContainer setObject:arr forKey:[new absoluteString]];
+ [arr release];
+ }
+
+ // Set the global history coming from the Prefs as default if available
+ if (![historyContainer objectForKey:[new absoluteString]]) {
+ if ([prefs objectForKey:SPQueryHistory]) {
+ NSMutableArray *arr = [[NSMutableArray alloc] init];
+ [arr addObjectsFromArray:[prefs objectForKey:SPQueryHistory]];
+ [historyContainer setObject:arr forKey:[new absoluteString]];
+ [arr release];
+ }
+ else {
+ NSMutableArray *arr = [[NSMutableArray alloc] init];
+ [historyContainer setObject:[NSMutableArray array] forKey:[new absoluteString]];
+ [arr release];
+ }
+ }
+
+ // Set the doc-based content filters
+ if (![contentFilterContainer objectForKey:[new absoluteString]]) {
+ [contentFilterContainer setObject:[NSMutableDictionary dictionary] forKey:[new absoluteString]];
+ }
+
+ return new;
+ }
+
+ // Register a spf file to manage all query favorites and query history items
+ // file path based (incl. Untitled docs) in a dictionary whereby the key represents the file URL as string.
+ if (![favoritesContainer objectForKey:[fileURL absoluteString]]) {
+ if (contextInfo != nil && [contextInfo objectForKey:SPQueryFavorites] && [[contextInfo objectForKey:SPQueryFavorites] count]) {
+ NSMutableArray *arr = [[NSMutableArray alloc] init];
+ [arr addObjectsFromArray:[contextInfo objectForKey:SPQueryFavorites]];
+ [favoritesContainer setObject:arr forKey:[fileURL absoluteString]];
+ [arr release];
+ }
+ else {
+ NSMutableArray *arr = [[NSMutableArray alloc] init];
+ [favoritesContainer setObject:arr forKey:[fileURL absoluteString]];
+ [arr release];
+ }
+ }
+
+ if (![historyContainer objectForKey:[fileURL absoluteString]]) {
+ if (contextInfo != nil && [contextInfo objectForKey:SPQueryHistory] && [[contextInfo objectForKey:SPQueryHistory] count]) {
+ NSMutableArray *arr = [[NSMutableArray alloc] init];
+ [arr addObjectsFromArray:[contextInfo objectForKey:SPQueryHistory]];
+ [historyContainer setObject:arr forKey:[fileURL absoluteString]];
+ [arr release];
+ }
+ else {
+ NSMutableArray *arr = [[NSMutableArray alloc] init];
+ [historyContainer setObject:arr forKey:[fileURL absoluteString]];
+ [arr release];
+ }
+ }
+
+ if (![contentFilterContainer objectForKey:[fileURL absoluteString]]) {
+ if (contextInfo != nil && [contextInfo objectForKey:SPContentFilters]) {
+ [contentFilterContainer setObject:[contextInfo objectForKey:SPContentFilters] forKey:[fileURL absoluteString]];
+ }
+ else {
+ NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
+ [contentFilterContainer setObject:dict forKey:[fileURL absoluteString]];
+ [dict release];
+ }
+ }
+
+ return fileURL;
+#else
+ return nil;
+#endif
+}
+
+- (void)removeRegisteredDocumentWithFileURL:(NSURL *)fileURL
+{
+#ifndef SP_CODA
+ // Check for multiple instance of the same document.
+ // Remove it if only one instance was registerd.
+ NSArray *allDocs = [SPAppDelegate orderedDocuments];
+ NSMutableArray *allURLs = [NSMutableArray array];
+
+ for (id doc in allDocs)
+ {
+ if (![doc fileURL]) continue;
+
+ if ([allURLs containsObject:[doc fileURL]]) {
+ return;
+ }
+ else {
+ [allURLs addObject:[doc fileURL]];
+ }
+ }
+
+ if ([favoritesContainer objectForKey:[fileURL absoluteString]]) {
+ [favoritesContainer removeObjectForKey:[fileURL absoluteString]];
+ }
+
+ if ([historyContainer objectForKey:[fileURL absoluteString]]) {
+ [historyContainer removeObjectForKey:[fileURL absoluteString]];
+ }
+
+ if ([contentFilterContainer objectForKey:[fileURL absoluteString]]) {
+ [contentFilterContainer removeObjectForKey:[fileURL absoluteString]];
+ }
+#endif
+}
+
+- (void)replaceContentFilterByArray:(NSArray *)contentFilterArray ofType:(NSString *)filterType forFileURL:(NSURL *)fileURL
+{
+#ifndef SP_CODA
+ if ([contentFilterContainer objectForKey:[fileURL absoluteString]]) {
+ NSMutableDictionary *c = [[NSMutableDictionary alloc] init];
+ [c setDictionary:[contentFilterContainer objectForKey:[fileURL absoluteString]]];
+ [c setObject:contentFilterArray forKey:filterType];
+ [contentFilterContainer setObject:c forKey:[fileURL absoluteString]];
+ [c release];
+ }
+#endif
+}
+
+- (void)replaceFavoritesByArray:(NSArray *)favoritesArray forFileURL:(NSURL *)fileURL
+{
+#ifndef SP_CODA
+ if ([favoritesContainer objectForKey:[fileURL absoluteString]]) {
+ [favoritesContainer setObject:favoritesArray forKey:[fileURL absoluteString]];
+ }
+#endif
+}
+
+/**
+ * Remove a Query Favorite the passed file URL
+ *
+ * @param index The index of the to be removed favorite
+ *
+ * @param fileURL The NSURL of the current active SPDatabaseDocument
+ */
+- (void)removeFavoriteAtIndex:(NSUInteger)index forFileURL:(NSURL *)fileURL
+{
+#ifndef SP_CODA
+ [[favoritesContainer objectForKey:[fileURL absoluteString]] removeObjectAtIndex:index];
+#endif
+}
+
+- (void)insertFavorite:(NSDictionary *)favorite atIndex:(NSUInteger)index forFileURL:(NSURL *)fileURL
+{
+#ifndef SP_CODA
+ [[favoritesContainer objectForKey:[fileURL absoluteString]] insertObject:favorite atIndex:index];
+#endif
+}
+
+- (void)replaceHistoryByArray:(NSArray *)historyArray forFileURL:(NSURL *)fileURL
+{
+#ifndef SP_CODA
+ if ([historyContainer objectForKey:[fileURL absoluteString]]) {
+ [historyContainer setObject:historyArray forKey:[fileURL absoluteString]];
+ }
+
+ // Inform all opened documents to update the history list
+ for (id doc in [SPAppDelegate orderedDocuments])
+ {
+ if([[doc valueForKeyPath:@"customQueryInstance"] respondsToSelector:@selector(historyItemsHaveBeenUpdated:)]) {
+ [[doc valueForKeyPath:@"customQueryInstance"] performSelectorOnMainThread:@selector(historyItemsHaveBeenUpdated:) withObject:self waitUntilDone:NO];
+ }
+ }
+
+ // User did choose to clear the global history list
+ if (![fileURL isFileURL] && ![historyArray count]) {
+ [prefs setObject:historyArray forKey:SPQueryHistory];
+ }
+#endif
+}
+
+- (void)addFavorite:(NSDictionary *)favorite forFileURL:(NSURL *)fileURL
+{
+#ifndef SP_CODA
+ if ([favoritesContainer objectForKey:[fileURL absoluteString]]) {
+ [[favoritesContainer objectForKey:[fileURL absoluteString]] addObject:favorite];
+ }
+#endif
+}
+
+- (void)addHistory:(NSString *)history forFileURL:(NSURL *)fileURL
+{
+#ifndef SP_CODA
+ NSUInteger maxHistoryItems = [[prefs objectForKey:SPCustomQueryMaxHistoryItems] integerValue];
+
+ // Save each history item due to its document source
+ if ([historyContainer objectForKey:[fileURL absoluteString]]) {
+
+ // Remove all duplicates by using a NSPopUpButton
+ NSPopUpButton *uniquifier = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0,0,0,0) pullsDown:YES];
+
+ [uniquifier addItemsWithTitles:[historyContainer objectForKey:[fileURL absoluteString]]];
+ [uniquifier insertItemWithTitle:history atIndex:0];
+
+ while ((NSUInteger)[uniquifier numberOfItems] > maxHistoryItems)
+ {
+ [uniquifier removeItemAtIndex:[uniquifier numberOfItems]-1];
+ }
+
+ [self replaceHistoryByArray:[uniquifier itemTitles] forFileURL:fileURL];
+ [uniquifier release];
+ }
+
+ // Save history items coming from each Untitled document in the global Preferences successively
+ // regardingless of the source document.
+ if (![fileURL isFileURL]) {
+
+ // Remove all duplicates by using a NSPopUpButton
+ NSPopUpButton *uniquifier = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0,0,0,0) pullsDown:YES];
+ [uniquifier addItemsWithTitles:[prefs objectForKey:SPQueryHistory]];
+ [uniquifier insertItemWithTitle:history atIndex:0];
+
+ while ((NSUInteger)[uniquifier numberOfItems] > maxHistoryItems)
+ {
+ [uniquifier removeItemAtIndex:[uniquifier numberOfItems] - 1];
+ }
+
+ [prefs setObject:[uniquifier itemTitles] forKey:SPQueryHistory];
+ [uniquifier release];
+ }
+#endif
+}
+
+- (NSMutableArray *)favoritesForFileURL:(NSURL *)fileURL
+{
+#ifndef SP_CODA
+ if ([favoritesContainer objectForKey:[fileURL absoluteString]]) {
+ return [favoritesContainer objectForKey:[fileURL absoluteString]];
+ }
+#endif
+
+ return [NSMutableArray array];
+}
+
+- (NSMutableArray *)historyForFileURL:(NSURL *)fileURL
+{
+#ifndef SP_CODA
+ if ([historyContainer objectForKey:[fileURL absoluteString]]) {
+ return [historyContainer objectForKey:[fileURL absoluteString]];
+ }
+#endif
+
+ return [NSMutableArray array];
+}
+
+- (NSArray *)historyMenuItemsForFileURL:(NSURL *)fileURL
+{
+#ifndef SP_CODA
+ if ([historyContainer objectForKey:[fileURL absoluteString]]) {
+ NSMutableArray *returnArray = [NSMutableArray arrayWithCapacity:[[historyContainer objectForKey:[fileURL absoluteString]] count]];
+ NSMenuItem *historyMenuItem;
+
+ for (NSString* history in [historyContainer objectForKey:[fileURL absoluteString]])
+ {
+ historyMenuItem = [[[NSMenuItem alloc] initWithTitle:([history length] > 64) ? [NSString stringWithFormat:@"%@…", [history substringToIndex:63]] : history
+ action:NULL
+ keyEquivalent:@""] autorelease];
+
+ [historyMenuItem setToolTip:([history length] > 256) ? [NSString stringWithFormat:@"%@…", [history substringToIndex:255]] : history];
+ [returnArray addObject:historyMenuItem];
+ }
+
+ return returnArray;
+ }
+#endif
+
+ return @[];
+}
+
+/**
+ * Return the number of history items for the passed file URL
+ *
+ * @param fileURL The NSURL of the current active SPDatabaseDocument
+ *
+ */
+- (NSUInteger)numberOfHistoryItemsForFileURL:(NSURL *)fileURL
+{
+#ifndef SP_CODA
+ if ([historyContainer objectForKey:[fileURL absoluteString]]) {
+ return [[historyContainer objectForKey:[fileURL absoluteString]] count];
+ }
+ else {
+ return 0;
+ }
+#endif
+
+ return 0;
+}
+
+/**
+ * Return a mutable dictionary of all content filters for the passed file URL.
+ * If no content filters were found it returns an empty mutable dictionary.
+ *
+ * @param fileURL The NSURL of the current active SPDatabaseDocument
+ *
+ */
+- (NSMutableDictionary *)contentFilterForFileURL:(NSURL *)fileURL
+{
+#ifndef SP_CODA
+ if ([contentFilterContainer objectForKey:[fileURL absoluteString]]) {
+ return [contentFilterContainer objectForKey:[fileURL absoluteString]];
+ }
+#endif
+
+ return [NSMutableDictionary dictionary];
+}
+
+- (NSArray *)queryFavoritesForFileURL:(NSURL *)fileURL andTabTrigger:(NSString *)tabTrigger includeGlobals:(BOOL)includeGlobals
+{
+ if (![tabTrigger length]) return @[];
+
+ NSMutableArray *result = [[NSMutableArray alloc] init];
+
+ for (id fav in [self favoritesForFileURL:fileURL])
+ {
+ if ([fav objectForKey:@"tabtrigger"] && [[fav objectForKey:@"tabtrigger"] isEqualToString:tabTrigger]) {
+ [result addObject:fav];
+ }
+ }
+
+#ifndef SP_CODA
+ if (includeGlobals && [prefs objectForKey:SPQueryFavorites]) {
+
+ for (id fav in [prefs objectForKey:SPQueryFavorites])
+ {
+ if ([fav objectForKey:@"tabtrigger"] && [[fav objectForKey:@"tabtrigger"] isEqualToString:tabTrigger]) {
+ [result addObject:fav];
+ break;
+ }
+ }
+ }
+#endif
+
+ return [result autorelease];
+}
+
+#pragma mark -
+#pragma mark Completion list controller
+
+/**
+ * Return an array of all pre-defined SQL functions for completion.
+ */
+- (NSArray*)functionList
+{
+ return (completionFunctionList != nil && [completionFunctionList count]) ? completionFunctionList : @[];
+}
+
+/**
+ * Return an array of all pre-defined SQL keywords for completion.
+ */
+- (NSArray*)keywordList
+{
+ return (completionKeywordList != nil && [completionKeywordList count]) ? completionKeywordList : @[];
+}
+
+/**
+ * Return the parameter list as snippet of the passed SQL functions for completion.
+ *
+ * @param func The name of the function whose parameter list is asked for
+ */
+- (NSString*)argumentSnippetForFunction:(NSString*)func
+{
+ return (functionArgumentSnippets && [functionArgumentSnippets objectForKey:[func uppercaseString]]) ? [functionArgumentSnippets objectForKey:[func uppercaseString]] : @"";
+}
+
#pragma mark -
- (void)dealloc
diff --git a/Source/SPQueryControllerInitializer.h b/Source/SPQueryControllerInitializer.h
deleted file mode 100644
index fa082a90..00000000
--- a/Source/SPQueryControllerInitializer.h
+++ /dev/null
@@ -1,37 +0,0 @@
-//
-// SPQueryControllerInitializer.h
-// sequel-pro
-//
-// Created by Stuart Connolly (stuconnolly.com) on September 1, 2011.
-// Copyright (c) 2011 Stuart Connolly. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// More info at <https://github.com/sequelpro/sequelpro>
-
-#import "SPQueryController.h"
-
-@interface SPQueryController (SPQueryControllerInitializer)
-
-- (NSError *)loadCompletionLists;
-
-@end
diff --git a/Source/SPQueryControllerInitializer.m b/Source/SPQueryControllerInitializer.m
deleted file mode 100644
index f8292b37..00000000
--- a/Source/SPQueryControllerInitializer.m
+++ /dev/null
@@ -1,145 +0,0 @@
-//
-// SPQueryControllerInitializer.m
-// sequel-pro
-//
-// Created by Stuart Connolly (stuconnolly.com) on September 1, 2011.
-// Copyright (c) 2011 Stuart Connolly. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// More info at <https://github.com/sequelpro/sequelpro>
-
-#import "SPQueryControllerInitializer.h"
-
-static NSString *SPCompletionTokensFilename = @"CompletionTokens.plist";
-
-static NSString *SPCompletionTokensKeywordsKey = @"core_keywords";
-static NSString *SPCompletionTokensFunctionsKey = @"core_builtin_functions";
-static NSString *SPCompletionTokensSnippetsKey = @"function_argument_snippets";
-
-@interface SPQueryController ()
-
-- (void)_updateFilterState;
-
-@end
-
-@implementation SPQueryController (SPQueryControllerInitializer)
-
-/**
- * Set the window's auto save name and initialise display.
- */
-- (void)awakeFromNib
-{
-#ifndef SP_CODA /* init ivars */
- prefs = [NSUserDefaults standardUserDefaults];
-
- [self setWindowFrameAutosaveName:SPQueryConsoleWindowAutoSaveName];
-
- // Show/hide table columns
- [[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] setHidden:![prefs boolForKey:SPConsoleShowTimestamps]];
- [[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] setHidden:![prefs boolForKey:SPConsoleShowConnections]];
- [[consoleTableView tableColumnWithIdentifier:SPTableViewDatabaseColumnID] setHidden:![prefs boolForKey:SPConsoleShowDatabases]];
-
- showSelectStatementsAreDisabled = ![prefs boolForKey:SPConsoleShowSelectsAndShows];
- showHelpStatementsAreDisabled = ![prefs boolForKey:SPConsoleShowHelps];
-
- [self _updateFilterState];
-
- [loggingDisabledTextField setStringValue:([prefs boolForKey:SPConsoleEnableLogging]) ? @"" : NSLocalizedString(@"Query logging is currently disabled", @"query logging disabled label")];
-
- // Setup data formatter
- dateFormatter = [[NSDateFormatter alloc] init];
-
- [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
-
- [dateFormatter setDateStyle:NSDateFormatterNoStyle];
- [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
-
- // Set the process table view's vertical gridlines if required
- [consoleTableView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
-
- // Set the strutcture and index view's font
- BOOL useMonospacedFont = [prefs boolForKey:SPUseMonospacedFonts];
- CGFloat monospacedFontSize = [prefs floatForKey:SPMonospacedFontSize] > 0 ? [prefs floatForKey:SPMonospacedFontSize] : [NSFont smallSystemFontSize];
-
- for (NSTableColumn *column in [consoleTableView tableColumns])
- {
- [[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:monospacedFontSize] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
- }
-
- //allow drag-out copying of selected rows
- [consoleTableView setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
-#endif
-}
-
-/**
- * Loads the query controller's completion tokens data.
- */
-- (NSError *)loadCompletionLists
-{
- NSError *readError = nil;
- NSString *convError = nil;
- NSString *errorDescription = nil;
-
- NSPropertyListFormat format;
- NSData *completionTokensData = [NSData dataWithContentsOfFile:
- [NSBundle pathForResource:SPCompletionTokensFilename
- ofType:nil
- inDirectory:[[NSBundle mainBundle] bundlePath]]
- options:NSMappedRead error:&readError];
-
- NSDictionary *completionPlist = [NSDictionary dictionaryWithDictionary:
- [NSPropertyListSerialization propertyListFromData:completionTokensData
- mutabilityOption:NSPropertyListMutableContainersAndLeaves
- format:&format
- errorDescription:&convError]];
-
- if (completionPlist == nil || readError != nil || convError != nil) {
- errorDescription = [NSString stringWithFormat:@"Error reading '%@': %@, %@", SPCompletionTokensFilename, [readError localizedDescription], convError];
- }
- else {
- if ([completionPlist objectForKey:SPCompletionTokensKeywordsKey]) {
- completionKeywordList = [[NSArray arrayWithArray:[completionPlist objectForKey:SPCompletionTokensKeywordsKey]] retain];
- }
- else {
- errorDescription = [NSString stringWithFormat:@"No '%@' array found.", SPCompletionTokensKeywordsKey];
- }
-
- if ([completionPlist objectForKey:SPCompletionTokensFunctionsKey]) {
- completionFunctionList = [[NSArray arrayWithArray:[completionPlist objectForKey:SPCompletionTokensFunctionsKey]] retain];
- }
- else {
- errorDescription = [NSString stringWithFormat:@"No '%@' array found.", SPCompletionTokensFunctionsKey];
- }
-
- if ([completionPlist objectForKey:SPCompletionTokensSnippetsKey]) {
- functionArgumentSnippets = [[NSDictionary dictionaryWithDictionary:[completionPlist objectForKey:SPCompletionTokensSnippetsKey]] retain];
- }
- else {
- errorDescription = [NSString stringWithFormat:@"No '%@' dictionary found.", SPCompletionTokensSnippetsKey];
- }
- }
-
- return errorDescription ? [NSError errorWithDomain:NSCocoaErrorDomain code:1 userInfo:@{NSLocalizedDescriptionKey : errorDescription}] : nil;
-}
-
-@end
diff --git a/Source/SPQueryDocumentsController.h b/Source/SPQueryDocumentsController.h
deleted file mode 100644
index a57eff2e..00000000
--- a/Source/SPQueryDocumentsController.h
+++ /dev/null
@@ -1,61 +0,0 @@
-//
-// SPQueryDocumentsController.h
-// sequel-pro
-//
-// Created by Stuart Connolly (stuconnolly.com) on August 30, 2011.
-// Copyright (c) 2011 Stuart Connolly. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// More info at <https://github.com/sequelpro/sequelpro>
-
-#import "SPQueryController.h"
-
-@interface SPQueryController (SPQueryDocumentsController)
-
-- (NSURL *)registerDocumentWithFileURL:(NSURL *)fileURL andContextInfo:(NSMutableDictionary *)contextInfo;
-- (void)removeRegisteredDocumentWithFileURL:(NSURL *)fileURL;
-
-- (void)addFavorite:(NSDictionary *)favorite forFileURL:(NSURL *)fileURL;
-- (void)replaceFavoritesByArray:(NSArray *)favoritesArray forFileURL:(NSURL *)fileURL;
-- (void)removeFavoriteAtIndex:(NSUInteger)index forFileURL:(NSURL *)fileURL;
-- (void)insertFavorite:(NSDictionary *)favorite atIndex:(NSUInteger)index forFileURL:(NSURL *)fileURL;
-
-- (void)addHistory:(NSString *)history forFileURL:(NSURL *)fileURL;
-- (void)replaceHistoryByArray:(NSArray *)historyArray forFileURL:(NSURL *)fileURL;
-
-- (void)replaceContentFilterByArray:(NSArray *)contentFilterArray ofType:(NSString *)filterType forFileURL:(NSURL *)fileURL;
-
-- (NSMutableArray *)favoritesForFileURL:(NSURL *)fileURL;
-- (NSMutableArray *)historyForFileURL:(NSURL *)fileURL;
-- (NSArray *)historyMenuItemsForFileURL:(NSURL *)fileURL;
-- (NSUInteger)numberOfHistoryItemsForFileURL:(NSURL *)fileURL;
-- (NSMutableDictionary *)contentFilterForFileURL:(NSURL *)fileURL;
-
-- (NSArray *)queryFavoritesForFileURL:(NSURL *)fileURL andTabTrigger:(NSString *)tabTrigger includeGlobals:(BOOL)includeGlobals;
-
-// Completion list controller
-- (NSArray*)functionList;
-- (NSArray*)keywordList;
-- (NSString*)argumentSnippetForFunction:(NSString*)func;
-
-@end
diff --git a/Source/SPQueryDocumentsController.m b/Source/SPQueryDocumentsController.m
deleted file mode 100644
index e4689c41..00000000
--- a/Source/SPQueryDocumentsController.m
+++ /dev/null
@@ -1,414 +0,0 @@
-//
-// SPQueryDocumentsController.m
-// sequel-pro
-//
-// Created by Stuart Connolly (stuconnolly.com) on August 30, 2011.
-// Copyright (c) 2011 Stuart Connolly. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// More info at <https://github.com/sequelpro/sequelpro>
-
-#import "SPQueryDocumentsController.h"
-#import "SPCustomQuery.h"
-#import "SPAppController.h"
-
-@implementation SPQueryController (SPQueryDocumentsController)
-
-- (NSURL *)registerDocumentWithFileURL:(NSURL *)fileURL andContextInfo:(NSMutableDictionary *)contextInfo
-{
-#ifndef SP_CODA
- // Register a new untiled document and return its URL
- if (fileURL == nil) {
- NSURL *new = [NSURL URLWithString:[[NSString stringWithFormat:NSLocalizedString(@"Untitled %ld",@"Title of a new Sequel Pro Document"), (unsigned long)untitledDocumentCounter] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
- untitledDocumentCounter++;
-
- if (![favoritesContainer objectForKey:[new absoluteString]]) {
- NSMutableArray *arr = [[NSMutableArray alloc] init];
- [favoritesContainer setObject:arr forKey:[new absoluteString]];
- [arr release];
- }
-
- // Set the global history coming from the Prefs as default if available
- if (![historyContainer objectForKey:[new absoluteString]]) {
- if ([prefs objectForKey:SPQueryHistory]) {
- NSMutableArray *arr = [[NSMutableArray alloc] init];
- [arr addObjectsFromArray:[prefs objectForKey:SPQueryHistory]];
- [historyContainer setObject:arr forKey:[new absoluteString]];
- [arr release];
- }
- else {
- NSMutableArray *arr = [[NSMutableArray alloc] init];
- [historyContainer setObject:[NSMutableArray array] forKey:[new absoluteString]];
- [arr release];
- }
- }
-
- // Set the doc-based content filters
- if (![contentFilterContainer objectForKey:[new absoluteString]]) {
- [contentFilterContainer setObject:[NSMutableDictionary dictionary] forKey:[new absoluteString]];
- }
-
- return new;
- }
-
- // Register a spf file to manage all query favorites and query history items
- // file path based (incl. Untitled docs) in a dictionary whereby the key represents the file URL as string.
- if (![favoritesContainer objectForKey:[fileURL absoluteString]]) {
- if (contextInfo != nil && [contextInfo objectForKey:SPQueryFavorites] && [[contextInfo objectForKey:SPQueryFavorites] count]) {
- NSMutableArray *arr = [[NSMutableArray alloc] init];
- [arr addObjectsFromArray:[contextInfo objectForKey:SPQueryFavorites]];
- [favoritesContainer setObject:arr forKey:[fileURL absoluteString]];
- [arr release];
- }
- else {
- NSMutableArray *arr = [[NSMutableArray alloc] init];
- [favoritesContainer setObject:arr forKey:[fileURL absoluteString]];
- [arr release];
- }
- }
-
- if (![historyContainer objectForKey:[fileURL absoluteString]]) {
- if (contextInfo != nil && [contextInfo objectForKey:SPQueryHistory] && [[contextInfo objectForKey:SPQueryHistory] count]) {
- NSMutableArray *arr = [[NSMutableArray alloc] init];
- [arr addObjectsFromArray:[contextInfo objectForKey:SPQueryHistory]];
- [historyContainer setObject:arr forKey:[fileURL absoluteString]];
- [arr release];
- }
- else {
- NSMutableArray *arr = [[NSMutableArray alloc] init];
- [historyContainer setObject:arr forKey:[fileURL absoluteString]];
- [arr release];
- }
- }
-
- if (![contentFilterContainer objectForKey:[fileURL absoluteString]]) {
- if (contextInfo != nil && [contextInfo objectForKey:SPContentFilters]) {
- [contentFilterContainer setObject:[contextInfo objectForKey:SPContentFilters] forKey:[fileURL absoluteString]];
- }
- else {
- NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
- [contentFilterContainer setObject:dict forKey:[fileURL absoluteString]];
- [dict release];
- }
- }
-
- return fileURL;
-#else
- return nil;
-#endif
-}
-
-- (void)removeRegisteredDocumentWithFileURL:(NSURL *)fileURL
-{
-#ifndef SP_CODA
- // Check for multiple instance of the same document.
- // Remove it if only one instance was registerd.
- NSArray *allDocs = [SPAppDelegate orderedDocuments];
- NSMutableArray *allURLs = [NSMutableArray array];
-
- for (id doc in allDocs)
- {
- if (![doc fileURL]) continue;
-
- if ([allURLs containsObject:[doc fileURL]]) {
- return;
- }
- else {
- [allURLs addObject:[doc fileURL]];
- }
- }
-
- if ([favoritesContainer objectForKey:[fileURL absoluteString]]) {
- [favoritesContainer removeObjectForKey:[fileURL absoluteString]];
- }
-
- if ([historyContainer objectForKey:[fileURL absoluteString]]) {
- [historyContainer removeObjectForKey:[fileURL absoluteString]];
- }
-
- if ([contentFilterContainer objectForKey:[fileURL absoluteString]]) {
- [contentFilterContainer removeObjectForKey:[fileURL absoluteString]];
- }
-#endif
-}
-
-- (void)replaceContentFilterByArray:(NSArray *)contentFilterArray ofType:(NSString *)filterType forFileURL:(NSURL *)fileURL
-{
-#ifndef SP_CODA
- if ([contentFilterContainer objectForKey:[fileURL absoluteString]]) {
- NSMutableDictionary *c = [[NSMutableDictionary alloc] init];
- [c setDictionary:[contentFilterContainer objectForKey:[fileURL absoluteString]]];
- [c setObject:contentFilterArray forKey:filterType];
- [contentFilterContainer setObject:c forKey:[fileURL absoluteString]];
- [c release];
- }
-#endif
-}
-
-- (void)replaceFavoritesByArray:(NSArray *)favoritesArray forFileURL:(NSURL *)fileURL
-{
-#ifndef SP_CODA
- if ([favoritesContainer objectForKey:[fileURL absoluteString]]) {
- [favoritesContainer setObject:favoritesArray forKey:[fileURL absoluteString]];
- }
-#endif
-}
-
-/**
- * Remove a Query Favorite the passed file URL
- *
- * @param index The index of the to be removed favorite
- *
- * @param fileURL The NSURL of the current active SPDatabaseDocument
- */
-- (void)removeFavoriteAtIndex:(NSUInteger)index forFileURL:(NSURL *)fileURL
-{
-#ifndef SP_CODA
- [[favoritesContainer objectForKey:[fileURL absoluteString]] removeObjectAtIndex:index];
-#endif
-}
-
-- (void)insertFavorite:(NSDictionary *)favorite atIndex:(NSUInteger)index forFileURL:(NSURL *)fileURL
-{
-#ifndef SP_CODA
- [[favoritesContainer objectForKey:[fileURL absoluteString]] insertObject:favorite atIndex:index];
-#endif
-}
-
-- (void)replaceHistoryByArray:(NSArray *)historyArray forFileURL:(NSURL *)fileURL
-{
-#ifndef SP_CODA
- if ([historyContainer objectForKey:[fileURL absoluteString]]) {
- [historyContainer setObject:historyArray forKey:[fileURL absoluteString]];
- }
-
- // Inform all opened documents to update the history list
- for (id doc in [SPAppDelegate orderedDocuments])
- {
- if([[doc valueForKeyPath:@"customQueryInstance"] respondsToSelector:@selector(historyItemsHaveBeenUpdated:)]) {
- [[doc valueForKeyPath:@"customQueryInstance"] performSelectorOnMainThread:@selector(historyItemsHaveBeenUpdated:) withObject:self waitUntilDone:NO];
- }
- }
-
- // User did choose to clear the global history list
- if (![fileURL isFileURL] && ![historyArray count]) {
- [prefs setObject:historyArray forKey:SPQueryHistory];
- }
-#endif
-}
-
-- (void)addFavorite:(NSDictionary *)favorite forFileURL:(NSURL *)fileURL
-{
-#ifndef SP_CODA
- if ([favoritesContainer objectForKey:[fileURL absoluteString]]) {
- [[favoritesContainer objectForKey:[fileURL absoluteString]] addObject:favorite];
- }
-#endif
-}
-
-- (void)addHistory:(NSString *)history forFileURL:(NSURL *)fileURL
-{
-#ifndef SP_CODA
- NSUInteger maxHistoryItems = [[prefs objectForKey:SPCustomQueryMaxHistoryItems] integerValue];
-
- // Save each history item due to its document source
- if ([historyContainer objectForKey:[fileURL absoluteString]]) {
-
- // Remove all duplicates by using a NSPopUpButton
- NSPopUpButton *uniquifier = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0,0,0,0) pullsDown:YES];
-
- [uniquifier addItemsWithTitles:[historyContainer objectForKey:[fileURL absoluteString]]];
- [uniquifier insertItemWithTitle:history atIndex:0];
-
- while ((NSUInteger)[uniquifier numberOfItems] > maxHistoryItems)
- {
- [uniquifier removeItemAtIndex:[uniquifier numberOfItems]-1];
- }
-
- [self replaceHistoryByArray:[uniquifier itemTitles] forFileURL:fileURL];
- [uniquifier release];
- }
-
- // Save history items coming from each Untitled document in the global Preferences successively
- // regardingless of the source document.
- if (![fileURL isFileURL]) {
-
- // Remove all duplicates by using a NSPopUpButton
- NSPopUpButton *uniquifier = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0,0,0,0) pullsDown:YES];
- [uniquifier addItemsWithTitles:[prefs objectForKey:SPQueryHistory]];
- [uniquifier insertItemWithTitle:history atIndex:0];
-
- while ((NSUInteger)[uniquifier numberOfItems] > maxHistoryItems)
- {
- [uniquifier removeItemAtIndex:[uniquifier numberOfItems] - 1];
- }
-
- [prefs setObject:[uniquifier itemTitles] forKey:SPQueryHistory];
- [uniquifier release];
- }
-#endif
-}
-
-- (NSMutableArray *)favoritesForFileURL:(NSURL *)fileURL
-{
-#ifndef SP_CODA
- if ([favoritesContainer objectForKey:[fileURL absoluteString]]) {
- return [favoritesContainer objectForKey:[fileURL absoluteString]];
- }
-#endif
-
- return [NSMutableArray array];
-}
-
-- (NSMutableArray *)historyForFileURL:(NSURL *)fileURL
-{
-#ifndef SP_CODA
- if ([historyContainer objectForKey:[fileURL absoluteString]]) {
- return [historyContainer objectForKey:[fileURL absoluteString]];
- }
-#endif
-
- return [NSMutableArray array];
-}
-
-- (NSArray *)historyMenuItemsForFileURL:(NSURL *)fileURL
-{
-#ifndef SP_CODA
- if ([historyContainer objectForKey:[fileURL absoluteString]]) {
- NSMutableArray *returnArray = [NSMutableArray arrayWithCapacity:[[historyContainer objectForKey:[fileURL absoluteString]] count]];
- NSMenuItem *historyMenuItem;
-
- for (NSString* history in [historyContainer objectForKey:[fileURL absoluteString]])
- {
- historyMenuItem = [[[NSMenuItem alloc] initWithTitle:([history length] > 64) ? [NSString stringWithFormat:@"%@…", [history substringToIndex:63]] : history
- action:NULL
- keyEquivalent:@""] autorelease];
-
- [historyMenuItem setToolTip:([history length] > 256) ? [NSString stringWithFormat:@"%@…", [history substringToIndex:255]] : history];
- [returnArray addObject:historyMenuItem];
- }
-
- return returnArray;
- }
-#endif
-
- return @[];
-}
-
-/**
- * Return the number of history items for the passed file URL
- *
- * @param fileURL The NSURL of the current active SPDatabaseDocument
- *
- */
-- (NSUInteger)numberOfHistoryItemsForFileURL:(NSURL *)fileURL
-{
-#ifndef SP_CODA
- if ([historyContainer objectForKey:[fileURL absoluteString]]) {
- return [[historyContainer objectForKey:[fileURL absoluteString]] count];
- }
- else {
- return 0;
- }
-#endif
-
- return 0;
-}
-
-/**
- * Return a mutable dictionary of all content filters for the passed file URL.
- * If no content filters were found it returns an empty mutable dictionary.
- *
- * @param fileURL The NSURL of the current active SPDatabaseDocument
- *
- */
-- (NSMutableDictionary *)contentFilterForFileURL:(NSURL *)fileURL
-{
-#ifndef SP_CODA
- if ([contentFilterContainer objectForKey:[fileURL absoluteString]]) {
- return [contentFilterContainer objectForKey:[fileURL absoluteString]];
- }
-#endif
-
- return [NSMutableDictionary dictionary];
-}
-
-- (NSArray *)queryFavoritesForFileURL:(NSURL *)fileURL andTabTrigger:(NSString *)tabTrigger includeGlobals:(BOOL)includeGlobals
-{
- if (![tabTrigger length]) return @[];
-
- NSMutableArray *result = [[NSMutableArray alloc] init];
-
- for (id fav in [self favoritesForFileURL:fileURL])
- {
- if ([fav objectForKey:@"tabtrigger"] && [[fav objectForKey:@"tabtrigger"] isEqualToString:tabTrigger]) {
- [result addObject:fav];
- }
- }
-
-#ifndef SP_CODA
- if (includeGlobals && [prefs objectForKey:SPQueryFavorites]) {
-
- for (id fav in [prefs objectForKey:SPQueryFavorites])
- {
- if ([fav objectForKey:@"tabtrigger"] && [[fav objectForKey:@"tabtrigger"] isEqualToString:tabTrigger]) {
- [result addObject:fav];
- break;
- }
- }
- }
-#endif
-
- return [result autorelease];
-}
-
-#pragma mark -
-#pragma mark Completion list controller
-
-/**
- * Return an array of all pre-defined SQL functions for completion.
- */
-- (NSArray*)functionList
-{
- return (completionFunctionList != nil && [completionFunctionList count]) ? completionFunctionList : @[];
-}
-
-/**
- * Return an array of all pre-defined SQL keywords for completion.
- */
-- (NSArray*)keywordList
-{
- return (completionKeywordList != nil && [completionKeywordList count]) ? completionKeywordList : @[];
-}
-
-/**
- * Return the parameter list as snippet of the passed SQL functions for completion.
- *
- * @param func The name of the function whose parameter list is asked for
- */
-- (NSString*)argumentSnippetForFunction:(NSString*)func
-{
- return (functionArgumentSnippets && [functionArgumentSnippets objectForKey:[func uppercaseString]]) ? [functionArgumentSnippets objectForKey:[func uppercaseString]] : @"";
-}
-
-@end
diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m
index 36e5dd26..e987986b 100644
--- a/Source/SPQueryFavoriteManager.m
+++ b/Source/SPQueryFavoriteManager.m
@@ -32,7 +32,6 @@
#import "ImageAndTextCell.h"
#import "SPEncodingPopupAccessory.h"
#import "SPQueryController.h"
-#import "SPQueryDocumentsController.h"
#import "SPDatabaseDocument.h"
#import "SPConnectionController.h"
#import "RegexKitLite.h"
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index 87e996c7..aa614b76 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -39,7 +39,6 @@
#import "SPDataCellFormatter.h"
#import "SPTableData.h"
#import "SPQueryController.h"
-#import "SPQueryDocumentsController.h"
#import "SPTextAndLinkCell.h"
#ifndef SP_CODA
#import "SPSplitView.h"
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index 7056befd..f06bbaef 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -33,7 +33,6 @@
#import "SPDatabaseDocument.h"
#import "SPNarrowDownCompletion.h"
#import "SPQueryController.h"
-#import "SPQueryDocumentsController.h"
#import "SPTooltip.h"
#import "SPTablesList.h"
#import "SPNavigatorController.h"