selector:@selector(mappingDidChange:)
name:NJEventMappingChanged
object:nil];
+ [NSNotificationCenter.defaultCenter
+ addObserver:self
+ selector:@selector(mappingListDidChange:)
+ name:NJEventMappingListChanged
+ object:nil];
[NSNotificationCenter.defaultCenter
addObserver:self
selector:@selector(eventTranslationActivated:)
- (void)applicationWillTerminate:(NSNotification *)aNotification {
[NSUserDefaults.standardUserDefaults synchronize];
+ [NSNotificationCenter.defaultCenter removeObserver:self];
}
- (void)eventTranslationActivated:(NSNotification *)note {
NSLog(@"Ignoring application changes.");
}
-- (void)mappingsChanged {
+- (void)mappingListDidChange:(NSNotification *)note {
+ NSArray *mappings = note.object;
NSInteger removeFrom = mappingsMenuIndex;
while (dockMenuBase.numberOfItems > removeFrom)
[dockMenuBase removeItemAtIndex:dockMenuBase.numberOfItems - 1];
int added = 0;
- for (NJMapping *mapping in self.mappingsController) {
+ for (NJMapping *mapping in mappings) {
NSString *keyEquiv = ++added < 10 ? @(added).stringValue : @"";
[dockMenuBase addItemWithTitle:mapping.name
action:@selector(chooseMapping:)
#import "NJMappingsController.h"
-#import "EnjoyableApplicationDelegate.h"
#import "NJMapping.h"
#import "NJMappingsController.h"
#import "NJOutput.h"
return idx < _mappings.count ? _mappings[idx] : nil;
}
+- (void)mappingsChanged {
+ [self save];
+ [tableView reloadData];
+ [NSNotificationCenter.defaultCenter
+ postNotificationName:NJEventMappingListChanged
+ object:_mappings];
+}
+
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
objects:(__unsafe_unretained id [])buffer
count:(NSUInteger)len {
- (IBAction)addPressed:(id)sender {
NJMapping *newMapping = [[NJMapping alloc] initWithName:@"Untitled"];
[_mappings addObject:newMapping];
- [(EnjoyableApplicationDelegate *)NSApplication.sharedApplication.delegate mappingsChanged];
- [tableView reloadData];
- [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:_mappings.count - 1] byExtendingSelection:NO];
- [tableView editColumn:0 row:_mappings.count - 1 withEvent:nil select:YES];
+ [self mappingsChanged];
[self activateMapping:newMapping];
+ [tableView editColumn:0 row:_mappings.count - 1 withEvent:nil select:YES];
}
- (IBAction)removePressed:(id)sender {
return;
[_mappings removeObjectAtIndex:tableView.selectedRow];
- [tableView reloadData];
- [(EnjoyableApplicationDelegate *)NSApplication.sharedApplication.delegate mappingsChanged];
+ [self mappingsChanged];
[self activateMapping:_mappings[0]];
- [self save];
}
-(void)tableViewSelectionDidChange:(NSNotification *)notify {
- if (tableView.selectedRow >= 0)
- [self activateMapping:_mappings[tableView.selectedRow]];
+ [self activateMapping:self[tableView.selectedRow]];
}
- (id)tableView:(NSTableView *)view objectValueForTableColumn:(NSTableColumn *)column row:(NSInteger)index {
forTableColumn:(NSTableColumn *)col
row:(NSInteger)index {
self[index].name = obj;
- [self save];
- [tableView reloadData];
- [(EnjoyableApplicationDelegate *)NSApplication.sharedApplication.delegate mappingsChanged];
+ [self mappingsChanged];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
if (current >= newMappings.count)
current = 0;
_mappings = newMappings;
- [tableView reloadData];
- [(EnjoyableApplicationDelegate *)NSApplication.sharedApplication.delegate mappingsChanged];
+ [self mappingsChanged];
[self activateMapping:_mappings[current]];
}
}
mapping = mergeInto;
} else {
[_mappings addObject:mapping];
- [tableView reloadData];
}
- [self save];
- [(EnjoyableApplicationDelegate *)NSApplication.sharedApplication.delegate mappingsChanged];
+ [self mappingsChanged];
[self activateMapping:mapping];
[outputController loadCurrent];