X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=NJOutputController.m;h=0c301ff6811f9e407101ef89a2296ed6b6973d1a;hp=ed8fe2df6f74e0f6c3304a39317f4d803c558475;hb=3eb4949fe4554cb4a32e1237571da4a96d26978c;hpb=c38397be0be3a8b0b5c502bf5a5bc24b3c0f61bb diff --git a/NJOutputController.m b/NJOutputController.m index ed8fe2d..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,6 +23,21 @@ @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; @@ -180,12 +196,10 @@ keyInput.keyCode = [(NJOutputKeyPress*)output vk]; } else if ([output isKindOfClass:NJOutputMapping.class]) { [radioButtons selectCellAtRow:2 column:0]; - NSUInteger idx = [mappingPopup indexOfItemWithRepresentedObject:[(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]; @@ -218,10 +232,11 @@ [keyInput resignIfFirstResponder]; } -- (void)refreshMappings { +- (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:@""]; @@ -229,7 +244,7 @@ item.representedObject = mapping; [mappingPopup.menu addItem:item]; } - [mappingPopup selectItemAtIndex:[mappingPopup indexOfItemWithRepresentedObject:current]]; + [mappingPopup selectItemWithRepresentedObject:current]; } @end