Formal protocol for the interface shared between Joysticks and JSActions, use new...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Sat, 2 Mar 2013 12:33:11 +0000 (13:33 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Sat, 2 Mar 2013 12:33:11 +0000 (13:33 +0100)
ApplicationController.h
Enjoyable.xcodeproj/project.pbxproj
JSAction.h
JSAction.m
Joystick.h
Joystick.m
JoystickController.m
NJActionPathElement.h [new file with mode: 0644]
TargetController.m

index d9a875abcce553541d235740d4edca01054de2bf..a5dcb6a9e43fe7325ba6a37b56e1611852c07fee 100644 (file)
@@ -10,7 +10,7 @@
 @class TargetController;
 @class ConfigsController;
 
-@interface ApplicationController : NSObject {
+@interface ApplicationController : NSObject <NSApplicationDelegate> {
     IBOutlet NSDrawer *drawer;
     IBOutlet NSWindow *mainWindow;
     IBOutlet NSToolbarItem *activeButton;
index 35f48d8fc507843d9006619447f452cba5988d7a..c46eb774171d30f796946562ae56db2e73ab62e4 100644 (file)
@@ -89,6 +89,7 @@
                EE1D7C9116E01E7000B000EB /* NSView+FirstResponder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSView+FirstResponder.m"; sourceTree = "<group>"; };
                EE1D7C9416E0ECCF00B000EB /* NSError+Description.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+Description.h"; sourceTree = "<group>"; };
                EE1D7C9516E0ECCF00B000EB /* NSError+Description.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+Description.m"; sourceTree = "<group>"; };
+               EEF86B7316E2241000674B87 /* NJActionPathElement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NJActionPathElement.h; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                                8BEFAD9B15C46BFF00823AEC /* TargetMouseScroll.m */,
                                8BEFAD9E15C476DC00823AEC /* TargetToggleMouseScope.h */,
                                8BEFAD9F15C476DC00823AEC /* TargetToggleMouseScope.m */,
+                               EEF86B7316E2241000674B87 /* NJActionPathElement.h */,
                        );
                        name = Classes;
                        sourceTree = "<group>";
index 0e2584726f52cffb7d0ddaa00f779c975d486f60..dc00a8d8749eca6f84c6c3f30ebc5a50b21936f1 100644 (file)
@@ -6,7 +6,9 @@
 //  Copyright 2009 University of Otago. All rights reserved.
 //
 
-@interface JSAction : NSObject
+#import "NJActionPathElement.h"
+
+@interface JSAction : NSObject <NJActionPathElement>
 
 @property (nonatomic, assign) IOHIDElementCookie cookie;
 @property (nonatomic, copy) NSArray *children;
@@ -16,7 +18,7 @@
 @property (nonatomic, readonly) float magnitude;
 @property (readonly) NSString *uid;
 
-- (id)initWithName:(NSString *)newName base:(JSAction *)newBase;
+- (id)initWithName:(NSString *)newName base:(id <NJActionPathElement>)newBase;
 
 - (void)notifyEvent:(IOHIDValueRef)value;
 - (id)findSubActionForValue:(IOHIDValueRef)value;
index 6903c56f922238a789e90d351b7faf9631a8dc07..1cdbeb23e4f0e5b32fe4052cbd25d3a9a3bb1353 100644 (file)
@@ -9,7 +9,7 @@
 
 @implementation JSAction
 
-- (id)initWithName:(NSString *)newName base:(JSAction *)newBase {
+- (id)initWithName:(NSString *)newName base:(id <NJActionPathElement>)newBase {
     if ((self = [super init])) {
         self.name = newName;
         self.base = newBase;
index 4b60ba84d75c563d14763f8d9cb9b32bd78ce7b1..e5566f1e78451d924b7923dba646b701a4102d35 100644 (file)
@@ -6,9 +6,11 @@
 //  Copyright 2009 University of Otago. All rights reserved.
 //
 
+#import "NJActionPathElement.h"
+
 @class JSAction;
 
-@interface Joystick : NSObject
+@interface Joystick : NSObject <NJActionPathElement>
 
 @property (nonatomic, assign) int index;
 @property (nonatomic, copy) NSString *productName;
@@ -18,7 +20,7 @@
 @property (readonly) NSString *uid;
 
 - (id)initWithDevice:(IOHIDDeviceRef)device;
-- (id)handlerForEvent:(IOHIDValueRef)value;
+- (JSAction *)handlerForEvent:(IOHIDValueRef)value;
 - (JSAction *)actionForEvent:(IOHIDValueRef)value;
 
 @end
index 3b43e4e3249ba57c158e1f1947681d765b87bfdb..4753caffa7b9171a83f43b483873867d86410b6b 100644 (file)
@@ -95,7 +95,7 @@ static NSArray *ActionsForElement(IOHIDDeviceRef device, id base) {
     return nil;
 }
 
-- (id)handlerForEvent:(IOHIDValueRef) value {
+- (JSAction *)handlerForEvent:(IOHIDValueRef)value {
     JSAction *mainAction = [self actionForEvent:value];
     return [mainAction findSubActionForValue:value];
 }
index 967a935c7b7baa94fe23eb0433f35ce52dca08bb..ab59c82ad435a34ab5ad0ae748862fa7e859cde6 100644 (file)
     CFRelease(hidManager);
 }
 
-- (void)expandRecursive:(id)handler {
-    if ([handler base])
-        [self expandRecursive:[handler base]];
-    [outlineView expandItem:handler];
+- (void)expandRecursive:(id <NJActionPathElement>)pathElement {
+    if (pathElement) {
+        [self expandRecursive:pathElement.base];
+        [outlineView expandItem:pathElement];
+    }
 }
 
 - (void)addRunningTarget:(Target *)target {
@@ -188,26 +189,30 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD
 }
 
 - (JSAction *)selectedAction {
-    id item = [outlineView itemAtRow:outlineView.selectedRow];
-    return [item children] ? nil : item;
+    id <NJActionPathElement> item = [outlineView itemAtRow:outlineView.selectedRow];
+    return (!item.children && item.base) ? item : nil;
 }
 
-- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
-    return item ? [[item children] count] : _joysticks.count;
+- (NSInteger)outlineView:(NSOutlineView *)outlineView
+  numberOfChildrenOfItem:(id <NJActionPathElement>)item {
+    return item ? item.children.count : _joysticks.count;
 }
 
-- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
+- (BOOL)outlineView:(NSOutlineView *)outlineView
+   isItemExpandable:(id <NJActionPathElement>)item {
     return item ? [[item children] count] > 0: YES;
 }
 
-- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
-    return item ? [item children][index] : _joysticks[index];
+- (id)outlineView:(NSOutlineView *)outlineView
+            child:(NSInteger)index
+           ofItem:(id <NJActionPathElement>)item {
+    return item ? item.children[index] : _joysticks[index];
 }
 
-- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item  {
-    if(item == nil)
-        return @"root";
-    return [item name];
+- (id)outlineView:(NSOutlineView *)outlineView
+objectValueForTableColumn:(NSTableColumn *)tableColumn
+           byItem:(id <NJActionPathElement>)item  {
+    return item ? item.name : @"root";
 }
 
 - (void)outlineViewSelectionDidChange:(NSNotification *)notification {
diff --git a/NJActionPathElement.h b/NJActionPathElement.h
new file mode 100644 (file)
index 0000000..f5eb0ca
--- /dev/null
@@ -0,0 +1,9 @@
+#import <Foundation/Foundation.h>
+
+@protocol NJActionPathElement <NSObject>
+
+- (NSArray *)children;
+- (id <NJActionPathElement>) base;
+- (NSString *)name;
+
+@end
index 75f58abe48f3d1254126baec71dab0721a09a5f2..1f285ec5ada026baa3aad49aa3d9b61cdb369677 100644 (file)
     } else {
         self.enabled = YES;
         NSString *actFullName = action.name;
-        for (JSAction *cur = action.base; cur; cur = cur.base) {
+        for (id <NJActionPathElement> cur = action.base; cur; cur = cur.base) {
             actFullName = [[NSString alloc] initWithFormat:@"%@ > %@", cur.name, actFullName];
         }
         title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", configsController.currentConfig.name, actFullName];