aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-08-06 14:01:30 +0000
committerBibiko <bibiko@eva.mpg.de>2009-08-06 14:01:30 +0000
commit494b4df263e7c73bd7696f54264cdf953c1f6158 (patch)
treee402e0d2f93f7e833b9d2ec659fec18736d8a438
parent7b840caf675ece703faf5a16749b47d1b023bdcd (diff)
downloadsequelpro-494b4df263e7c73bd7696f54264cdf953c1f6158.tar.gz
sequelpro-494b4df263e7c73bd7696f54264cdf953c1f6158.tar.bz2
sequelpro-494b4df263e7c73bd7696f54264cdf953c1f6158.zip
• enabled "Open" menu item to open SQL files
- lastSqlFileEncoding will be stored in the Preference.plist - to open SPF files not yet supported
-rw-r--r--Interfaces/English.lproj/MainMenu.xib15
-rw-r--r--Resources/PreferenceDefaults.plist2
-rw-r--r--Source/MainController.m10
-rw-r--r--Source/TableDocument.h3
-rw-r--r--Source/TableDocument.m145
5 files changed, 114 insertions, 61 deletions
diff --git a/Interfaces/English.lproj/MainMenu.xib b/Interfaces/English.lproj/MainMenu.xib
index c19968a2..750018c4 100644
--- a/Interfaces/English.lproj/MainMenu.xib
+++ b/Interfaces/English.lproj/MainMenu.xib
@@ -2,9 +2,9 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03">
<data>
<int key="IBDocument.SystemTarget">1050</int>
- <string key="IBDocument.SystemVersion">9J61</string>
+ <string key="IBDocument.SystemVersion">9L30</string>
<string key="IBDocument.InterfaceBuilderVersion">677</string>
- <string key="IBDocument.AppKitVersion">949.46</string>
+ <string key="IBDocument.AppKitVersion">949.54</string>
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -241,7 +241,6 @@
</object>
<object class="NSMenuItem" id="849728981">
<reference key="NSMenu" ref="709725194"/>
- <bool key="NSIsHidden">YES</bool>
<string key="NSTitle">Open</string>
<string key="NSKeyEquiv">o</string>
<int key="NSKeyEquivModMask">1048576</int>
@@ -252,7 +251,7 @@
<object class="NSMenuItem" id="256715652">
<reference key="NSMenu" ref="709725194"/>
<bool key="NSIsHidden">YES</bool>
- <string key="NSTitle">Save Connection</string>
+ <string key="NSTitle">Save</string>
<string key="NSKeyEquiv">s</string>
<int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
@@ -4178,7 +4177,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{449, 1007}, {197, 53}}</string>
- <string>{{164, 719}, {511, 20}}</string>
+ <string>{{311, 851}, {511, 20}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{506, 836}, {511, 20}}</string>
@@ -4249,7 +4248,7 @@
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
- <string>{{701, 502}, {218, 253}}</string>
+ <string>{{176, 466}, {218, 253}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{518, 583}, {218, 253}}</string>
@@ -4271,7 +4270,7 @@
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
- <string>{{1022, 54}, {279, 423}}</string>
+ <string>{{660, 216}, {279, 423}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{556, 185}, {279, 383}}</string>
@@ -4355,7 +4354,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{270, 486}, {209, 233}}</string>
+ <string>{{417, 618}, {209, 233}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{180, 535}, {182, 253}}</string>
diff --git a/Resources/PreferenceDefaults.plist b/Resources/PreferenceDefaults.plist
index 644a6db1..72e975b3 100644
--- a/Resources/PreferenceDefaults.plist
+++ b/Resources/PreferenceDefaults.plist
@@ -72,6 +72,8 @@
<false/>
<key>CustomQueryAutoHelpDelay</key>
<real>1</real>
+ <key>lastSqlFileEncoding</key>
+ <integer>4</integer>
<key>SelectLastFavoriteUsed</key>
<true/>
<key>LastFavoriteIndex</key>
diff --git a/Source/MainController.m b/Source/MainController.m
index 1cdc0244..3f297574 100644
--- a/Source/MainController.m
+++ b/Source/MainController.m
@@ -73,11 +73,11 @@
[firstTableDocument makeWindowControllers];
[firstTableDocument showWindows];
}
- } else
-
- // Pass query to the Query editor of the current document
- [[[NSDocumentController sharedDocumentController] currentDocument] doPerformLoadQueryService:[self contentOfFile:filename]];
-
+ } else {
+ // Pass query to the Query editor of the current document
+ [[[NSDocumentController sharedDocumentController] currentDocument] doPerformLoadQueryService:[self contentOfFile:filename]];
+ }
+
break; // open only the first SQL file
}
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index a89a4a69..7df1155d 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -121,8 +121,7 @@ enum {
NSMutableArray *allDatabases;
NSString *queryEditorInitString;
-
- NSArray *encodings;
+
}
- (NSString *)getHTMLforPrint;
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 3faa9f94..851fc746 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -1550,32 +1550,19 @@
kCFStringEncodingEUC_KR,
-1
};
- if (encodings == nil) {
- NSMutableArray *encs = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"Encodings"] mutableCopy];
- if (encs == nil) {
- NSStringEncoding defaultEncoding = [NSString defaultCStringEncoding];
- NSStringEncoding encoding;
- BOOL hasDefault = NO;
- NSInteger cnt = 0;
- encs = [[NSMutableArray alloc] init];
- while (plainTextFileStringEncodingsSupported[cnt] != -1) {
- if ((encoding = CFStringConvertEncodingToNSStringEncoding(plainTextFileStringEncodingsSupported[cnt++])) != kCFStringEncodingInvalidId) {
- [encs addObject:[NSNumber numberWithUnsignedInteger:encoding]];
- if (encoding == defaultEncoding) hasDefault = YES;
- }
- }
- if (!hasDefault) [encs addObject:[NSNumber numberWithUnsignedInteger:defaultEncoding]];
- }
- encodings = encs;
- }
- return encodings;
+ NSStringEncoding encoding;
+ NSInteger cnt = 0;
+ NSMutableArray *encs = [NSMutableArray array];
+ while (plainTextFileStringEncodingsSupported[cnt] != -1)
+ if ((encoding = CFStringConvertEncodingToNSStringEncoding(plainTextFileStringEncodingsSupported[cnt++])) != kCFStringEncodingInvalidId)
+ [encs addObject:[NSNumber numberWithUnsignedInteger:encoding]];
+
+ return encs;
}
/**
* This method initializes the provided popup with list of encodings;
- * it also sets up the selected encoding as indicated and if includeDefaultItem is YES,
- * includes an initial item for selecting "Automatic" choice.
- * These non-encoding items all have NoStringEncoding as their tags.
+ * it also sets up the selected encoding as indicated and if includeDefaultItem is YES.
* Otherwise the tags are set to the NSStringEncoding value for the encoding.
*/
- (void)setupPopUp:(NSPopUpButton *)popup selectedEncoding:(NSUInteger)selectedEncoding withDefaultEntry:(BOOL)includeDefaultItem
@@ -1586,12 +1573,6 @@
// Put the encodings in the popup
[popup removeAllItems];
- // Put the initial "Automatic" item, if desired
- if (includeDefaultItem) {
- [popup addItemWithTitle:NSLocalizedString(@"Automatic", @"Encoding popup entry indicating automatic choice of encoding")];
- [[popup itemAtIndex:0] setTag:NoStringEncoding];
- }
-
// Make sure the initial selected encoding appears in the list
if (!includeDefaultItem && (selectedEncoding != NoStringEncoding) && ![encs containsObject:[NSNumber numberWithUnsignedInteger:selectedEncoding]]) encs = [encs arrayByAddingObject:[NSNumber numberWithUnsignedInteger:selectedEncoding]];
@@ -1606,22 +1587,12 @@
if (enc == selectedEncoding) itemToSelect = [popup numberOfItems] - 1;
}
- // Add an optional separator and "customize" item at end
- // if ([popup numberOfItems] > 0) {
- // [[popup menu] addItem:[NSMenuItem separatorItem]];
- // [[popup lastItem] setTag:NoStringEncoding];
- // }
- // [popup addItemWithTitle:NSLocalizedString(@"Customize Encodings List\\U2026", @"Encoding popup entry for bringing up the Customize Encodings List panel (this also occurs as the title of the panel itself, they should have the same localization)")];
- // [[popup lastItem] setAction:@selector(showPanel:)];
- // [[popup lastItem] setTarget:self];
- // [[popup lastItem] setTag:NoStringEncoding];
-
[popup selectItemAtIndex:itemToSelect];
}
/**
- * Opens connection file(s)
+ * Opens SP session file(s) or a SQL file
*/
- (IBAction)openConnectionSheet:(id)sender
{
@@ -1635,9 +1606,15 @@
[panel setAccessoryView:encodingAccessoryView];
// Set up encoding list
- // TODO save last used enc in prefs
[encodingPopUp setEnabled:NO];
- [self setupPopUp:encodingPopUp selectedEncoding:4 withDefaultEntry:NO];
+
+ // If no lastSqlFileEncoding in prefs set it to UTF-8
+ if(![prefs integerForKey:@"lastSqlFileEncoding"]) {
+ [prefs setInteger:4 forKey:@"lastSqlFileEncoding"];
+ [prefs synchronize];
+ }
+
+ [self setupPopUp:encodingPopUp selectedEncoding:[prefs integerForKey:@"lastSqlFileEncoding"] withDefaultEntry:NO];
[panel beginSheetForDirectory:nil
file:@""
@@ -1650,8 +1627,53 @@
- (void)openConnectionPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
if ( returnCode ) {
- NSArray *fileName = [panel filenames];
- NSLog(@"open: '%@' %d", [fileName description], [[encodingPopUp selectedItem] tag]);
+ NSArray *fileNames = [panel filenames];
+ NSString *filename;
+
+ for(filename in fileNames) {
+ if([[[filename pathExtension] lowercaseString] isEqualToString:@"sql"]) {
+
+ NSError *err;
+ NSString *content = [NSString stringWithContentsOfFile:filename encoding:[[encodingPopUp selectedItem] tag] error:&err];
+
+ // If file couldn't read show an alert and return
+ if(!content) {
+ NSAlert *errorAlert = [NSAlert alertWithError:err];
+ [errorAlert runModal];
+ return;
+ }
+
+ // Save last used encoding
+ [prefs setInteger:[[encodingPopUp selectedItem] tag] forKey:@"lastSqlFileEncoding"];
+
+ // 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 MainController as sender to trigger autoconnection
+ if (firstTableDocument = [[NSDocumentController sharedDocumentController] makeUntitledDocumentOfType:@"DocumentType" error:nil]) {
+ [firstTableDocument setShouldAutomaticallyConnect:NO];
+ [firstTableDocument initQueryEditorWithString:content];
+ [[NSDocumentController sharedDocumentController] addDocument:firstTableDocument];
+ [firstTableDocument makeWindowControllers];
+ [firstTableDocument showWindows];
+ }
+ } else {
+ // Pass query to the Query editor of the current document
+ [[[NSDocumentController sharedDocumentController] currentDocument] doPerformLoadQueryService:content];
+ }
+
+ break; // open only the first SQL file
+ }
+ else if([[[filename pathExtension] lowercaseString] isEqualToString:@"spf"]) {
+ NSLog(@"open connection %@", filename);
+ }
+ else {
+ NSLog(@"Only files with the extensions ‘spf’ or ‘sql’ are allowed.");
+ }
+ }
}
}
@@ -1674,18 +1696,46 @@
}
/**
- * Saves connection(s) to file
+ * Saves SP session or if Custom Query tab is active the editor's content as SQL file
*/
- (IBAction)saveConnectionSheet:(id)sender
{
NSSavePanel *panel = [NSSavePanel savePanel];
- [panel setAllowedFileTypes:[NSArray arrayWithObjects:@"spf", nil]];
+ NSString *filename;
+
[panel setAllowsOtherFileTypes:NO];
[panel setCanSelectHiddenExtension:YES];
+ if( [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 2 ) {
+
+ // Custom Query tab is active thus save the editor's content as SQL file
+ [panel setAccessoryView:encodingAccessoryView];
+ [panel setMessage:NSLocalizedString(@"Save SQL file", @"Save SQL file")];
+ [panel setAllowedFileTypes:[NSArray arrayWithObjects:@"sql", nil]];
+ filename = [NSString stringWithString:@""];
+
+ // If no lastSqlFileEncoding in prefs set it to UTF-8
+ if(![prefs integerForKey:@"lastSqlFileEncoding"]) {
+ [prefs setInteger:4 forKey:@"lastSqlFileEncoding"];
+ [prefs synchronize];
+ }
+
+ // Set up encoding list
+ [encodingPopUp setEnabled:YES];
+ [self setupPopUp:encodingPopUp selectedEncoding:[prefs integerForKey:@"lastSqlFileEncoding"] withDefaultEntry:NO];
+
+ } else {
+
+ // Save current session (open connection windows as SPF file)
+ [panel setMessage:NSLocalizedString(@"Save Sequel Pro session", @"Save Sequel Pro session")];
+ [panel setAllowedFileTypes:[NSArray arrayWithObjects:@"spf", nil]];
+ filename = [NSString stringWithFormat:@"%@", [self name]];
+
+ }
+
[panel beginSheetForDirectory:nil
- file:[NSString stringWithFormat:@"%@", [self name]]
+ file:filename
modalForWindow:tableWindow
modalDelegate:self
didEndSelector:@selector(saveConnectionPanelDidEnd:returnCode:contextInfo:)
@@ -1697,6 +1747,9 @@
if ( returnCode ) {
NSString *fileName = [panel filename];
NSLog(@"save as: '%@'", fileName);
+
+ [prefs setInteger:[[encodingPopUp selectedItem] tag] forKey:@"lastSqlFileEncoding"];
+
}
}
/**