Skip to content

Commit

Permalink
Changed my mind about something, to make it safer for localization
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoagx committed Nov 3, 2015
1 parent ddaa461 commit edd4ae3
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 5 deletions.
44 changes: 41 additions & 3 deletions Interfaces/English.lproj/DBView.xib
Expand Up @@ -1675,7 +1675,7 @@
<nil key="NSMenuItem"/>
<bool key="NSMenuItemRespectAlignment">YES</bool>
<object class="NSMenu" key="NSMenu" id="856601787">
<string key="NSTitle">encodingPopupMenu</string>
<string key="NSTitle">OtherViews</string>
<array class="NSMutableArray" key="NSMenuItems"/>
</object>
<int key="NSSelectedIndex">-1</int>
Expand Down Expand Up @@ -1717,7 +1717,7 @@
<nil key="NSMenuItem"/>
<bool key="NSMenuItemRespectAlignment">YES</bool>
<object class="NSMenu" key="NSMenu" id="65801928">
<string key="NSTitle">collationPopupMenu</string>
<string key="NSTitle">OtherViews</string>
<array class="NSMutableArray" key="NSMenuItems"/>
</object>
<int key="NSSelectedIndex">-1</int>
Expand Down Expand Up @@ -26385,10 +26385,40 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
<boolean value="NO" key="749.showNotes"/>
<string key="7490.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<boolean value="NO" key="7490.showNotes"/>
<string key="7491.CustomClassName">SPIdMenu</string>
<object class="NSMutableDictionary" key="7491.IBAttributePlaceholdersKey">
<string key="NS.key.0">IBUserDefinedRuntimeAttributesPlaceholderName</string>
<object class="IBUserDefinedRuntimeAttributesPlaceholder" key="NS.object.0">
<string key="name">IBUserDefinedRuntimeAttributesPlaceholderName</string>
<reference key="object" ref="856601787"/>
<array key="userDefinedRuntimeAttributes">
<object class="IBUserDefinedRuntimeAttribute">
<string key="typeIdentifier">com.apple.InterfaceBuilder.userDefinedRuntimeAttributeType.string</string>
<string key="keyPath">menuId</string>
<string key="value">encodingPopupMenu</string>
</object>
</array>
</object>
</object>
<string key="7491.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<boolean value="NO" key="7491.showNotes"/>
<string key="7493.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<boolean value="NO" key="7493.showNotes"/>
<string key="7494.CustomClassName">SPIdMenu</string>
<object class="NSMutableDictionary" key="7494.IBAttributePlaceholdersKey">
<string key="NS.key.0">IBUserDefinedRuntimeAttributesPlaceholderName</string>
<object class="IBUserDefinedRuntimeAttributesPlaceholder" key="NS.object.0">
<string key="name">IBUserDefinedRuntimeAttributesPlaceholderName</string>
<reference key="object" ref="65801928"/>
<array key="userDefinedRuntimeAttributes">
<object class="IBUserDefinedRuntimeAttribute">
<string key="typeIdentifier">com.apple.InterfaceBuilder.userDefinedRuntimeAttributeType.string</string>
<string key="keyPath">menuId</string>
<string key="value">collationPopupMenu</string>
</object>
</array>
</object>
</object>
<string key="7494.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<boolean value="NO" key="7494.showNotes"/>
<string key="7499.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
Expand Down Expand Up @@ -29806,6 +29836,14 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
<string key="minorKey">../Source/SPHistoryController.m</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">SPIdMenu</string>
<string key="superclassName">NSMenu</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">../Source/SPIdMenu.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">SPIndexesController</string>
<string key="superclassName">NSWindowController</string>
Expand Down Expand Up @@ -31025,7 +31063,7 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
</object>
<object class="IBToOneOutletInfo" key="infoTable">
<string key="name">infoTable</string>
<string key="candidateClassName">id</string>
<string key="candidateClassName">NSTableView</string>
</object>
<object class="IBToOneOutletInfo" key="tableDataInstance">
<string key="name">tableDataInstance</string>
Expand Down
47 changes: 47 additions & 0 deletions Source/SPIdMenu.h
@@ -0,0 +1,47 @@
//
// SPIdMenu.h
// sequel-pro
//
// Created by Max Lohrmann on 02.11.15.
// Copyright (c) 2015 Max Lohrmann. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// More info at <https://github.com/sequelpro/sequelpro>

#import <Cocoa/Cocoa.h>

/**
* This class aims to solve the problem, that the only strong connection between
* a menu in IB and code can be made via an outlet. Since comparing breaks once
* the menu is copied (which NSTableView does for its cells) and the menu title
* is localizable, ie. not constant either, we need to add another field.
*
* Note that menuId can be set via IB's "Custom Runtime Attribute" section.
*/
@interface SPIdMenu : NSMenu {
NSString *_menuId;
}

@property (copy) NSString *menuId;

@end
73 changes: 73 additions & 0 deletions Source/SPIdMenu.m
@@ -0,0 +1,73 @@
//
// SPIdMenu.m
// sequel-pro
//
// Created by Max Lohrmann on 02.11.15.
// Copyright (c) 2015 Max Lohrmann. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// More info at <https://github.com/sequelpro/sequelpro>

#import "SPIdMenu.h"

@implementation SPIdMenu

@synthesize menuId = _menuId;

-(id)copyWithZone:(NSZone *)zone
{
SPIdMenu *copy = [super copyWithZone:zone];
copy->_menuId = [[self menuId] copyWithZone:zone];
return copy;
}

-(void)dealloc
{
[self setMenuId:nil];
[super dealloc];
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
[super encodeWithCoder:aCoder];
if([aCoder allowsKeyedCoding]) {
[aCoder encodeObject:[self menuId] forKey:@"SPMenuId"];
}
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
if(self = [super initWithCoder:aDecoder]) {
if([aDecoder allowsKeyedCoding]) {
[self setMenuId:[aDecoder decodeObjectForKey:@"SPMenuId"]];
}
}
return self;
}

- (NSString *)description
{
return [[super description] stringByAppendingFormat:@" with menuId=%@",[self menuId]];
}

@end
6 changes: 4 additions & 2 deletions Source/SPTableStructureDelegate.m
Expand Up @@ -39,6 +39,7 @@
#import "SPServerSupport.h"
#import "SPTablesList.h"
#import "SPPillAttachmentCell.h"
#import "SPIdMenu.h"

#import <SPMySQL/SPMySQL.h>

Expand Down Expand Up @@ -654,6 +655,7 @@ - (NSString *)comboBoxCell:(NSComboBoxCell *)aComboBoxCell completedString:(NSSt

- (void)menuNeedsUpdate:(NSMenu *)menu
{
if(![menu isKindOfClass:[SPIdMenu class]]) return;
//NOTE: NSTableView will usually copy the menu and call this method on the copy. Matching with == won't work!

//walk through the menu and clear the attributedTitle if set. This will remove the gray color from the default items
Expand All @@ -665,7 +667,7 @@ - (void)menuNeedsUpdate:(NSMenu *)menu

NSDictionary *rowData = NSArrayObjectAtIndex(tableFields, [tableSourceView selectedRow]);

if([[menu title] isEqualToString:@"encodingPopupMenu"]) {
if([[menu menuId] isEqualToString:@"encodingPopupMenu"]) {
NSString *tableEncoding = [tableDataInstance tableEncoding];
//NSString *databaseEncoding = [databaseDataInstance getDatabaseDefaultCharacterSet];
//NSString *serverEncoding = [databaseDataInstance getServerDefaultCharacterSet];
Expand All @@ -691,7 +693,7 @@ - (void)menuNeedsUpdate:(NSMenu *)menu

_BuildMenuWithPills(menu, defaultCmp, COUNT_OF(defaultCmp));
}
else if([[menu title] isEqualToString:@"collationPopupMenu"]) {
else if([[menu menuId] isEqualToString:@"collationPopupMenu"]) {
NSString *encoding = [rowData objectForKey:@"encodingName"];
NSString *encodingDefaultCollation = [databaseDataInstance getDefaultCollationForEncoding:encoding];
NSString *tableCollation = [tableDataInstance statusValueForKey:@"Collation"];
Expand Down
6 changes: 6 additions & 0 deletions sequel-pro.xcodeproj/project.pbxproj
Expand Up @@ -198,6 +198,7 @@
507FF26A1BC8450100104523 /* SPExportSettingsPersistence.m in Sources */ = {isa = PBXBuildFile; fileRef = 507FF2691BC8450100104523 /* SPExportSettingsPersistence.m */; };
507FF2A11BCD27A700104523 /* SPFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = 507FF1111BBCC57600104523 /* SPFunctions.m */; };
507FF2A21BCD27AE00104523 /* SPOSInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 50EAB5B71A8FBB08008F627A /* SPOSInfo.m */; };
5089B0271BE714E300E226CD /* SPIdMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = 5089B0261BE714E300E226CD /* SPIdMenu.m */; };
50A9F8B119EAD4B90053E571 /* SPGotoDatabaseController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50A9F8B019EAD4B90053E571 /* SPGotoDatabaseController.m */; };
50D3C3491A75B8A800B5429C /* GotoDatabaseDialog.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50D3C34B1A75B8A800B5429C /* GotoDatabaseDialog.xib */; };
50D3C3521A77135F00B5429C /* SPParserUtils.c in Sources */ = {isa = PBXBuildFile; fileRef = 50D3C3501A77135F00B5429C /* SPParserUtils.c */; };
Expand Down Expand Up @@ -916,6 +917,8 @@
507FF1111BBCC57600104523 /* SPFunctions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPFunctions.m; sourceTree = "<group>"; };
507FF2681BC8450100104523 /* SPExportSettingsPersistence.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPExportSettingsPersistence.h; sourceTree = "<group>"; };
507FF2691BC8450100104523 /* SPExportSettingsPersistence.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPExportSettingsPersistence.m; sourceTree = "<group>"; };
5089B0251BE714E300E226CD /* SPIdMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPIdMenu.h; sourceTree = "<group>"; };
5089B0261BE714E300E226CD /* SPIdMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPIdMenu.m; sourceTree = "<group>"; };
50A9F8AF19EAD4B90053E571 /* SPGotoDatabaseController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPGotoDatabaseController.h; sourceTree = "<group>"; };
50A9F8B019EAD4B90053E571 /* SPGotoDatabaseController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPGotoDatabaseController.m; sourceTree = "<group>"; };
50D3C34A1A75B8A800B5429C /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/GotoDatabaseDialog.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2394,6 +2397,8 @@
children = (
507FF1101BBCC4C400104523 /* SPFunctions.h */,
507FF1111BBCC57600104523 /* SPFunctions.m */,
5089B0251BE714E300E226CD /* SPIdMenu.h */,
5089B0261BE714E300E226CD /* SPIdMenu.m */,
);
name = Utility;
sourceTree = "<group>";
Expand Down Expand Up @@ -3248,6 +3253,7 @@
171312CE109D23C700FB465F /* SPTableTextFieldCell.m in Sources */,
174CE14210AB9281008F892B /* SPProcessListController.m in Sources */,
1792C13710AD75C800ABE758 /* SPServerVariablesController.m in Sources */,
5089B0271BE714E300E226CD /* SPIdMenu.m in Sources */,
1792C26110AE1A2D00ABE758 /* SPConnectionDelegate.m in Sources */,
17CC97F310B4ABE90034CD7A /* SPAboutController.m in Sources */,
5870868410FA3E9C00D58E1C /* SPDataStorage.m in Sources */,
Expand Down

0 comments on commit edd4ae3

Please sign in to comment.