Subscribe the output controller to notifications directly. Application delegate has...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 5 Mar 2013 01:08:03 +0000 (02:08 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 5 Mar 2013 01:08:03 +0000 (02:08 +0100)
English.lproj/MainMenu.xib
EnjoyableApplicationDelegate.h
EnjoyableApplicationDelegate.m
NJOutputController.h
NJOutputController.m

index 00740ba..cc6ba01 100644 (file)
                                                        <string key="NSToolbarItemPaletteLabel">Mapping Selector</string>
                                                        <nil key="NSToolbarItemToolTip"/>
                                                        <object class="NSButton" key="NSToolbarItemView" id="227597319">
-                                                               <reference key="NSNextResponder"/>
+                                                               <nil key="NSNextResponder"/>
                                                                <int key="NSvFlags">268</int>
                                                                <string key="NSFrame">{{0, 14}, {140, 25}}</string>
-                                                               <reference key="NSSuperview"/>
                                                                <string key="NSReuseIdentifierKey">_NS:9</string>
                                                                <bool key="NSEnabled">YES</bool>
                                                                <object class="NSButtonCell" key="NSCell" id="850080795">
                                                        <string key="NSToolbarItemPaletteLabel">Translation Switch</string>
                                                        <nil key="NSToolbarItemToolTip"/>
                                                        <object class="NSSegmentedControl" key="NSToolbarItemView" id="679083346">
-                                                               <reference key="NSNextResponder"/>
+                                                               <nil key="NSNextResponder"/>
                                                                <int key="NSvFlags">268</int>
                                                                <string key="NSFrame">{{19, 14}, {67, 25}}</string>
-                                                               <reference key="NSSuperview"/>
                                                                <string key="NSReuseIdentifierKey">_NS:9</string>
                                                                <bool key="NSEnabled">YES</bool>
                                                                <object class="NSSegmentedCell" key="NSCell" id="594076765">
                                        </object>
                                        <int key="connectionID">820</int>
                                </object>
-                               <object class="IBConnectionRecord">
-                                       <object class="IBOutletConnection" key="connection">
-                                               <string key="label">outputController</string>
-                                               <reference key="source" ref="207406104"/>
-                                               <reference key="destination" ref="801536542"/>
-                                       </object>
-                                       <int key="connectionID">825</int>
-                               </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBOutletConnection" key="connection">
                                                <string key="label">window</string>
                                                <string key="dockMenuBase">NSMenu</string>
                                                <string key="inputController">NJDeviceController</string>
                                                <string key="mappingsController">NJMappingsController</string>
-                                               <string key="outputController">NJOutputController</string>
                                                <string key="window">NSWindow</string>
                                        </dictionary>
                                        <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
                                                        <string key="name">mappingsController</string>
                                                        <string key="candidateClassName">NJMappingsController</string>
                                                </object>
-                                               <object class="IBToOneOutletInfo" key="outputController">
-                                                       <string key="name">outputController</string>
-                                                       <string key="candidateClassName">NJOutputController</string>
-                                               </object>
                                                <object class="IBToOneOutletInfo" key="window">
                                                        <string key="name">window</string>
                                                        <string key="candidateClassName">NSWindow</string>
index 6488135..4615d12 100644 (file)
@@ -16,7 +16,6 @@
 }
 
 @property (nonatomic, strong) IBOutlet NJDeviceController *inputController;
-@property (nonatomic, strong) IBOutlet NJOutputController *outputController;
 @property (nonatomic, strong) IBOutlet NJMappingsController *mappingsController;
 
 @end
index 313ba9a..1406115 100644 (file)
@@ -89,7 +89,6 @@
         item.state = mapping == self.mappingsController.currentMapping;
         [dockMenuBase addItem:item];
     }
-    [_outputController refreshMappings];
 }
 
 - (void)mappingDidChange:(NSNotification *)note {
index 5b9a749..0c6a859 100644 (file)
@@ -28,7 +28,6 @@
 @property (assign) BOOL enabled;
 
 - (void)loadCurrent;
-- (void)refreshMappings;
 - (IBAction)radioChanged:(id)sender;
 - (IBAction)mdirChanged:(id)sender;
 - (IBAction)mbtnChanged:(id)sender;
index 5ceccba..0c301ff 100644 (file)
@@ -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"
 
 @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;
     
         [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:@""];