#import "NJMappingsController.h"
#import "NJMapping.h"
#import "NJInput.h"
-#import "NJInputController.h"
+#import "NJEvents.h"
+#import "NJDeviceController.h"
#import "NJKeyInputField.h"
#import "NJOutputMapping.h"
#import "NJOutputController.h"
@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];
}
break;
case 2: {
NJOutputMapping *c = [[NJOutputMapping alloc] init];
- c.mapping = mappingsController.mappings[mappingPopup.indexOfSelectedItem];
+ c.mapping = mappingsController[mappingPopup.indexOfSelectedItem];
return c;
}
case 3: {
for (id <NJInputPathElement> 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]) {
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];
[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.mappings) {
+ 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