From 6cee2033d1c0fc0dacf444064305b9e7e87672a9 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Wed, 20 Mar 2013 20:26:21 +0100 Subject: [PATCH] Move simulation toggle out of device controller. --- Classes/EnjoyableApplicationDelegate.h | 12 +- Classes/EnjoyableApplicationDelegate.m | 74 ++-- Classes/NJDeviceController.h | 6 +- Classes/NJDeviceController.m | 16 - Info.plist | 2 +- Resources/English.lproj/MainMenu.xib | 502 +++++++++++++++++++++++-- 6 files changed, 520 insertions(+), 92 deletions(-) diff --git a/Classes/EnjoyableApplicationDelegate.h b/Classes/EnjoyableApplicationDelegate.h index 52869f2..3b1f2f4 100644 --- a/Classes/EnjoyableApplicationDelegate.h +++ b/Classes/EnjoyableApplicationDelegate.h @@ -19,11 +19,7 @@ NJDeviceViewControllerDelegate, NJMappingsViewControllerDelegate, NJMappingMenuDelegate, - NSWindowDelegate> { - IBOutlet NSMenu *dockMenu; - IBOutlet NSMenu *statusItemMenu; - IBOutlet NSWindow *window; -} + NSWindowDelegate> @property (nonatomic, strong) IBOutlet NJMappingsController *mappingsController; @property (nonatomic, strong) IBOutlet NJDeviceController *deviceController; @@ -31,8 +27,14 @@ @property (nonatomic, strong) IBOutlet NJMappingsViewController *mvc; @property (nonatomic, strong) IBOutlet NJDeviceViewController *dvc; +@property (nonatomic, strong) IBOutlet NSMenu *dockMenu; +@property (nonatomic, strong) IBOutlet NSMenu *statusItemMenu; +@property (nonatomic, strong) IBOutlet NSWindow *window; +@property (nonatomic, strong) IBOutlet NSButton *simulatingEventsButton; + - (IBAction)restoreToForeground:(id)sender; - (IBAction)importMappingClicked:(id)sender; - (IBAction)exportMappingClicked:(id)sender; +- (IBAction)simulatingEventsChanged:(NSButton *)sender; @end diff --git a/Classes/EnjoyableApplicationDelegate.m b/Classes/EnjoyableApplicationDelegate.m index ca641f7..41d068a 100644 --- a/Classes/EnjoyableApplicationDelegate.m +++ b/Classes/EnjoyableApplicationDelegate.m @@ -49,7 +49,7 @@ statusItem = [NSStatusBar.systemStatusBar statusItemWithLength:36]; statusItem.image = [NSImage imageNamed:@"Status Menu Icon Disabled"]; statusItem.highlightMode = YES; - statusItem.menu = statusItemMenu; + statusItem.menu = self.statusItemMenu; statusItem.target = self; } @@ -58,7 +58,7 @@ && NSRunningApplication.currentApplication.wasLaunchedAsLoginItemOrResume) [self transformIntoElement:nil]; else - [window makeKeyAndOrderFront:nil]; + [self.window makeKeyAndOrderFront:nil]; } - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication @@ -71,7 +71,7 @@ ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType(&psn, kProcessTransformToForegroundApplication); [NSApplication.sharedApplication activateIgnoringOtherApps:YES]; - [window makeKeyAndOrderFront:sender]; + [self.window makeKeyAndOrderFront:sender]; [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(transformIntoElement:) object:self]; @@ -79,7 +79,7 @@ } - (void)applicationWillBecomeActive:(NSNotification *)notification { - if (window.isVisible) + if (self.window.isVisible) [self restoreToForeground:notification]; } @@ -109,6 +109,7 @@ } - (void)eventSimulationStarted:(NSNotification *)note { + self.simulatingEventsButton.state = NSOnState; statusItem.image = [NSImage imageNamed:@"Status Menu Icon"]; [NSWorkspace.sharedWorkspace.notificationCenter addObserver:self @@ -118,6 +119,7 @@ } - (void)eventSimulationStopped:(NSNotification *)note { + self.simulatingEventsButton.state = NSOffState; statusItem.image = [NSImage imageNamed:@"Status Menu Icon Disabled"]; [NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self @@ -129,7 +131,7 @@ NSUInteger idx = [note.userInfo[NJMappingIndexKey] intValue]; [self.mvc changedActiveMappingToIndex:idx]; - if (!window.isVisible) + if (!self.window.isVisible) for (int i = 0; i < 4; ++i) [self performSelector:@selector(flashStatusItem) withObject:self @@ -137,7 +139,7 @@ } - (NSMenu *)applicationDockMenu:(NSApplication *)sender { - return dockMenu; + return self.dockMenu; } - (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename { @@ -157,11 +159,11 @@ [self.mvc endUpdates]; [self.mappingsController activateMapping:mapping]; } else { - [window presentError:error - modalForWindow:window - delegate:nil - didPresentSelector:nil - contextInfo:nil]; + [self.window presentError:error + modalForWindow:self.window + delegate:nil + didPresentSelector:nil + contextInfo:nil]; } return !!mapping; } @@ -191,11 +193,11 @@ returnCode:(int)returnCode contextInfo:(void *)contextInfo { [NSUserDefaults.standardUserDefaults setBool:YES forKey:@"explained login items"]; - [window performClose:sheet]; + [self.window performClose:sheet]; } - (BOOL)windowShouldClose:(NSWindow *)sender { - if (sender != window + if (sender != self.window || NSRunningApplication.currentApplication.isLoginItem || [NSUserDefaults.standardUserDefaults boolForKey:@"explained login items"]) return YES; @@ -203,7 +205,7 @@ NSLocalizedString(@"login items prompt", @"alert prompt for adding to login items"), NSLocalizedString(@"login items add button", @"button to add to login items"), NSLocalizedString(@"login items don't add button", @"button to not add to login items"), - nil, window, self, + nil, self.window, self, @selector(loginItemPromptDidEnd:returnCode:contextInfo:), @selector(loginItemPromptDidDismiss:returnCode:contextInfo:), NULL, @@ -219,7 +221,7 @@ - (void)importMappingClicked:(id)sender { NSOpenPanel *panel = [NSOpenPanel openPanel]; panel.allowedFileTypes = @[ @"enjoyable", @"json", @"txt" ]; - [panel beginSheetModalForWindow:window + [panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) { if (result != NSFileHandlingPanelOKButton) return; @@ -234,11 +236,11 @@ } else if (mapping) { [self.mappingsController addMapping:mapping]; } else { - [window presentError:error - modalForWindow:window - delegate:nil - didPresentSelector:nil - contextInfo:nil]; + [self.window presentError:error + modalForWindow:self.window + delegate:nil + didPresentSelector:nil + contextInfo:nil]; } }]; @@ -249,18 +251,18 @@ panel.allowedFileTypes = @[ @"enjoyable" ]; NJMapping *mapping = self.mappingsController.currentMapping; panel.nameFieldStringValue = [mapping.name stringByFixingPathComponent]; - [panel beginSheetModalForWindow:window + [panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) { if (result != NSFileHandlingPanelOKButton) return; [panel close]; NSError *error; if (![mapping writeToURL:panel.URL error:&error]) { - [window presentError:error - modalForWindow:window - delegate:nil - didPresentSelector:nil - contextInfo:nil]; + [self.window presentError:error + modalForWindow:self.window + delegate:nil + didPresentSelector:nil + contextInfo:nil]; } }]; } @@ -300,7 +302,7 @@ [conflictAlert addButtonWithTitle:NSLocalizedString(@"import and merge", @"button to merge imported mappings")]; [conflictAlert addButtonWithTitle:NSLocalizedString(@"cancel import", @"button to cancel import")]; [conflictAlert addButtonWithTitle:NSLocalizedString(@"import new mapping", @"button to import as new mapping")]; - [conflictAlert beginSheetModalForWindow:window + [conflictAlert beginSheetModalForWindow:self.window modalDelegate:self didEndSelector:@selector(mappingConflictDidResolve:returnCode:contextInfo:) contextInfo:(void *)CFBridgingRetain(@{ @"index": @(idx), @@ -437,14 +439,14 @@ // Since the error shows the window, it can trigger another attempt // to re-open the HID manager, which will also probably fail and error, // so don't bother repeating ourselves. - if (!window.attachedSheet) { + if (!self.window.attachedSheet) { [NSApplication.sharedApplication activateIgnoringOtherApps:YES]; - [window makeKeyAndOrderFront:nil]; - [window presentError:error - modalForWindow:window - delegate:nil - didPresentSelector:nil - contextInfo:nil]; + [self.window makeKeyAndOrderFront:nil]; + [self.window presentError:error + modalForWindow:self.window + delegate:nil + didPresentSelector:nil + contextInfo:nil]; } } @@ -457,4 +459,8 @@ return self.deviceController[idx]; } +- (IBAction)simulatingEventsChanged:(NSButton *)sender { + self.deviceController.simulatingEvents = sender.state == NSOnState; +} + @end diff --git a/Classes/NJDeviceController.h b/Classes/NJDeviceController.h index 3691d59..e594f10 100644 --- a/Classes/NJDeviceController.h +++ b/Classes/NJDeviceController.h @@ -7,16 +7,16 @@ // #import "NJHIDManager.h" -#import "NJDeviceViewController.h" +@class NJDevice; @class NJInput; +@class NJInputPathElement; @class NJMappingsController; @protocol NJDeviceControllerDelegate; @interface NJDeviceController : NSObject { IBOutlet NJMappingsController *mappingsController; - IBOutlet NSButton *simulatingEventsButton; } @property (nonatomic, weak) IBOutlet id delegate; @@ -24,8 +24,6 @@ @property (nonatomic, assign) NSPoint mouseLoc; @property (nonatomic, assign) BOOL simulatingEvents; -- (IBAction)simulatingEventsChanged:(NSButton *)sender; - - (NJDevice *)objectAtIndexedSubscript:(NSUInteger)idx; - (NJInputPathElement *)objectForKeyedSubscript:(NSString *)uid; - (NSUInteger)count; diff --git a/Classes/NJDeviceController.m b/Classes/NJDeviceController.m index 23a0932..1b64aaf 100644 --- a/Classes/NJDeviceController.m +++ b/Classes/NJDeviceController.m @@ -13,7 +13,6 @@ #import "NJInput.h" #import "NJOutput.h" #import "NJEvents.h" -#import "NJDeviceViewController.h" @implementation NJDeviceController { NJHIDManager *_hidManager; @@ -198,8 +197,6 @@ - (void)setSimulatingEvents:(BOOL)simulatingEvents { if (simulatingEvents != _simulatingEvents) { _simulatingEvents = simulatingEvents; - NSInteger state = simulatingEvents ? NSOnState : NSOffState; - simulatingEventsButton.state = state; NSString *name = simulatingEvents ? NJEventSimulationStarted : NJEventSimulationStopped; @@ -218,19 +215,6 @@ [self stopHid]; } -- (IBAction)simulatingEventsChanged:(NSButton *)sender { - self.simulatingEvents = sender.state == NSOnState; -} - -- (NSInteger)numberOfDevicesInDeviceList:(NJDeviceViewController *)dvc { - return _devices.count; -} - -- (NJDevice *)deviceViewController:(NJDeviceViewController *)dvc - deviceForIndex:(NSUInteger)idx { - return _devices[idx]; -} - - (NJInputPathElement *)objectForKeyedSubscript:(NSString *)uid { for (NJDevice *dev in _devices) { id item = [dev elementForUID:uid]; diff --git a/Info.plist b/Info.plist index fa16792..a645f94 100644 --- a/Info.plist +++ b/Info.plist @@ -46,7 +46,7 @@ CFBundleSignature ???? CFBundleVersion - 535 + 540 LSApplicationCategoryType public.app-category.utilities NSHumanReadableCopyright diff --git a/Resources/English.lproj/MainMenu.xib b/Resources/English.lproj/MainMenu.xib index bbb398e..b3d81ba 100644 --- a/Resources/English.lproj/MainMenu.xib +++ b/Resources/English.lproj/MainMenu.xib @@ -361,9 +361,11 @@ Enabled - + 268 {{7, 14}, {36, 25}} + + _NS:9 YES @@ -409,9 +411,11 @@ Mapping Selector - + 268 {{0, 14}, {140, 25}} + + _NS:9 YES @@ -500,6 +504,7 @@ -2147483374 {{20, 20}, {194, 283}} + _NS:22 YES @@ -529,6 +534,7 @@ Lg 274 {{20, 20}, {194, 283}} + _NS:22 YES @@ -563,7 +569,8 @@ aW5nLg {232, 321} - + + YES NO YES @@ -658,6 +665,7 @@ aW5nLg {{1, 1}, {232, 321}} + @@ -668,6 +676,7 @@ aW5nLg -2147483392 {{1, 1}, {8, 298}} + NO @@ -679,6 +688,7 @@ aW5nLg -2147483392 {{-100, -100}, {473, 15}} + NO 1 @@ -689,7 +699,8 @@ aW5nLg {234, 323} - + + 150034 @@ -702,6 +713,7 @@ aW5nLg {234, 323} + _NS:9 NSView @@ -715,6 +727,7 @@ aW5nLg 268 {{197, 157}, {193, 21}} + _NS:9 YES @@ -739,6 +752,7 @@ aW5nLg 265 {{189, 117}, {224, 20}} + _NS:9 YES @@ -780,6 +794,7 @@ aW5nLg 268 {{343, 31}, {70, 18}} + _NS:9 YES @@ -810,6 +825,7 @@ aW5nLg 265 {{189, 33}, {150, 20}} + _NS:9 YES @@ -854,6 +870,7 @@ aW5nLg 265 {{191, 24}, {146, 16}} + _NS:9 YES @@ -879,6 +896,7 @@ aW5nLg 265 {{189, 70}, {224, 24}} + _NS:9 YES @@ -932,6 +950,7 @@ aW5nLg 265 {{191, 108}, {220, 16}} + _NS:9 YES @@ -957,6 +976,7 @@ aW5nLg 265 {{191, 196}, {220, 23}} + _NS:9 NJKeyInputField @@ -966,6 +986,7 @@ aW5nLg 265 {{188, 153}, {226, 26}} + YES @@ -998,6 +1019,7 @@ aW5nLg 268 {{24, 20}, {163, 250}} + NO 6 @@ -1128,6 +1150,7 @@ aW5nLg 266 {{9, 286}, {412, 17}} + YES @@ -1151,6 +1174,7 @@ aW5nLg 10 {{12, 276}, {406, 5}} + {0, 0} @@ -1177,6 +1201,7 @@ aW5nLg {{233, 0}, {431, 323}} + _NS:9 NSView @@ -1184,6 +1209,7 @@ aW5nLg {664, 323} + {{0, 0}, {1440, 878}} @@ -1209,7 +1235,8 @@ aW5nLg 256 {198, 198} - + + YES NO YES @@ -1266,6 +1293,7 @@ aW5nLg {{1, 1}, {198, 198}} + @@ -1276,6 +1304,7 @@ aW5nLg -2147483392 {{306, 1}, {15, 403}} + NO @@ -1287,6 +1316,7 @@ aW5nLg -2147483392 {{-100, -100}, {366, 16}} + NO 1 @@ -1297,7 +1327,8 @@ aW5nLg {{0, 20}, {200, 200}} - + + 150034 @@ -1312,6 +1343,7 @@ aW5nLg 268 {{66, -1}, {68, 23}} + _NS:22 YES @@ -1340,6 +1372,7 @@ aW5nLg 292 {{0, -1}, {34, 23}} + YES @@ -1366,6 +1399,7 @@ aW5nLg 292 {{166, -1}, {34, 23}} + YES 67108864 @@ -1387,6 +1421,7 @@ aW5nLg 292 {{133, -1}, {34, 23}} + YES @@ -1409,6 +1444,7 @@ aW5nLg 292 {{33, -1}, {34, 23}} + YES @@ -1433,6 +1469,7 @@ aW5nLg {200, 220} + NSView @@ -1669,30 +1706,6 @@ aW5nLg 822 - - - outputController - - - - 826 - - - - simulatingEventsChanged: - - - - 978 - - - - simulatingEventsButton - - - - 982 - delegate @@ -1789,6 +1802,22 @@ aW5nLg 1027 + + + simulatingEventsChanged: + + + + 1030 + + + + simulatingEventsButton + + + + 1031 + performClick: @@ -3344,9 +3373,418 @@ aW5nLg - 1029 + 1031 + + + + + EnjoyableApplicationDelegate + NSObject + + id + id + id + NSButton + + + + exportMappingClicked: + id + + + importMappingClicked: + id + + + restoreToForeground: + id + + + simulatingEventsChanged: + NSButton + + + + NJDeviceController + NSMenu + NJDeviceViewController + NJMappingsController + NJMappingsViewController + NJOutputController + NSButton + NSMenu + NSWindow + + + + deviceController + NJDeviceController + + + dockMenu + NSMenu + + + dvc + NJDeviceViewController + + + mappingsController + NJMappingsController + + + mvc + NJMappingsViewController + + + outputController + NJOutputController + + + simulatingEventsButton + NSButton + + + statusItemMenu + NSMenu + + + window + NSWindow + + + + IBProjectSource + ./Classes/EnjoyableApplicationDelegate.h + + + + NJDeviceController + NSObject + + id + NJMappingsController + + + + delegate + id + + + mappingsController + NJMappingsController + + + + IBProjectSource + ./Classes/NJDeviceController.h + + + + NJDeviceViewController + NSObject + + id + NSView + NSOutlineView + NSView + + + + delegate + id + + + hidStoppedNotice + NSView + + + inputsTree + NSOutlineView + + + noDevicesNotice + NSView + + + + IBProjectSource + ./Classes/NJDeviceViewController.h + + + + NJKeyInputField + NSControl + + delegate + id + + + delegate + + delegate + id + + + + IBProjectSource + ./Classes/NJKeyInputField.h + + + + NJMappingMenuController + NSObject + + id + NSMenuItem + NSMenu + + + + delegate + id + + + eventSimulationToggle + NSMenuItem + + + menu + NSMenu + + + + IBProjectSource + ./Classes/NJMappingMenuController.h + + + + NJMappingsController + NSObject + + IBProjectSource + ./Classes/NJMappingsController.h + + + + NJMappingsViewController + NSViewController + + id + id + id + id + id + + + + addClicked: + id + + + mappingTriggerClicked: + id + + + moveDownClicked: + id + + + moveUpClicked: + id + + + removeClicked: + id + + + + id + NSTableView + NSPopover + NSButton + NSButton + NSButton + NSButton + + + + delegate + id + + + mappingList + NSTableView + + + mappingListPopover + NSPopover + + + mappingListTrigger + NSButton + + + moveDown + NSButton + + + moveUp + NSButton + + + removeMapping + NSButton + + + + IBProjectSource + ./Classes/NJMappingsViewController.h + + + + NJOutputController + NSObject + + id + id + id + id + id + id + id + + + + mbtnChanged: + id + + + mdirChanged: + id + + + mouseSpeedChanged: + id + + + radioChanged: + id + + + scrollSpeedChanged: + id + + + scrollTypeChanged: + id + + + sdirChanged: + id + + + + NJKeyInputField + NSPopUpButton + NJMappingsController + NSSegmentedControl + NSSegmentedControl + NSSlider + NSMatrix + NSSegmentedControl + NSSlider + NSButton + NSTextField + NSButton + + + + keyInput + NJKeyInputField + + + mappingPopup + NSPopUpButton + + + mappingsController + NJMappingsController + + + mouseBtnSelect + NSSegmentedControl + + + mouseDirSelect + NSSegmentedControl + + + mouseSpeedSlider + NSSlider + + + radioButtons + NSMatrix + + + scrollDirSelect + NSSegmentedControl + + + scrollSpeedSlider + NSSlider + + + smoothCheck + NSButton + + + title + NSTextField + + + unknownMapping + NSButton + + + + IBProjectSource + ./Classes/NJOutputController.h + + + + SUUpdater + NSObject + + checkForUpdates: + id + + + checkForUpdates: + + checkForUpdates: + id + + + + delegate + id + + + delegate + + delegate + id + + + + IBProjectSource + ./Classes/SUUpdater.h + + + - 0 IBCocoaFramework YES -- 2.30.2