+}
+
+- (void)addMapping:(NJMapping *)mapping {
+ [self insertMapping:mapping atIndex:_mappings.count];
+}
+
+- (void)insertMapping:(NJMapping *)mapping atIndex:(NSInteger)idx {
+ [_mappings insertObject:mapping atIndex:idx];
+ [self mappingsChanged];
+}
+
+- (void)removeMappingAtIndex:(NSInteger)idx {
+ NSInteger currentIdx = [self indexOfMapping:_currentMapping];
+ [_mappings removeObjectAtIndex:idx];
+ [self activateMapping:self[MIN(currentIdx, _mappings.count - 1)]];
+ [self mappingsChanged];
+}
+
+- (void)moveMoveMappingFromIndex:(NSInteger)fromIdx toIndex:(NSInteger)toIdx {
+ [_mappings moveObjectAtIndex:fromIdx toIndex:toIdx];
+ [self mappingsChanged];
+}
+
+- (NSUInteger)count {
+ return _mappings.count;
+}
+
+- (void)mappingConflictDidResolve:(NSAlert *)alert
+ returnCode:(NSInteger)returnCode
+ contextInfo:(void *)contextInfo {
+ NSDictionary *userInfo = CFBridgingRelease(contextInfo);
+ NJMapping *oldMapping = userInfo[@"old mapping"];
+ NJMapping *newMapping = userInfo[@"new mapping"];
+ [alert.window orderOut:nil];
+ switch (returnCode) {
+ case NSAlertFirstButtonReturn: // Merge
+ [self mergeMapping:newMapping intoMapping:oldMapping];
+ [self activateMapping:oldMapping];
+ break;
+ case NSAlertThirdButtonReturn: // New Mapping
+ [self.mvc.mappingList beginUpdates];
+ [self addMapping:newMapping];
+ [self.mvc addedMappingAtIndex:_mappings.count - 1 startEditing:YES];
+ [self.mvc.mappingList endUpdates];
+ [self activateMapping:newMapping];
+ break;
+ default: // Cancel, other.
+ break;