X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=NJOutputController.m;h=0c301ff6811f9e407101ef89a2296ed6b6973d1a;hp=8f942c6ea28880a83e1a32f88df3c1b2697c84cb;hb=3eb4949fe4554cb4a32e1237571da4a96d26978c;hpb=ca998dd950f0b1900b21dc05cf57987d09b4e70e diff --git a/NJOutputController.m b/NJOutputController.m index 8f942c6..0c301ff 100644 --- a/NJOutputController.m +++ b/NJOutputController.m @@ -10,6 +10,7 @@ #import "NJMappingsController.h" #import "NJMapping.h" #import "NJInput.h" +#import "NJEvents.h" #import "NJDeviceController.h" #import "NJKeyInputField.h" #import "NJOutputMapping.h" @@ -22,11 +23,26 @@ @implementation NJOutputController +- (id)init { + if ((self = [super init])) { + [NSNotificationCenter.defaultCenter + addObserver:self + selector:@selector(mappingListDidChange:) + name:NJEventMappingListChanged + object:nil]; + } + return self; +} + +- (void)dealloc { + [NSNotificationCenter.defaultCenter removeObserver:self]; +} + - (void)cleanUpInterface { NSInteger row = radioButtons.selectedRow; if (row != 1) { - keyInput.keyCode = -1; + keyInput.keyCode = NJKeyInputFieldEmpty; [keyInput resignIfFirstResponder]; } @@ -172,7 +188,7 @@ for (id cur = input.base; cur; cur = cur.base) { inpFullName = [[NSString alloc] initWithFormat:@"%@ > %@", cur.name, inpFullName]; } - title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", mappingsController.currentMapping.name, inpFullName]; + title.stringValue = inpFullName; } if ([output isKindOfClass:NJOutputKeyPress.class]) { @@ -180,13 +196,10 @@ keyInput.keyCode = [(NJOutputKeyPress*)output vk]; } else if ([output isKindOfClass:NJOutputMapping.class]) { [radioButtons selectCellAtRow:2 column:0]; - NSUInteger idx = [mappingsController.mappings - indexOfObject:[(NJOutputMapping *)output mapping]]; - if (idx == NSNotFound) { + NSMenuItem *item = [mappingPopup itemWithRepresentedObject:[(NJOutputMapping *)output mapping]]; + [mappingPopup selectItem:item]; + if (!item) [radioButtons selectCellAtRow:self.enabled ? 0 : -1 column:0]; - [mappingPopup selectItemAtIndex:-1]; - } else - [mappingPopup selectItemAtIndex:idx]; } else if ([output isKindOfClass:NJOutputMouseMove.class]) { [radioButtons selectCellAtRow:3 column:0]; @@ -219,17 +232,19 @@ [keyInput resignIfFirstResponder]; } -- (void)refreshMappings { - NSInteger initialIndex = mappingPopup.indexOfSelectedItem; +- (void)mappingListDidChange:(NSNotification *)note { + NSArray *mappings = note.object; + NJMapping *current = mappingPopup.selectedItem.representedObject; [mappingPopup.menu removeAllItems]; - for (NJMapping *mapping in mappingsController) { + for (NJMapping *mapping in mappings) { NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:mapping.name action:@selector(mappingChosen:) keyEquivalent:@""]; item.target = self; + item.representedObject = mapping; [mappingPopup.menu addItem:item]; } - [mappingPopup selectItemAtIndex:initialIndex]; + [mappingPopup selectItemWithRepresentedObject:current]; } @end