From edd4ae31b6ad14bcf3bc4deca6e68af79ad24b2a Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 3 Nov 2015 22:42:43 +0100 Subject: Changed my mind about something, to make it safer for localization --- Interfaces/English.lproj/DBView.xib | 44 ++++++++++++++++++++-- Source/SPIdMenu.h | 47 +++++++++++++++++++++++ Source/SPIdMenu.m | 73 ++++++++++++++++++++++++++++++++++++ Source/SPTableStructureDelegate.m | 6 ++- sequel-pro.xcodeproj/project.pbxproj | 6 +++ 5 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 Source/SPIdMenu.h create mode 100644 Source/SPIdMenu.m diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index d7f22211..4288acde 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -1675,7 +1675,7 @@ YES - encodingPopupMenu + OtherViews -1 @@ -1717,7 +1717,7 @@ YES - collationPopupMenu + OtherViews -1 @@ -26385,10 +26385,40 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA com.apple.InterfaceBuilder.CocoaPlugin + SPIdMenu + + IBUserDefinedRuntimeAttributesPlaceholderName + + IBUserDefinedRuntimeAttributesPlaceholderName + + + + com.apple.InterfaceBuilder.userDefinedRuntimeAttributeType.string + menuId + encodingPopupMenu + + + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + SPIdMenu + + IBUserDefinedRuntimeAttributesPlaceholderName + + IBUserDefinedRuntimeAttributesPlaceholderName + + + + com.apple.InterfaceBuilder.userDefinedRuntimeAttributeType.string + menuId + collationPopupMenu + + + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -29806,6 +29836,14 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA ../Source/SPHistoryController.m + + SPIdMenu + NSMenu + + IBProjectSource + ../Source/SPIdMenu.h + + SPIndexesController NSWindowController @@ -31025,7 +31063,7 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA infoTable - id + NSTableView tableDataInstance diff --git a/Source/SPIdMenu.h b/Source/SPIdMenu.h new file mode 100644 index 00000000..dbda8952 --- /dev/null +++ b/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 + +#import + +/** + * 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 diff --git a/Source/SPIdMenu.m b/Source/SPIdMenu.m new file mode 100644 index 00000000..7cb7d97e --- /dev/null +++ b/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 + +#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 diff --git a/Source/SPTableStructureDelegate.m b/Source/SPTableStructureDelegate.m index 3ff4d6e4..6b2249dc 100644 --- a/Source/SPTableStructureDelegate.m +++ b/Source/SPTableStructureDelegate.m @@ -39,6 +39,7 @@ #import "SPServerSupport.h" #import "SPTablesList.h" #import "SPPillAttachmentCell.h" +#import "SPIdMenu.h" #import @@ -654,6 +655,7 @@ static void _BuildMenuWithPills(NSMenu *menu,struct _cmpMap *map,size_t mapEntri - (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 @@ -665,7 +667,7 @@ static void _BuildMenuWithPills(NSMenu *menu,struct _cmpMap *map,size_t mapEntri 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]; @@ -691,7 +693,7 @@ static void _BuildMenuWithPills(NSMenu *menu,struct _cmpMap *map,size_t mapEntri _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"]; diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 44fe6ecc..7abb7567 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -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 */; }; @@ -916,6 +917,8 @@ 507FF1111BBCC57600104523 /* SPFunctions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPFunctions.m; sourceTree = ""; }; 507FF2681BC8450100104523 /* SPExportSettingsPersistence.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPExportSettingsPersistence.h; sourceTree = ""; }; 507FF2691BC8450100104523 /* SPExportSettingsPersistence.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPExportSettingsPersistence.m; sourceTree = ""; }; + 5089B0251BE714E300E226CD /* SPIdMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPIdMenu.h; sourceTree = ""; }; + 5089B0261BE714E300E226CD /* SPIdMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPIdMenu.m; sourceTree = ""; }; 50A9F8AF19EAD4B90053E571 /* SPGotoDatabaseController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPGotoDatabaseController.h; sourceTree = ""; }; 50A9F8B019EAD4B90053E571 /* SPGotoDatabaseController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPGotoDatabaseController.m; sourceTree = ""; }; 50D3C34A1A75B8A800B5429C /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/GotoDatabaseDialog.xib; sourceTree = ""; }; @@ -2394,6 +2397,8 @@ children = ( 507FF1101BBCC4C400104523 /* SPFunctions.h */, 507FF1111BBCC57600104523 /* SPFunctions.m */, + 5089B0251BE714E300E226CD /* SPIdMenu.h */, + 5089B0261BE714E300E226CD /* SPIdMenu.m */, ); name = Utility; sourceTree = ""; @@ -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 */, -- cgit v1.2.3