Skip to content

Commit 47d9bf6

Browse files
committed
Fix the charset/collation selection when creating a new db/table (minor leftover from #2237)
1 parent edd4ae3 commit 47d9bf6

File tree

5 files changed

+50
-20
lines changed

5 files changed

+50
-20
lines changed

Interfaces/English.lproj/DBView.xib

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7474,14 +7474,14 @@
74747474
<object class="NSWindowTemplate" id="971880172">
74757475
<int key="NSWindowStyleMask">9</int>
74767476
<int key="NSWindowBacking">2</int>
7477-
<string key="NSWindowRect">{{343, 433}, {384, 162}}</string>
7477+
<string key="NSWindowRect">{{343, 433}, {425, 162}}</string>
74787478
<int key="NSWTFlags">1886912512</int>
74797479
<string key="NSWindowTitle">New Table</string>
74807480
<string key="NSWindowClass">NSWindow</string>
74817481
<nil key="NSViewClass"/>
74827482
<nil key="NSUserInterfaceItemIdentifier"/>
74837483
<string key="NSWindowContentMaxSize">{600, 162}</string>
7484-
<string key="NSWindowContentMinSize">{384, 142}</string>
7484+
<string key="NSWindowContentMinSize">{425, 162}</string>
74857485
<object class="NSView" key="NSWindowView" id="381160134">
74867486
<nil key="NSNextResponder"/>
74877487
<int key="NSvFlags">256</int>
@@ -7527,7 +7527,7 @@
75277527
<object class="NSTextField" id="374259664">
75287528
<reference key="NSNextResponder" ref="381160134"/>
75297529
<int key="NSvFlags">258</int>
7530-
<string key="NSFrame">{{138, 124}, {226, 18}}</string>
7530+
<string key="NSFrame">{{138, 124}, {267, 18}}</string>
75317531
<reference key="NSSuperview" ref="381160134"/>
75327532
<reference key="NSNextKeyView" ref="513414376"/>
75337533
<bool key="NSEnabled">YES</bool>
@@ -7547,7 +7547,7 @@
75477547
<object class="NSButton" id="671615720">
75487548
<reference key="NSNextResponder" ref="381160134"/>
75497549
<int key="NSvFlags">257</int>
7550-
<string key="NSFrame">{{291, 13}, {78, 28}}</string>
7550+
<string key="NSFrame">{{332, 13}, {78, 28}}</string>
75517551
<reference key="NSSuperview" ref="381160134"/>
75527552
<string key="NSHuggingPriority">{250, 750}</string>
75537553
<int key="NSTag">1</int>
@@ -7572,7 +7572,7 @@
75727572
<object class="NSPopUpButton" id="1050266816">
75737573
<reference key="NSNextResponder" ref="381160134"/>
75747574
<int key="NSvFlags">258</int>
7575-
<string key="NSFrame">{{135, 95}, {232, 22}}</string>
7575+
<string key="NSFrame">{{135, 95}, {273, 22}}</string>
75767576
<reference key="NSSuperview" ref="381160134"/>
75777577
<reference key="NSNextKeyView" ref="289339603"/>
75787578
<bool key="NSEnabled">YES</bool>
@@ -7624,7 +7624,7 @@
76247624
<object class="NSPopUpButton" id="467430961">
76257625
<reference key="NSNextResponder" ref="381160134"/>
76267626
<int key="NSvFlags">258</int>
7627-
<string key="NSFrame">{{135, 70}, {232, 22}}</string>
7627+
<string key="NSFrame">{{135, 70}, {273, 22}}</string>
76287628
<reference key="NSSuperview" ref="381160134"/>
76297629
<reference key="NSNextKeyView" ref="725803993"/>
76307630
<bool key="NSEnabled">YES</bool>
@@ -7676,7 +7676,7 @@
76767676
<object class="NSPopUpButton" id="189903457">
76777677
<reference key="NSNextResponder" ref="381160134"/>
76787678
<int key="NSvFlags">258</int>
7679-
<string key="NSFrame">{{135, 45}, {232, 22}}</string>
7679+
<string key="NSFrame">{{135, 45}, {273, 22}}</string>
76807680
<reference key="NSSuperview" ref="381160134"/>
76817681
<reference key="NSNextKeyView" ref="635170907"/>
76827682
<bool key="NSEnabled">YES</bool>
@@ -7709,7 +7709,7 @@
77097709
<object class="NSButton" id="635170907">
77107710
<reference key="NSNextResponder" ref="381160134"/>
77117711
<int key="NSvFlags">257</int>
7712-
<string key="NSFrame">{{209, 13}, {84, 28}}</string>
7712+
<string key="NSFrame">{{250, 13}, {84, 28}}</string>
77137713
<reference key="NSSuperview" ref="381160134"/>
77147714
<reference key="NSNextKeyView" ref="671615720"/>
77157715
<string key="NSHuggingPriority">{250, 750}</string>
@@ -7731,7 +7731,7 @@
77317731
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
77327732
</object>
77337733
</array>
7734-
<string key="NSFrameSize">{384, 162}</string>
7734+
<string key="NSFrameSize">{425, 162}</string>
77357735
<reference key="NSNextKeyView" ref="1005413998"/>
77367736
</object>
77377737
<string key="NSScreenRect">{{0, 0}, {1920, 1178}}</string>

Source/SPCharsetCollationHelper.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
NSString *selectedCharset;
5252
NSString *selectedCollation;
5353
NSString *defaultCharsetFormatString;
54+
NSString *defaultCollationFormatString;
5455
NSString *_oldCharset;
5556

5657
BOOL _enabled;
@@ -105,6 +106,27 @@
105106
*/
106107
@property(readwrite,retain) NSString *defaultCharsetFormatString;
107108

109+
/**
110+
* This is the format string that will be used for formatting the defaultCollation.
111+
* It must contain one %@ variable (the collation name).
112+
*
113+
* Note that this is only used as long as the user keeps the _implicit_ defaultCharset.
114+
* E.g. if the charset menu has those items:
115+
* @code
116+
* Inherited from db (latin1)
117+
* -------------------------------
118+
* ...
119+
* cp1521 Western Europe (latin1)
120+
* ...
121+
* @endcode
122+
* This item will only be used for the FIRST appearance of latin1.
123+
* If the user picks ANY item below the line (thus making the charset explicit) both the defaultCollation
124+
* and the defaultCollationFormatString no longer apply and the item at the top of
125+
* the collation list will be the global default for the given charset (not the inherited one)
126+
* and named "Default (...)", because that is how MySQL applies the settings.
127+
*/
128+
@property(readwrite,retain) NSString *defaultCollationFormatString;
129+
108130
/**
109131
* Set this to YES before showing the UI and NO after dismissing it.
110132
* This will cause the charsets to be re-read and the selection to be reset.

Source/SPCharsetCollationHelper.m

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ @implementation SPCharsetCollationHelper
5353
@synthesize selectedCharset;
5454
@synthesize selectedCollation;
5555
@synthesize defaultCharsetFormatString;
56+
@synthesize defaultCollationFormatString;
5657
@synthesize _oldCharset;
5758

5859
- (id)initWithCharsetButton:(NSPopUpButton *)aCharsetButton CollationButton:(NSPopUpButton *)aCollationButton
@@ -63,7 +64,8 @@ - (id)initWithCharsetButton:(NSPopUpButton *)aCharsetButton CollationButton:(NSP
6364
self = [super init];
6465
if (self != nil) {
6566
[self setPromoteUTF8:YES];
66-
[self setDefaultCharsetFormatString:NSLocalizedString(@"Default (%@)",@"Charset Dropdown : Default item ($1 = name)")];
67+
[self setDefaultCharsetFormatString:NSLocalizedString(@"Default (%@)",@"Charset Dropdown : Default item ($1 = charset name)")];
68+
[self setDefaultCollationFormatString:NSLocalizedString(@"Default (%@)",@"Collation Dropdown : Default collation for given charset ($1 = collation name)")];
6769
charsetButton = aCharsetButton;
6870
collationButton = aCollationButton;
6971
//connect the charset button with ourselves
@@ -210,6 +212,7 @@ - (void)refreshCollations {
210212

211213
//get the charset id
212214
NSString *charsetId = [[charsetButton selectedItem] representedObject];
215+
BOOL charsetIsInherited = ([self selectedCharset] == nil);
213216

214217
//now let's get the list of collations for the selected charset id
215218
NSArray *applicableCollations = [databaseData getDatabaseCollationsForEncoding:charsetId];
@@ -220,16 +223,18 @@ - (void)refreshCollations {
220223

221224
//add a separator
222225
[[collationButton menu] addItem:[NSMenuItem separatorItem]];
223-
224-
//if this is the defaultCharset and we have a defaultCollation use that instead
225-
BOOL useGivenDefaultCollation = (defaultCharset && defaultCollation && [charsetId isEqualToString:defaultCharset]);
226-
227-
if(useGivenDefaultCollation) {
228-
NSString *userDefaultCollateTitle = [NSString stringWithFormat:fmtStrDefaultId,defaultCollation];
226+
227+
// there are two kinds of default collations:
228+
// - the inherited default (which is only used if NEITHER charset NOR collation is explicitly set), and
229+
// - the charset default (which is used if charset is explicitly set, but collation is not)
230+
// - that even applies if the selectedCharset is the same as the defaultCharset!
231+
if(charsetIsInherited) {
232+
// implies [charsetId isEqualToString:defaultCharset]
233+
NSString *userInheritedCollateTitle = [NSString stringWithFormat:defaultCollationFormatString,defaultCollation];
229234
//remove the dummy default item.
230235
[collationButton removeItemAtIndex:0];
231236
//add it to the top of the list
232-
[collationButton insertItemWithTitle:userDefaultCollateTitle atIndex:0];
237+
[collationButton insertItemWithTitle:userInheritedCollateTitle atIndex:0];
233238
}
234239

235240
//add the real items
@@ -238,16 +243,16 @@ - (void)refreshCollations {
238243
NSString *collationName = [collation objectForKey:@"COLLATION_NAME"];
239244
[collationButton addItemWithTitle:collationName];
240245

241-
//is this the default collation for this charset (and we didn't override it)?
242-
if(!useGivenDefaultCollation && [[collation objectForKey:@"IS_DEFAULT"] isEqualToString:@"Yes"]) {
246+
//is this the default collation for this charset and charset was given explicitly (ie. breaking inheritance)?
247+
if(!charsetIsInherited && [[collation objectForKey:@"IS_DEFAULT"] isEqualToString:@"Yes"]) {
243248
NSString *defaultCollateTitle = [NSString stringWithFormat:fmtStrDefaultId,collationName];
244249
//remove the dummy default item.
245250
[collationButton removeItemAtIndex:0];
246251
//add it to the top of the list
247252
[collationButton insertItemWithTitle:defaultCollateTitle atIndex:0];
248253
}
249254
}
250-
//reset selection to first item (it may moved when adding the default item)
255+
//reset selection to first item (it may have moved when adding the default item)
251256
[collationButton selectItemAtIndex:0];
252257

253258
//honor selectedCollation

Source/SPDatabaseDocument.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,8 @@ - (IBAction)addDatabase:(id)sender
809809

810810
// Setup the charset and collation dropdowns
811811
[addDatabaseCharsetHelper setDatabaseData:databaseDataInstance];
812+
[addDatabaseCharsetHelper setDefaultCharsetFormatString:NSLocalizedString(@"Server Default (%@)", @"Add Database : Charset dropdown : default item ($1 = charset name)")];
813+
[addDatabaseCharsetHelper setDefaultCollationFormatString:NSLocalizedString(@"Server Default (%@)", @"Add Database : Collation dropdown : default item ($1 = collation name)")];
812814
[addDatabaseCharsetHelper setServerSupport:serverSupport];
813815
[addDatabaseCharsetHelper setPromoteUTF8:YES];
814816
[addDatabaseCharsetHelper setSelectedCharset:nil];

Source/SPTablesList.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ - (IBAction)addTable:(id)sender
391391
[addTableCharsetHelper setServerSupport:[tableDocumentInstance serverSupport]];
392392
[addTableCharsetHelper setPromoteUTF8:YES];
393393
[addTableCharsetHelper setDefaultCharsetFormatString:NSLocalizedString(@"Inherit from database (%@)", @"New Table Sheet : Table Encoding Dropdown : Default inherited from database")];
394+
[addTableCharsetHelper setDefaultCollationFormatString:NSLocalizedString(@"Inherit from database (%@)", @"New Table Sheet : Table Collation Dropdown : Default inherited from database")];
394395
[addTableCharsetHelper setDefaultCharset:[databaseDataInstance getDatabaseDefaultCharacterSet]];
395396
[addTableCharsetHelper setDefaultCollation:[databaseDataInstance getDatabaseDefaultCollation]];
396397
[addTableCharsetHelper setSelectedCharset:nil]; //reset to not carry over state from last time sheet was shown

0 commit comments

Comments
 (0)