aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-08-22 13:26:08 +0000
committerBibiko <bibiko@eva.mpg.de>2009-08-22 13:26:08 +0000
commit54ed811d6071cc843a9d2699d3ca972af9ca4c5d (patch)
tree345fa444b320f56af35ab4a0f734ec1dd8e53eef
parenta35bbeac66279cd42230e301332dee1c26ae4be2 (diff)
downloadsequelpro-54ed811d6071cc843a9d2699d3ca972af9ca4c5d.tar.gz
sequelpro-54ed811d6071cc843a9d2699d3ca972af9ca4c5d.tar.bz2
sequelpro-54ed811d6071cc843a9d2699d3ca972af9ca4c5d.zip
• outsourced SPEncodingPopupAccessory
- added SPEncodingPopupAccessory class and nib - it returns an accessory view containing a popup menu with predefined encodings - removed that view from DBView
-rw-r--r--Interfaces/English.lproj/DBView.xib227
-rw-r--r--Interfaces/English.lproj/EncodingPopupView.xib46
-rw-r--r--Source/SPAppController.h2
-rw-r--r--Source/SPAppController.m50
-rw-r--r--Source/SPEncodingPopupAccessory.h41
-rw-r--r--Source/SPEncodingPopupAccessory.m118
-rw-r--r--Source/TableDocument.h4
-rw-r--r--Source/TableDocument.m87
-rw-r--r--sequel-pro.xcodeproj/project.pbxproj6
9 files changed, 268 insertions, 313 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib
index 38e8b39d..cea60e1f 100644
--- a/Interfaces/English.lproj/DBView.xib
+++ b/Interfaces/English.lproj/DBView.xib
@@ -8,7 +8,6 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="6305"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -47,7 +46,7 @@
<string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string>
<string key="NSWindowContentMinSize">{780, 480}</string>
<object class="NSView" key="NSWindowView" id="579726586">
- <reference key="NSNextResponder"/>
+ <nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -186,7 +185,6 @@
</object>
<string key="NSFrameSize">{212, 26}</string>
<reference key="NSSuperview" ref="199860064"/>
- <reference key="NSNextKeyView" ref="643201879"/>
<reference key="NSDocView" ref="643201879"/>
<object class="NSColor" key="NSBGColor" id="529261656">
<int key="NSColorSpace">6</int>
@@ -222,7 +220,6 @@
</object>
<string key="NSFrameSize">{212, 26}</string>
<reference key="NSSuperview" ref="801427893"/>
- <reference key="NSNextKeyView" ref="588922296"/>
<int key="NSsFlags">0</int>
<reference key="NSVScroller" ref="540853896"/>
<reference key="NSHScroller" ref="566705316"/>
@@ -337,7 +334,6 @@
</object>
<string key="NSFrameSize">{212, 354}</string>
<reference key="NSSuperview" ref="233472824"/>
- <reference key="NSNextKeyView" ref="251040077"/>
<reference key="NSDocView" ref="251040077"/>
<object class="NSColor" key="NSBGColor" id="1024678221">
<int key="NSColorSpace">6</int>
@@ -369,7 +365,6 @@
</object>
<string key="NSFrameSize">{212, 354}</string>
<reference key="NSSuperview" ref="1017775084"/>
- <reference key="NSNextKeyView" ref="73685676"/>
<int key="NSsFlags">528</int>
<reference key="NSVScroller" ref="693168867"/>
<reference key="NSHScroller" ref="656188692"/>
@@ -494,7 +489,6 @@
</object>
<string key="NSFrameSize">{212, 145}</string>
<reference key="NSSuperview" ref="298226231"/>
- <reference key="NSNextKeyView" ref="347093764"/>
<reference key="NSDocView" ref="347093764"/>
<reference key="NSBGColor" ref="1024678221"/>
<int key="NScvFlags">6</int>
@@ -521,7 +515,6 @@
</object>
<string key="NSFrameSize">{212, 145}</string>
<reference key="NSSuperview" ref="192579410"/>
- <reference key="NSNextKeyView" ref="685057119"/>
<int key="NSsFlags">512</int>
<reference key="NSVScroller" ref="245346414"/>
<reference key="NSHScroller" ref="353686052"/>
@@ -2128,7 +2121,6 @@
</object>
<string key="NSFrame">{{1, 17}, {688, 455}}</string>
<reference key="NSSuperview" ref="33038697"/>
- <reference key="NSNextKeyView" ref="22576329"/>
<reference key="NSDocView" ref="22576329"/>
<reference key="NSBGColor" ref="1024678221"/>
<int key="NScvFlags">2</int>
@@ -2162,7 +2154,6 @@
</object>
<string key="NSFrame">{{1, 0}, {688, 17}}</string>
<reference key="NSSuperview" ref="33038697"/>
- <reference key="NSNextKeyView" ref="457166030"/>
<reference key="NSDocView" ref="457166030"/>
<reference key="NSBGColor" ref="1024678221"/>
<int key="NScvFlags">4</int>
@@ -2171,7 +2162,6 @@
</object>
<string key="NSFrame">{{6, 32}, {690, 473}}</string>
<reference key="NSSuperview" ref="1013108064"/>
- <reference key="NSNextKeyView" ref="545438501"/>
<int key="NSsFlags">562</int>
<reference key="NSVScroller" ref="398797698"/>
<reference key="NSHScroller" ref="178353583"/>
@@ -2242,8 +2232,8 @@
<bool key="NS.raise.underflow">YES</bool>
<bool key="NS.raise.dividebyzero">YES</bool>
</object>
- <string key="NS.decimal">.</string>
- <string key="NS.thousand">,</string>
+ <string key="NS.decimal">,</string>
+ <string key="NS.thousand">.</string>
<bool key="NS.hasthousands">NO</bool>
<bool key="NS.localized">YES</bool>
<bool key="NS.allowsfloats">NO</bool>
@@ -3238,7 +3228,7 @@
<reference key="NSControlView" ref="363916571"/>
<int key="NSButtonFlags">-2042609409</int>
<int key="NSButtonFlags2">35</int>
- <object class="NSCustomResource" key="NSNormalImage">
+ <object class="NSCustomResource" key="NSNormalImage" id="607934853">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">button_action</string>
</object>
@@ -3253,10 +3243,7 @@
<string key="NSKeyEquiv"/>
<int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
- <object class="NSCustomResource" key="NSImage">
- <string key="NSClassName">NSImage</string>
- <string key="NSResourceName">button_action</string>
- </object>
+ <reference key="NSImage" ref="607934853"/>
<string key="NSAction">_popUpItemAction:</string>
<reference key="NSTarget" ref="984501775"/>
</object>
@@ -4690,7 +4677,6 @@
</object>
</object>
<string key="NSFrameSize">{944, 550}</string>
- <reference key="NSSuperview"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1920, 1178}}</string>
<string key="NSMinSize">{780, 502}</string>
@@ -11296,98 +11282,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string key="NSFrameSize">{269, 32}</string>
<string key="NSClassName">NSView</string>
</object>
- <object class="NSCustomView" id="1012120233">
- <nil key="NSNextResponder"/>
- <int key="NSvFlags">268</int>
- <object class="NSMutableArray" key="NSSubviews">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSTextField" id="561637557">
- <reference key="NSNextResponder" ref="1012120233"/>
- <int key="NSvFlags">268</int>
- <string key="NSFrame">{{6, 10}, {180, 14}}</string>
- <reference key="NSSuperview" ref="1012120233"/>
- <bool key="NSEnabled">YES</bool>
- <object class="NSTextFieldCell" key="NSCell" id="176323924">
- <int key="NSCellFlags">68288064</int>
- <int key="NSCellFlags2">272761856</int>
- <string key="NSContents">File Encoding:</string>
- <reference key="NSSupport" ref="26"/>
- <reference key="NSControlView" ref="561637557"/>
- <reference key="NSBackgroundColor" ref="62854682"/>
- <reference key="NSTextColor" ref="454249633"/>
- </object>
- </object>
- <object class="NSPopUpButton" id="262386526">
- <reference key="NSNextResponder" ref="1012120233"/>
- <int key="NSvFlags">268</int>
- <string key="NSFrame">{{84, 5}, {180, 22}}</string>
- <reference key="NSSuperview" ref="1012120233"/>
- <bool key="NSEnabled">YES</bool>
- <object class="NSPopUpButtonCell" key="NSCell" id="169419191">
- <int key="NSCellFlags">-1539178944</int>
- <int key="NSCellFlags2">133120</int>
- <reference key="NSSupport" ref="26"/>
- <reference key="NSControlView" ref="262386526"/>
- <int key="NSButtonFlags">109199615</int>
- <int key="NSButtonFlags2">129</int>
- <string key="NSAlternateContents"/>
- <string key="NSKeyEquivalent"/>
- <int key="NSPeriodicDelay">400</int>
- <int key="NSPeriodicInterval">75</int>
- <object class="NSMenuItem" key="NSMenuItem" id="704879172">
- <reference key="NSMenu" ref="597592082"/>
- <string key="NSTitle">Item 1</string>
- <string key="NSKeyEquiv"/>
- <int key="NSKeyEquivModMask">1048576</int>
- <int key="NSMnemonicLoc">2147483647</int>
- <int key="NSState">1</int>
- <reference key="NSOnImage" ref="450876295"/>
- <reference key="NSMixedImage" ref="414351669"/>
- <string key="NSAction">_popUpItemAction:</string>
- <reference key="NSTarget" ref="169419191"/>
- </object>
- <bool key="NSMenuItemRespectAlignment">YES</bool>
- <object class="NSMenu" key="NSMenu" id="597592082">
- <string key="NSTitle">OtherViews</string>
- <object class="NSMutableArray" key="NSMenuItems">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="704879172"/>
- <object class="NSMenuItem" id="498019985">
- <reference key="NSMenu" ref="597592082"/>
- <string key="NSTitle">Item 2</string>
- <string key="NSKeyEquiv"/>
- <int key="NSKeyEquivModMask">1048576</int>
- <int key="NSMnemonicLoc">2147483647</int>
- <reference key="NSOnImage" ref="450876295"/>
- <reference key="NSMixedImage" ref="414351669"/>
- <string key="NSAction">_popUpItemAction:</string>
- <int key="NSTag">1</int>
- <reference key="NSTarget" ref="169419191"/>
- </object>
- <object class="NSMenuItem" id="384926559">
- <reference key="NSMenu" ref="597592082"/>
- <string key="NSTitle">Item 3</string>
- <string key="NSKeyEquiv"/>
- <int key="NSKeyEquivModMask">1048576</int>
- <int key="NSMnemonicLoc">2147483647</int>
- <reference key="NSOnImage" ref="450876295"/>
- <reference key="NSMixedImage" ref="414351669"/>
- <string key="NSAction">_popUpItemAction:</string>
- <int key="NSTag">2</int>
- <reference key="NSTarget" ref="169419191"/>
- </object>
- </object>
- </object>
- <int key="NSPreferredEdge">1</int>
- <bool key="NSUsesItemFromMenu">YES</bool>
- <bool key="NSAltersState">YES</bool>
- <int key="NSArrowPosition">2</int>
- </object>
- </object>
- </object>
- <string key="NSFrameSize">{271, 34}</string>
- <string key="NSClassName">NSView</string>
- </object>
<object class="NSCustomView" id="730777562">
<nil key="NSNextResponder"/>
<int key="NSvFlags">265</int>
@@ -15037,22 +14931,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<int key="connectionID">6323</int>
</object>
<object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
- <string key="label">encodingAccessoryView</string>
- <reference key="source" ref="427689665"/>
- <reference key="destination" ref="1012120233"/>
- </object>
- <int key="connectionID">6331</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
- <string key="label">encodingPopUp</string>
- <reference key="source" ref="427689665"/>
- <reference key="destination" ref="262386526"/>
- </object>
- <int key="connectionID">6338</int>
- </object>
- <object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">copy:</string>
<reference key="source" ref="22576329"/>
@@ -21206,75 +21084,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<reference key="parent" ref="168035361"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">6325</int>
- <reference key="object" ref="1012120233"/>
- <object class="NSMutableArray" key="children">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="561637557"/>
- <reference ref="262386526"/>
- </object>
- <reference key="parent" ref="1043842561"/>
- <string key="objectName">Encoding Accessory</string>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">6328</int>
- <reference key="object" ref="561637557"/>
- <object class="NSMutableArray" key="children">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="176323924"/>
- </object>
- <reference key="parent" ref="1012120233"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">6329</int>
- <reference key="object" ref="176323924"/>
- <reference key="parent" ref="561637557"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">6332</int>
- <reference key="object" ref="262386526"/>
- <object class="NSMutableArray" key="children">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="169419191"/>
- </object>
- <reference key="parent" ref="1012120233"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">6333</int>
- <reference key="object" ref="169419191"/>
- <object class="NSMutableArray" key="children">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="597592082"/>
- </object>
- <reference key="parent" ref="262386526"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">6334</int>
- <reference key="object" ref="597592082"/>
- <object class="NSMutableArray" key="children">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="704879172"/>
- <reference ref="498019985"/>
- <reference ref="384926559"/>
- </object>
- <reference key="parent" ref="169419191"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">6335</int>
- <reference key="object" ref="704879172"/>
- <reference key="parent" ref="597592082"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">6336</int>
- <reference key="object" ref="498019985"/>
- <reference key="parent" ref="597592082"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">6337</int>
- <reference key="object" ref="384926559"/>
- <reference key="parent" ref="597592082"/>
- </object>
- <object class="IBObjectRecord">
<int key="objectID">6340</int>
<reference key="object" ref="870308047"/>
<reference key="parent" ref="481018596"/>
@@ -22618,17 +22427,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>6305.IBPluginDependency</string>
<string>6317.IBPluginDependency</string>
<string>6318.IBPluginDependency</string>
- <string>6325.IBEditorWindowLastContentRect</string>
- <string>6325.IBPluginDependency</string>
- <string>6328.IBPluginDependency</string>
- <string>6329.IBPluginDependency</string>
- <string>6332.IBPluginDependency</string>
- <string>6333.IBPluginDependency</string>
- <string>6334.IBEditorWindowLastContentRect</string>
- <string>6334.IBPluginDependency</string>
- <string>6335.IBPluginDependency</string>
- <string>6336.IBPluginDependency</string>
- <string>6337.IBPluginDependency</string>
<string>6340.IBPluginDependency</string>
<string>6341.IBPluginDependency</string>
<string>6343.IBPluginDependency</string>
@@ -23677,9 +23475,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{280, 178}, {944, 550}}</string>
+ <string>{{78, 178}, {944, 550}}</string>
<boolean value="NO"/>
- <string>{{280, 178}, {944, 550}}</string>
+ <string>{{78, 178}, {944, 550}}</string>
<reference ref="9"/>
<reference ref="9"/>
<string>{{62, 352}, {845, 504}}</string>
@@ -24436,17 +24234,6 @@ aGUgYWN0aXZlIHNlbGVjdGlvbiAo4oyl4oyYUik</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{736, 891}, {271, 34}}</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{769, 837}, {180, 54}}</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
diff --git a/Interfaces/English.lproj/EncodingPopupView.xib b/Interfaces/English.lproj/EncodingPopupView.xib
index b7265b31..4effe3f9 100644
--- a/Interfaces/English.lproj/EncodingPopupView.xib
+++ b/Interfaces/English.lproj/EncodingPopupView.xib
@@ -26,7 +26,7 @@
<object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSCustomObject" id="1001">
- <string key="NSClassName">NSObject</string>
+ <string key="NSClassName">SPEncodingPopupAccessory</string>
</object>
<object class="NSCustomObject" id="1003">
<string key="NSClassName">FirstResponder</string>
@@ -157,6 +157,22 @@
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">encodingPopUp</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="1054695"/>
+ </object>
+ <int key="connectionID">10</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">encodingAccessoryView</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="894430783"/>
+ </object>
+ <int key="connectionID">11</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -315,9 +331,33 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">9</int>
+ <int key="maxID">11</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <object class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBPartialClassDescription">
+ <string key="className">SPEncodingPopupAccessory</string>
+ <object class="NSMutableDictionary" key="outlets">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>encodingAccessoryView</string>
+ <string>encodingPopUp</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>id</string>
+ <string>id</string>
+ </object>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBUserSource</string>
+ <string key="minorKey"/>
+ </object>
+ </object>
+ </object>
</object>
- <object class="IBClassDescriber" key="IBDocument.Classes"/>
<int key="IBDocument.localizationMode">0</int>
<nil key="IBDocument.LastKnownRelativeProjectPath"/>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
diff --git a/Source/SPAppController.h b/Source/SPAppController.h
index d328d353..6a5f9b6a 100644
--- a/Source/SPAppController.h
+++ b/Source/SPAppController.h
@@ -32,6 +32,8 @@
BOOL isNewFavorite;
SPPreferenceController *prefsController;
+
+ id encodingPopUp;
}
// IBAction methods
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index 2dba0c68..97029a68 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -27,6 +27,7 @@
#import "SPAppController.h"
#import "TableDocument.h"
#import "SPPreferenceController.h"
+#import "SPEncodingPopupAccessory.h"
#import <Sparkle/Sparkle.h>
@@ -47,6 +48,23 @@
return self;
}
+
+- (void)panelSelectionDidChange:(id)sender
+{
+
+ if([sender isKindOfClass:[NSOpenPanel class]]) {
+ if([[[[sender filename] pathExtension] lowercaseString] isEqualToString:@"sql"]) {
+ [encodingPopUp setEnabled:YES];
+ [sender setAllowsMultipleSelection:NO];
+ } else {
+ [encodingPopUp setEnabled:NO];
+ [sender setAllowsMultipleSelection:YES];
+ }
+ }
+
+}
+
+
- (IBAction)openConnectionSheet:(id)sender
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
@@ -55,18 +73,21 @@
[panel setCanChooseDirectories:NO];
[panel setAllowsMultipleSelection:YES];
[panel setResolvesAliases:YES];
- // [panel setAccessoryView:encodingAccessoryView];
- // Set up encoding list
- // [encodingPopUp setEnabled:NO];
-
+ // // Set up encoding list
+
// 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];
+ [panel setAccessoryView:[SPEncodingPopupAccessory encodingAccessory:[[NSUserDefaults standardUserDefaults] integerForKey:@"lastSqlFileEncoding"]
+ includeDefaultEntry:NO encodingPopUp:&encodingPopUp]];
+
+ [encodingPopUp setEnabled:NO];
+
+ // [self setupPopUp:encodingPopUp selectedEncoding:[[NSUserDefaults standardUserDefaults] integerForKey:@"lastSqlFileEncoding"] withDefaultEntry:NO];
int returnCode = [panel runModalForDirectory:nil file:nil types:[NSArray arrayWithObjects:@"spf", @"sql", nil]];
if( returnCode )
@@ -86,6 +107,11 @@
// Opens a sql file and insert its content into the Custom Query editor
if([[[filename pathExtension] lowercaseString] isEqualToString:@"sql"]) {
+ // if encodingPopUp is defined the filename comes from an openPanel and
+ // the encodingPopUp contains the chosen encoding; otherwise autodetect encoding
+ if(encodingPopUp)
+ [[NSUserDefaults standardUserDefaults] setInteger:[[encodingPopUp selectedItem] tag] forKey:@"lastSqlFileEncoding"];
+
// Check if at least one document exists
if (![[[NSDocumentController sharedDocumentController] documents] count]) {
@@ -94,7 +120,19 @@
// Manually open a new document, setting SPAppController as sender to trigger autoconnection
if (firstTableDocument = [[NSDocumentController sharedDocumentController] makeUntitledDocumentOfType:@"DocumentType" error:nil]) {
[firstTableDocument setShouldAutomaticallyConnect:NO];
- [firstTableDocument initQueryEditorWithString:[self contentOfFile:filename]];
+ if(encodingPopUp) {
+ NSError *error = nil;
+ NSString *content = [NSString stringWithContentsOfFile:filename encoding:[[encodingPopUp selectedItem] tag] error:&error];
+ if(error != nil) {
+ NSAlert *errorAlert = [NSAlert alertWithError:error];
+ [errorAlert runModal];
+ return;
+ }
+ [firstTableDocument initQueryEditorWithString:content];
+
+ }
+ else
+ [firstTableDocument initQueryEditorWithString:[self contentOfFile:filename]];
[[NSDocumentController sharedDocumentController] addDocument:firstTableDocument];
[firstTableDocument makeWindowControllers];
[firstTableDocument showWindows];
diff --git a/Source/SPEncodingPopupAccessory.h b/Source/SPEncodingPopupAccessory.h
new file mode 100644
index 00000000..7f594095
--- /dev/null
+++ b/Source/SPEncodingPopupAccessory.h
@@ -0,0 +1,41 @@
+//
+// $Id$
+//
+// SPEncodingPopupAccessory.h
+// sequel-pro
+//
+// Created by Hans-Jörg Bibiko on August 22, 2009
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import <Cocoa/Cocoa.h>
+
+enum {
+ NoStringEncoding = 0xFFFFFFFF
+};
+
+@interface SPEncodingPopupAccessory : NSObject {
+@public
+ IBOutlet NSPopUpButton *encodingPopUp;
+ IBOutlet NSView *encodingAccessoryView;
+}
+
++ (NSArray *)enabledEncodings;
++ (NSView *)encodingAccessory:(NSUInteger)encoding includeDefaultEntry:(BOOL)includeDefaultItem encodingPopUp:(NSPopUpButton **)popup;
++ (void)setupPopUp:(NSPopUpButton *)popup selectedEncoding:(NSUInteger)selectedEncoding withDefaultEntry:(BOOL)includeDefaultItem;
+
+@end
diff --git a/Source/SPEncodingPopupAccessory.m b/Source/SPEncodingPopupAccessory.m
new file mode 100644
index 00000000..c5b30630
--- /dev/null
+++ b/Source/SPEncodingPopupAccessory.m
@@ -0,0 +1,118 @@
+//
+// $Id$
+//
+// SPEncodingPopupAccessory.m
+// sequel-pro
+//
+// Created by Hans-Jörg Bibiko on August 22, 2009
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import "SPEncodingPopupAccessory.h"
+
+
+@implementation SPEncodingPopupAccessory
+
++ (NSView *)encodingAccessory:(NSUInteger)encoding includeDefaultEntry:(BOOL)includeDefaultItem encodingPopUp:(NSPopUpButton **)popup {
+ SPEncodingPopupAccessory *owner = [[[SPEncodingPopupAccessory alloc] init] autorelease];
+ // Rather than caching, load the accessory view everytime, as it might appear in multiple panels simultaneously.
+ if (![NSBundle loadNibNamed:@"EncodingPopupView" owner:owner]) {
+ NSLog(@"Failed to load EncodingPopupView.nib");
+ return nil;
+ }
+ if (popup) *popup = owner->encodingPopUp;
+ [[self class] setupPopUp:owner->encodingPopUp selectedEncoding:encoding withDefaultEntry:includeDefaultItem];
+ return [owner->encodingAccessoryView autorelease];
+}
+
+/**
+ * Returns the actual enabled list of encodings for open/save SQL files.
+ */
++ (NSArray *)enabledEncodings
+{
+ static const NSInteger plainTextFileStringEncodingsSupported[] = {
+ kCFStringEncodingUTF8,
+ kCFStringEncodingUTF16,
+ kCFStringEncodingUTF16BE,
+ kCFStringEncodingUTF16LE,
+ kCFStringEncodingUTF32,
+ kCFStringEncodingWindowsLatin1,
+ kCFStringEncodingISOLatin1,
+ kCFStringEncodingWindowsLatin2,
+ kCFStringEncodingISOLatin2,
+ kCFStringEncodingISOLatin3,
+ kCFStringEncodingISOLatin4,
+ kCFStringEncodingWindowsLatin5,
+ kCFStringEncodingKOI8_R,
+ kCFStringEncodingKOI8_U,
+ kCFStringEncodingMacRoman,
+ kCFStringEncodingMacJapanese,
+ kCFStringEncodingShiftJIS,
+ kCFStringEncodingEUC_JP,
+ kCFStringEncodingISO_2022_JP,
+ kCFStringEncodingMacChineseTrad,
+ kCFStringEncodingMacChineseSimp,
+ kCFStringEncodingBig5,
+ kCFStringEncodingGB_18030_2000,
+ kCFStringEncodingEUC_CN,
+ kCFStringEncodingEUC_TW,
+ kCFStringEncodingMacKorean,
+ kCFStringEncodingEUC_KR,
+ -1
+ };
+ 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.
+ * Otherwise the tags are set to the NSStringEncoding value for the encoding.
+ */
++ (void)setupPopUp:(NSPopUpButton *)popup selectedEncoding:(NSUInteger)selectedEncoding withDefaultEntry:(BOOL)includeDefaultItem
+{
+ NSArray *encs = [self enabledEncodings];
+ NSUInteger cnt, numEncodings, itemToSelect = 0;
+
+ // Put the encodings in the popup
+ [popup removeAllItems];
+
+ // 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]];
+
+ numEncodings = [encs count];
+
+ // Fill with encodings
+ for (cnt = 0; cnt < numEncodings; cnt++) {
+ NSStringEncoding enc = [[encs objectAtIndex:cnt] unsignedIntegerValue];
+ [popup addItemWithTitle:[NSString localizedNameOfStringEncoding:enc]];
+ [[popup lastItem] setTag:enc];
+ [[popup lastItem] setEnabled:YES];
+ if (enc == selectedEncoding) itemToSelect = [popup numberOfItems] - 1;
+ }
+
+ [popup selectItemAtIndex:itemToSelect];
+}
+
+
+@end
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index 22c836db..6f36ea83 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -29,10 +29,6 @@
#import <MCPKit/MCPKit.h>
#import <WebKit/WebKit.h>
-enum {
- NoStringEncoding = 0xFFFFFFFF
-};
-
@class SPConnectionController, SPUserManager;
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 70d4089f..cd5967cb 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -49,6 +49,7 @@
#import "SPPrintAccessory.h"
#import "QLPreviewPanel.h"
#import "SPUserManager.h"
+#import "SPEncodingPopupAccessory.h"
// Used for printing
#import "MGTemplateEngine.h"
@@ -1587,82 +1588,6 @@
#pragma mark Menu methods
/**
- * Returns the actual enabled list of encodings for open/save SQL files.
- */
-- (NSArray *)enabledEncodings
-{
- static const NSInteger plainTextFileStringEncodingsSupported[] = {
- kCFStringEncodingUTF8,
- kCFStringEncodingUTF16,
- kCFStringEncodingUTF16BE,
- kCFStringEncodingUTF16LE,
- kCFStringEncodingUTF32,
- kCFStringEncodingWindowsLatin1,
- kCFStringEncodingISOLatin1,
- kCFStringEncodingWindowsLatin2,
- kCFStringEncodingISOLatin2,
- kCFStringEncodingISOLatin3,
- kCFStringEncodingISOLatin4,
- kCFStringEncodingWindowsLatin5,
- kCFStringEncodingKOI8_R,
- kCFStringEncodingKOI8_U,
- kCFStringEncodingMacRoman,
- kCFStringEncodingMacJapanese,
- kCFStringEncodingShiftJIS,
- kCFStringEncodingEUC_JP,
- kCFStringEncodingISO_2022_JP,
- kCFStringEncodingMacChineseTrad,
- kCFStringEncodingMacChineseSimp,
- kCFStringEncodingBig5,
- kCFStringEncodingGB_18030_2000,
- kCFStringEncodingEUC_CN,
- kCFStringEncodingEUC_TW,
- kCFStringEncodingMacKorean,
- kCFStringEncodingEUC_KR,
- -1
- };
- 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.
- * Otherwise the tags are set to the NSStringEncoding value for the encoding.
- */
-- (void)setupPopUp:(NSPopUpButton *)popup selectedEncoding:(NSUInteger)selectedEncoding withDefaultEntry:(BOOL)includeDefaultItem
-{
- NSArray *encs = [self enabledEncodings];
- NSUInteger cnt, numEncodings, itemToSelect = 0;
-
- // Put the encodings in the popup
- [popup removeAllItems];
-
- // 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]];
-
- numEncodings = [encs count];
-
- // Fill with encodings
- for (cnt = 0; cnt < numEncodings; cnt++) {
- NSStringEncoding enc = [[encs objectAtIndex:cnt] unsignedIntegerValue];
- [popup addItemWithTitle:[NSString localizedNameOfStringEncoding:enc]];
- [[popup lastItem] setTag:enc];
- [[popup lastItem] setEnabled:YES];
- if (enc == selectedEncoding) itemToSelect = [popup numberOfItems] - 1;
- }
-
- [popup selectItemAtIndex:itemToSelect];
-}
-
-
-/**
* Opens SP session file(s) or a SQL file
*/
- (IBAction)openConnectionSheet:(id)sender
@@ -1674,7 +1599,8 @@
[panel setCanChooseDirectories:NO];
[panel setAllowsMultipleSelection:YES];
[panel setResolvesAliases:YES];
- [panel setAccessoryView:encodingAccessoryView];
+ [panel setAccessoryView:[SPEncodingPopupAccessory encodingAccessory:[prefs integerForKey:@"lastSqlFileEncoding"]
+ includeDefaultEntry:NO encodingPopUp:&encodingPopUp]];
// Set up encoding list
[encodingPopUp setEnabled:NO];
@@ -1685,7 +1611,7 @@
[prefs synchronize];
}
- [self setupPopUp:encodingPopUp selectedEncoding:[prefs integerForKey:@"lastSqlFileEncoding"] withDefaultEntry:NO];
+ // [self setupPopUp:encodingPopUp selectedEncoding:[prefs integerForKey:@"lastSqlFileEncoding"] withDefaultEntry:NO];
[panel beginSheetForDirectory:nil
file:@""
@@ -1791,7 +1717,8 @@
if( [sender tag] == 0 ) {
// Save the editor's content as SQL file
- [panel setAccessoryView:encodingAccessoryView];
+ [panel setAccessoryView:[SPEncodingPopupAccessory encodingAccessory:[prefs integerForKey:@"lastSqlFileEncoding"]
+ includeDefaultEntry:NO encodingPopUp:&encodingPopUp]];
// [panel setMessage:NSLocalizedString(@"Save SQL file", @"Save SQL file")];
[panel setAllowedFileTypes:[NSArray arrayWithObjects:@"sql", nil]];
if(![prefs stringForKey:@"lastSqlFileName"]) {
@@ -1810,7 +1737,7 @@
// Set up encoding list
[encodingPopUp setEnabled:YES];
- [self setupPopUp:encodingPopUp selectedEncoding:[prefs integerForKey:@"lastSqlFileEncoding"] withDefaultEntry:NO];
+ // [self setupPopUp:encodingPopUp selectedEncoding:[prefs integerForKey:@"lastSqlFileEncoding"] withDefaultEntry:NO];
} else if([sender tag] == 1){
diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj
index c3752b27..c776e45b 100644
--- a/sequel-pro.xcodeproj/project.pbxproj
+++ b/sequel-pro.xcodeproj/project.pbxproj
@@ -214,6 +214,7 @@
B5E92F400F75B32100012500 /* toolbar-export-xml.tiff in Resources */ = {isa = PBXBuildFile; fileRef = B5E92F3A0F75B32100012500 /* toolbar-export-xml.tiff */; };
B5EAC0FD0EC87FF900CC579C /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5EAC0FC0EC87FF900CC579C /* Security.framework */; };
B5F4F7810F7BCF990059AE84 /* toolbar-switch-to-procedures.tiff in Resources */ = {isa = PBXBuildFile; fileRef = B5F4F7800F7BCF990059AE84 /* toolbar-switch-to-procedures.tiff */; };
+ BC01BCCF104024BE006BDEE7 /* SPEncodingPopupAccessory.m in Sources */ = {isa = PBXBuildFile; fileRef = BC01BCCE104024BE006BDEE7 /* SPEncodingPopupAccessory.m */; };
BC05F1C5101241DF008A97F8 /* AMIndeterminateProgressIndicatorCell.m in Sources */ = {isa = PBXBuildFile; fileRef = BC05F1C4101241DF008A97F8 /* AMIndeterminateProgressIndicatorCell.m */; };
BC1847EA0FE6EC8400094BFB /* SPEditSheetTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = BC1847E90FE6EC8400094BFB /* SPEditSheetTextView.m */; };
BC1E55C4100DC92200AAE9F0 /* table-view-small-square.tiff in Resources */ = {isa = PBXBuildFile; fileRef = BC1E55C3100DC92200AAE9F0 /* table-view-small-square.tiff */; };
@@ -585,6 +586,8 @@
B5E92F3A0F75B32100012500 /* toolbar-export-xml.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = "toolbar-export-xml.tiff"; sourceTree = "<group>"; };
B5EAC0FC0EC87FF900CC579C /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
B5F4F7800F7BCF990059AE84 /* toolbar-switch-to-procedures.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = "toolbar-switch-to-procedures.tiff"; sourceTree = "<group>"; };
+ BC01BCCD104024BE006BDEE7 /* SPEncodingPopupAccessory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPEncodingPopupAccessory.h; sourceTree = "<group>"; };
+ BC01BCCE104024BE006BDEE7 /* SPEncodingPopupAccessory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPEncodingPopupAccessory.m; sourceTree = "<group>"; };
BC05F1C3101241DF008A97F8 /* AMIndeterminateProgressIndicatorCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMIndeterminateProgressIndicatorCell.h; sourceTree = "<group>"; };
BC05F1C4101241DF008A97F8 /* AMIndeterminateProgressIndicatorCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMIndeterminateProgressIndicatorCell.m; sourceTree = "<group>"; };
BC1847E80FE6EC8400094BFB /* SPEditSheetTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPEditSheetTextView.h; sourceTree = "<group>"; };
@@ -930,6 +933,8 @@
17E641530EF01EF6001BC333 /* TableDump.m */,
17E641540EF01EF6001BC333 /* TableSource.h */,
17E641550EF01EF6001BC333 /* TableSource.m */,
+ BC01BCCD104024BE006BDEE7 /* SPEncodingPopupAccessory.h */,
+ BC01BCCE104024BE006BDEE7 /* SPEncodingPopupAccessory.m */,
);
name = Controllers;
sourceTree = "<group>";
@@ -1647,6 +1652,7 @@
589235321020C1230011DE00 /* SPHistoryController.m in Sources */,
BCA6271C1031B9D40047E5D5 /* SPTooltip.m in Sources */,
58DA8863103E15B5000B98DF /* SPLogger.m in Sources */,
+ BC01BCCF104024BE006BDEE7 /* SPEncodingPopupAccessory.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};