From a35bbeac66279cd42230e301332dee1c26ae4be2 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sat, 22 Aug 2009 10:54:17 +0000 Subject: =?UTF-8?q?=E2=80=A2=20further=20improvements=20for=20open/save=20?= =?UTF-8?q?SQL/SPF=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/EncodingPopupView.xib | 325 +++++++++++++++++++++++++ Source/SPAppController.h | 1 + Source/SPAppController.m | 43 +++- Source/TableDocument.h | 1 + Source/TableDocument.m | 57 +++-- sequel-pro.xcodeproj/project.pbxproj | 12 + 6 files changed, 414 insertions(+), 25 deletions(-) create mode 100644 Interfaces/English.lproj/EncodingPopupView.xib diff --git a/Interfaces/English.lproj/EncodingPopupView.xib b/Interfaces/English.lproj/EncodingPopupView.xib new file mode 100644 index 00000000..b7265b31 --- /dev/null +++ b/Interfaces/English.lproj/EncodingPopupView.xib @@ -0,0 +1,325 @@ + + + + 1050 + 9L30 + 677 + 949.54 + 353.00 + + YES + + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + YES + + YES + + + YES + + + + YES + + NSObject + + + FirstResponder + + + NSApplication + + + + 268 + + YES + + + 268 + {{6, 10}, {180, 14}} + + YES + + 68288064 + 272761856 + File Encoding: + + LucidaGrande + 1.100000e+01 + 3100 + + + + 6 + System + controlColor + + 3 + MC42NjY2NjY2OQA + + + + 6 + System + controlTextColor + + 3 + MAA + + + + + + + 268 + {{84, 5}, {180, 22}} + + YES + + -1539178944 + 133120 + + + 109199615 + 129 + + + 400 + 75 + + + Item 1 + + 1048576 + 2147483647 + 1 + + NSImage + NSMenuCheckmark + + + NSImage + NSMenuMixedState + + _popUpItemAction: + + + YES + + OtherViews + + YES + + + + Item 2 + + 1048576 + 2147483647 + + + _popUpItemAction: + 1 + + + + + Item 3 + + 1048576 + 2147483647 + + + _popUpItemAction: + 2 + + + + + 1 + YES + YES + 2 + + + + {271, 34} + + NSView + + + + + YES + + + + YES + + 0 + + YES + + + + + + -2 + + + RmlsZSdzIE93bmVyA + + + -1 + + + First Responder + + + -3 + + + Application + + + 1 + + + YES + + + + + Encoding Accessory + + + 2 + + + YES + + + + + + 3 + + + YES + + + + + + 4 + + + + + 5 + + + YES + + + + + + 6 + + + YES + + + + + + + + 7 + + + + + 8 + + + + + 9 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + 1.IBEditorWindowLastContentRect + 1.IBPluginDependency + 2.IBPluginDependency + 3.IBPluginDependency + 4.IBPluginDependency + 5.IBPluginDependency + 6.IBEditorWindowLastContentRect + 6.IBPluginDependency + 7.IBPluginDependency + 8.IBPluginDependency + 9.IBPluginDependency + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{293, 417}, {271, 34}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{769, 837}, {180, 54}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + YES + + YES + + + YES + + + + + YES + + YES + + + YES + + + + 9 + + + 0 + + 3 + + diff --git a/Source/SPAppController.h b/Source/SPAppController.h index af4a2df4..d328d353 100644 --- a/Source/SPAppController.h +++ b/Source/SPAppController.h @@ -36,6 +36,7 @@ // IBAction methods - (IBAction)openPreferences:(id)sender; +- (IBAction)openConnectionSheet:(id)sender; // Services menu methods - (void)doPerformQueryService:(NSPasteboard *)pboard userData:(NSString *)data error:(NSString **)error; diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 9b0bce1d..2dba0c68 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -47,6 +47,33 @@ return self; } +- (IBAction)openConnectionSheet:(id)sender +{ + NSOpenPanel *panel = [NSOpenPanel openPanel]; + [panel setCanSelectHiddenExtension:YES]; + [panel setDelegate:self]; + [panel setCanChooseDirectories:NO]; + [panel setAllowsMultipleSelection:YES]; + [panel setResolvesAliases:YES]; + // [panel setAccessoryView:encodingAccessoryView]; + + // Set up encoding list + // [encodingPopUp setEnabled:NO]; + + // If no lastSqlFileEncoding in prefs set it to UTF-8 + if(![[NSUserDefaults standardUserDefaults] integerForKey:@"lastSqlFileEncoding"]) { + [[NSUserDefaults standardUserDefaults] setInteger:4 forKey:@"lastSqlFileEncoding"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + } + + // [self setupPopUp:encodingPopUp selectedEncoding:[prefs integerForKey:@"lastSqlFileEncoding"] withDefaultEntry:NO]; + int returnCode = [panel runModalForDirectory:nil file:nil types:[NSArray arrayWithObjects:@"spf", @"sql", nil]]; + + if( returnCode ) + [self application:nil openFiles:[panel filenames]]; + +} + /** * Called if user drag and drops files on Sequel Pro's dock item or double-clicked * at files *.spf or *.sql @@ -61,8 +88,7 @@ // Check if at least one document exists if (![[[NSDocumentController sharedDocumentController] documents] count]) { - // TODO : maybe open a connection first - // return; + TableDocument *firstTableDocument; // Manually open a new document, setting SPAppController as sender to trigger autoconnection @@ -82,7 +108,18 @@ } else if([[[filename pathExtension] lowercaseString] isEqualToString:@"spf"]) { - NSLog(@"open connection %@", filename); + + TableDocument *newTableDocument; + + // Manually open a new document, setting SPAppController as sender to trigger autoconnection + if (newTableDocument = [[NSDocumentController sharedDocumentController] makeUntitledDocumentOfType:@"DocumentType" error:nil]) { + [newTableDocument setShouldAutomaticallyConnect:NO]; + [[NSDocumentController sharedDocumentController] addDocument:newTableDocument]; + [newTableDocument makeWindowControllers]; + [newTableDocument showWindows]; + [newTableDocument initWithConnectionFile:filename]; + } + } else { NSLog(@"Only files with the extensions ‘spf’ or ‘sql’ are allowed."); diff --git a/Source/TableDocument.h b/Source/TableDocument.h index 9b1a053f..22c836db 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -129,6 +129,7 @@ enum { - (IBAction)showUserManager:(id)sender; - (void)initQueryEditorWithString:(NSString *)query; +- (void)initWithConnectionFile:(NSString *)path; // Connection callback and methods - (void) setConnection:(MCPConnection *)theConnection; - (void)setShouldAutomaticallyConnect:(BOOL)shouldAutomaticallyConnect; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 86763614..70d4089f 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -161,6 +161,32 @@ } } +- (void)initWithConnectionFile:(NSString *)path +{ + + NSError *readError = nil; + NSString *convError = nil; + NSPropertyListFormat format; + NSData *pData = [[NSData dataWithContentsOfFile:path options:NSUncachedRead error:&readError] decompress]; + NSDictionary *spfData = [NSPropertyListSerialization propertyListFromData:pData + mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError]; + + if(!spfData || readError != nil || [convError length] | format != NSPropertyListBinaryFormat_v1_0) { + NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")] + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:NSLocalizedString(@"Connection data file couldn't be read.", @"error while reading connection data file")]; + + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; + return; + } + + NSLog(@"s: %@", [spfData description]); + +} + #pragma mark - #pragma mark Connection callback and methods @@ -1713,29 +1739,16 @@ break; // open only the first SQL file } else if([[[filename pathExtension] lowercaseString] isEqualToString:@"spf"]) { - - - NSError *readError = nil; - NSString *convError = nil; - NSPropertyListFormat format; - NSData *pData = [[NSData dataWithContentsOfFile:filename options:NSUncachedRead error:&readError] decompress]; - NSDictionary *spfData = [NSPropertyListSerialization propertyListFromData:pData - mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError]; - - if(!spfData || readError != nil || [convError length] | format != NSPropertyListBinaryFormat_v1_0) { - NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")] - defaultButton:NSLocalizedString(@"OK", @"OK button") - alternateButton:nil - otherButton:nil - informativeTextWithFormat:NSLocalizedString(@"Connection data file couldn't be read.", @"error while reading connection data file")]; - - [alert setAlertStyle:NSCriticalAlertStyle]; - [alert runModal]; - return; + TableDocument *newTableDocument; + + // Manually open a new document, setting SPAppController as sender to trigger autoconnection + if (newTableDocument = [[NSDocumentController sharedDocumentController] makeUntitledDocumentOfType:@"DocumentType" error:nil]) { + [newTableDocument setShouldAutomaticallyConnect:NO]; + [[NSDocumentController sharedDocumentController] addDocument:newTableDocument]; + [newTableDocument makeWindowControllers]; + [newTableDocument showWindows]; + [newTableDocument initWithConnectionFile:filename]; } - - NSLog(@"s: %@", [spfData description]); - } else { NSLog(@"Only files with the extensions ‘spf’ or ‘sql’ are allowed."); diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index cbbea8bc..c3752b27 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -220,6 +220,7 @@ BC2C16D40FEBEDF10003993B /* SPDataAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = BC2C16D30FEBEDF10003993B /* SPDataAdditions.m */; }; BC2C8E220FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html in Resources */ = {isa = PBXBuildFile; fileRef = BC2C8E210FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html */; }; BC688D811012462600D35128 /* borderlessbackground.png in Resources */ = {isa = PBXBuildFile; fileRef = BC688D801012462600D35128 /* borderlessbackground.png */; }; + BC8B0DAF104004F900FC02EC /* EncodingPopupView.xib in Resources */ = {isa = PBXBuildFile; fileRef = BC8B0DAD104004F900FC02EC /* EncodingPopupView.xib */; }; BC8C8532100E0A8000D7A129 /* SPTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = BC8C8531100E0A8000D7A129 /* SPTableView.m */; }; BC9F0881100FCF2C00A80D32 /* SPFieldEditorController.m in Sources */ = {isa = PBXBuildFile; fileRef = BC9F0880100FCF2C00A80D32 /* SPFieldEditorController.m */; }; BCA6271C1031B9D40047E5D5 /* SPTooltip.m in Sources */ = {isa = PBXBuildFile; fileRef = BCA6271B1031B9D40047E5D5 /* SPTooltip.m */; }; @@ -593,6 +594,7 @@ BC2C16D30FEBEDF10003993B /* SPDataAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPDataAdditions.m; sourceTree = ""; }; BC2C8E210FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "sequel-pro-mysql-help-template.html"; sourceTree = ""; }; BC688D801012462600D35128 /* borderlessbackground.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = borderlessbackground.png; sourceTree = ""; }; + BC8B0DAE104004F900FC02EC /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/EncodingPopupView.xib; sourceTree = ""; }; BC8C8530100E0A8000D7A129 /* SPTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableView.h; sourceTree = ""; }; BC8C8531100E0A8000D7A129 /* SPTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableView.m; sourceTree = ""; }; BC9F087F100FCF2C00A80D32 /* SPFieldEditorController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPFieldEditorController.h; sourceTree = ""; }; @@ -1105,6 +1107,7 @@ 17E642050EF020A3001BC333 /* Interfaces */ = { isa = PBXGroup; children = ( + BC8B0DAD104004F900FC02EC /* EncodingPopupView.xib */, 4D90B7A0101E0D1500D116A1 /* UserManagerView.xib */, B52460D90F8EF93B00171639 /* Console.xib */, BCA6F62F100FA7D700E80253 /* FieldEditorSheet.xib */, @@ -1503,6 +1506,7 @@ 581068B61015411B0068C6E2 /* link-arrow-highlighted.png in Resources */, 581069B410167EC10068C6E2 /* SequelProTunnelAssistant in Resources */, 4D90B7A2101E0D1500D116A1 /* UserManagerView.xib in Resources */, + BC8B0DAF104004F900FC02EC /* EncodingPopupView.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1782,6 +1786,14 @@ name = ExportDialog.xib; sourceTree = ""; }; + BC8B0DAD104004F900FC02EC /* EncodingPopupView.xib */ = { + isa = PBXVariantGroup; + children = ( + BC8B0DAE104004F900FC02EC /* English */, + ); + name = EncodingPopupView.xib; + sourceTree = ""; + }; BCA6F62F100FA7D700E80253 /* FieldEditorSheet.xib */ = { isa = PBXVariantGroup; children = ( -- cgit v1.2.3