From ef24a9ad6b36ca8a47c878c02b79b30e43933197 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Mon, 11 Mar 2013 12:17:26 +0100 Subject: [PATCH] Remove event translation menu item, it's not managed here anymore. Change NJKeyInputTextField to use the usual delegate with additional protocol requirements, rather than a custom delegate. --- Classes/NJDeviceController.h | 3 +-- Classes/NJDeviceController.m | 2 -- Classes/NJKeyInputField.h | 3 ++- Classes/NJKeyInputField.m | 20 +++++++++++++++---- Info.plist | 2 +- Resources/English.lproj/MainMenu.xib | 29 ++++++++-------------------- 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/Classes/NJDeviceController.h b/Classes/NJDeviceController.h index e668b0f..c0002e8 100644 --- a/Classes/NJDeviceController.h +++ b/Classes/NJDeviceController.h @@ -16,7 +16,6 @@ IBOutlet NJOutputController *outputController; IBOutlet NJMappingsController *mappingsController; IBOutlet NSButton *translatingEventsButton; - IBOutlet NSMenuItem *translatingEventsMenu; IBOutlet NSView *connectDevicePrompt; } @@ -24,6 +23,6 @@ @property (nonatomic, assign) NSPoint mouseLoc; @property (nonatomic, assign) BOOL translatingEvents; -- (IBAction)translatingEventsChanged:(id)sender; +- (IBAction)translatingEventsChanged:(NSButton *)sender; @end diff --git a/Classes/NJDeviceController.m b/Classes/NJDeviceController.m index 5a6603c..3f0c6c8 100644 --- a/Classes/NJDeviceController.m +++ b/Classes/NJDeviceController.m @@ -240,7 +240,6 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn _translatingEvents = translatingEvents; NSInteger state = translatingEvents ? NSOnState : NSOffState; translatingEventsButton.state = state; - translatingEventsMenu.title = translatingEvents ? @"Disable" : @"Enable"; NSString *name = translatingEvents ? NJEventTranslationActivated : NJEventTranslationDeactivated; @@ -253,5 +252,4 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn self.translatingEvents = sender.state == NSOnState; } - @end diff --git a/Classes/NJKeyInputField.h b/Classes/NJKeyInputField.h index ad026d3..9a7a3af 100644 --- a/Classes/NJKeyInputField.h +++ b/Classes/NJKeyInputField.h @@ -20,7 +20,7 @@ extern CGKeyCode NJKeyInputFieldEmpty; + (NSString *)stringForKeyCode:(CGKeyCode)keyCode; // Give the string name for a virtual key code. -@property (nonatomic, weak) IBOutlet id keyDelegate; +@property (nonatomic, weak) IBOutlet id delegate; @property (nonatomic, assign) CGKeyCode keyCode; // The currently displayed key code, or NJKeyInputFieldEmpty if no @@ -37,6 +37,7 @@ extern CGKeyCode NJKeyInputFieldEmpty; @protocol NJKeyInputFieldDelegate +@optional - (void)keyInputField:(NJKeyInputField *)keyInput didChangeKey:(CGKeyCode)keyCode; - (void)keyInputFieldDidClear:(NJKeyInputField *)keyInput; diff --git a/Classes/NJKeyInputField.m b/Classes/NJKeyInputField.m index 814fdfe..a03f238 100644 --- a/Classes/NJKeyInputField.m +++ b/Classes/NJKeyInputField.m @@ -22,7 +22,8 @@ CGKeyCode NJKeyInputFieldEmpty = 0xFFFF; - (void)clear { self.keyCode = NJKeyInputFieldEmpty; - [self.keyDelegate keyInputFieldDidClear:self]; + if ([self.delegate respondsToSelector:@selector(keyInputFieldDidClear:)]) + [self.delegate keyInputFieldDidClear:self]; [self resignIfFirstResponder]; } @@ -179,10 +180,12 @@ CGKeyCode NJKeyInputFieldEmpty = 0xFFFF; if ((event.modifierFlags & IGNORE) && event.keyCode == 0x33) { // Allow Alt/Command+Backspace to clear the field. self.keyCode = NJKeyInputFieldEmpty; - [self.keyDelegate keyInputFieldDidClear:self]; + if ([self.delegate respondsToSelector:@selector(keyInputFieldDidClear:)]) + [self.delegate keyInputFieldDidClear:self]; } else if (!(event.modifierFlags & IGNORE)) { self.keyCode = event.keyCode; - [self.keyDelegate keyInputField:self didChangeKey:self.keyCode]; + if ([self.delegate respondsToSelector:@selector(keyInputField:didChangeKey:)]) + [self.delegate keyInputField:self didChangeKey:self.keyCode]; } [self resignIfFirstResponder]; } @@ -204,8 +207,17 @@ CGKeyCode NJKeyInputFieldEmpty = 0xFFFF; // modifiers are still down. if (!(theEvent.modifierFlags & NSDeviceIndependentModifierFlagsMask)) { self.keyCode = theEvent.keyCode; - [self.keyDelegate keyInputField:self didChangeKey:_keyCode]; + if ([self.delegate respondsToSelector:@selector(keyInputField:didChangeKey:)]) + [self.delegate keyInputField:self didChangeKey:_keyCode]; } } +- (void)setDelegate:(id)delegate { + [super setDelegate:delegate]; +} + +- (id )delegate { + return (id)[super delegate]; +} + @end diff --git a/Info.plist b/Info.plist index 74f1265..4223333 100644 --- a/Info.plist +++ b/Info.plist @@ -46,7 +46,7 @@ CFBundleSignature ???? CFBundleVersion - 124 + 129 LSApplicationCategoryType public.app-category.utilities NSHumanReadableCopyright diff --git a/Resources/English.lproj/MainMenu.xib b/Resources/English.lproj/MainMenu.xib index 0a20186..c666565 100644 --- a/Resources/English.lproj/MainMenu.xib +++ b/Resources/English.lproj/MainMenu.xib @@ -524,7 +524,7 @@ aW5nLg {232, 321} - + YES NO YES @@ -654,7 +654,7 @@ aW5nLg {234, 323} - + 150034 @@ -1615,14 +1615,6 @@ aW5nLg 826 - - - translatingEventsMenu - - - - 877 - translatingEventsChanged: @@ -1977,11 +1969,11 @@ aW5nLg - keyDelegate + delegate - 818 + 966 @@ -3161,7 +3153,7 @@ aW5nLg - 965 + 966 @@ -3228,7 +3220,6 @@ aW5nLg NSOutlineView NJOutputController NSButton - NSMenuItem @@ -3251,10 +3242,6 @@ aW5nLg translatingEventsButton NSButton - - translatingEventsMenu - NSMenuItem - IBProjectSource @@ -3265,13 +3252,13 @@ aW5nLg NJKeyInputField NSTextField - keyDelegate + delegate id - keyDelegate + delegate - keyDelegate + delegate id -- 2.30.2