From ed4617c7fc292ac15a3cb340b2247d58793d3ca4 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 5 Aug 2009 21:14:15 +0000 Subject: =?UTF-8?q?=E2=80=A2=20open=20a=20SQL=20file=20via=20Finder=20or?= =?UTF-8?q?=20Terminal=20(open=20*.sql=20if=20SP=20is=20the=20default=20ap?= =?UTF-8?q?p=20for=20sql=20files)=20will=20insert=20the=20file=20content?= =?UTF-8?q?=20into=20the=20Custom=20Query=20editor=20of=20the=20current=20?= =?UTF-8?q?active=20doc=20-=20this=20action=20starts=20SP=20and=20asks=20f?= =?UTF-8?q?or=20a=20connection=20if=20it=20is=20not=20running=20-=20same?= =?UTF-8?q?=20for=20drag&drop=20a=20SQL=20file=20onto=20SP's=20dock=20icon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/MainController.m | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'Source/MainController.m') 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"]) { -- cgit v1.2.3