diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-08-05 21:14:15 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-08-05 21:14:15 +0000 |
commit | ed4617c7fc292ac15a3cb340b2247d58793d3ca4 (patch) | |
tree | cc32cc3a93ed8a8001945d85d9242aa6a8d42682 /Source | |
parent | 493fb09f6169864726be9909907fa1b84b3d0a21 (diff) | |
download | sequelpro-ed4617c7fc292ac15a3cb340b2247d58793d3ca4.tar.gz sequelpro-ed4617c7fc292ac15a3cb340b2247d58793d3ca4.tar.bz2 sequelpro-ed4617c7fc292ac15a3cb340b2247d58793d3ca4.zip |
• open a SQL file via Finder or Terminal (open *.sql if SP is the default app for sql files) will insert the file content into the Custom Query editor of the current active doc
- this action starts SP and asks for a connection if it is not running
- same for drag&drop a SQL file onto SP's dock icon
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CustomQuery.h | 1 | ||||
-rw-r--r-- | Source/CustomQuery.m | 5 | ||||
-rw-r--r-- | Source/MainController.m | 20 | ||||
-rw-r--r-- | Source/TableDocument.h | 5 | ||||
-rw-r--r-- | Source/TableDocument.m | 28 |
5 files changed, 54 insertions, 5 deletions
diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index c88cc879..c5cb2a30 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -151,6 +151,7 @@ - (void)setConnection:(MCPConnection *)theConnection; - (void)setFavorites; - (void)doPerformQueryService:(NSString *)query; +- (void)doPerformLoadQueryService:(NSString *)query; - (void)selectCurrentQuery; - (void)commentOut; - (void)commentOutCurrentQueryTakingSelection:(BOOL)takeSelection; diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index d6194484..5f8c368a 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -1201,6 +1201,11 @@ [textView setString:query]; [self runAllQueries:self]; } +- (void)doPerformLoadQueryService:(NSString *)query +{ + [textView setString:query]; + [textView insertText:@""]; +} - (NSString *)usedQuery { diff --git a/Source/MainController.m b/Source/MainController.m index 4e1119a6..17aa2652 100644 --- a/Source/MainController.m +++ b/Source/MainController.m @@ -56,17 +56,27 @@ for( NSString* filename in filenames ) { - // Opens a sql file and insert its content to the Custom Query editor + // Opens a sql file and insert its content into the Custom Query editor if([[[filename pathExtension] lowercaseString] isEqualToString:@"sql"]) { // Check if at least one document exists if (![[[NSDocumentController sharedDocumentController] documents] count]) { // TODO : maybe open a connection first - return; - } + // return; + TableDocument *firstTableDocument; + + // Manually open a new document, setting MainController as sender to trigger autoconnection + if (firstTableDocument = [[NSDocumentController sharedDocumentController] makeUntitledDocumentOfType:@"DocumentType" error:nil]) { + [firstTableDocument setShouldAutomaticallyConnect:NO]; + [firstTableDocument initQueryEditorWithString:[self contentOfFile:filename]]; + [[NSDocumentController sharedDocumentController] addDocument:firstTableDocument]; + [firstTableDocument makeWindowControllers]; + [firstTableDocument showWindows]; + } + } else - // Pass query to last created document - [[[[NSDocumentController sharedDocumentController] documents] objectAtIndex:([[[NSDocumentController sharedDocumentController] documents] count] - 1)] doPerformQueryService:[self contentOfFile:filename]]; + // Pass query to the Query editor of the current document + [[[NSDocumentController sharedDocumentController] currentDocument] doPerformLoadQueryService:[self contentOfFile:filename]]; } else if([[[filename pathExtension] lowercaseString] isEqualToString:@"spf"]) { diff --git a/Source/TableDocument.h b/Source/TableDocument.h index c9510a33..4cf4e369 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -111,10 +111,14 @@ WebView *printWebView; NSMutableArray *allDatabases; + + NSString *queryEditorInitString; } - (NSString *)getHTMLforPrint; +- (void)initQueryEditorWithString:(NSString *)query; + // Connection callback and methods - (void) setConnection:(MCPConnection *)theConnection; - (void)setShouldAutomaticallyConnect:(BOOL)shouldAutomaticallyConnect; @@ -157,6 +161,7 @@ - (IBAction)closeSheet:(id)sender; - (IBAction)closeErrorConnectionSheet:(id)sender; - (void)doPerformQueryService:(NSString *)query; +- (void)doPerformLoadQueryService:(NSString *)query; - (void)flushPrivileges:(id)sender; - (void)showVariables:(id)sender; - (void)closeConnection; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 68b79a1a..668f6b46 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -79,6 +79,7 @@ [printWebView setFrameLoadDelegate:self]; prefs = [NSUserDefaults standardUserDefaults]; + queryEditorInitString = nil; } @@ -203,6 +204,14 @@ [[SPGrowlController sharedGrowlController] notifyWithTitle:@"Connected" description:[NSString stringWithFormat:NSLocalizedString(@"Connected to %@",@"description for connected growl notification"), [tableWindow title]] notificationName:@"Connected"]; + + // Insert queryEditorInitString into the Query Editor if defined + if(queryEditorInitString && [queryEditorInitString length]) { + [self viewQuery:self]; + [customQueryInstance doPerformLoadQueryService:queryEditorInitString]; + [queryEditorInitString release]; + queryEditorInitString = nil; + } } @@ -1276,6 +1285,16 @@ #pragma mark Other Methods /** + * Set that query which will be inserted into the Query Editor + * after establishing the connection + */ + +- (void)initQueryEditorWithString:(NSString *)query +{ + queryEditorInitString = [query retain]; +} + +/** * Invoked when user hits the cancel button or close button in * dialogs such as the variableSheet or the createTableSyntaxSheet */ @@ -1302,6 +1321,15 @@ } /** + * Inserts query into the Custom Query editor + */ +- (void)doPerformLoadQueryService:(NSString *)query +{ + [self viewQuery:nil]; + [customQueryInstance doPerformLoadQueryService:query]; +} + +/** * Flushes the mysql privileges */ - (void)flushPrivileges:(id)sender |