From ca998dd950f0b1900b21dc05cf57987d09b4e70e Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Mon, 4 Mar 2013 13:52:00 +0100 Subject: [PATCH] Rework toolbar UI. No more drawer, use a popover. No more weird toggle button, use a segmented control. Swap sides. --- English.lproj/MainMenu.xib | 684 +++++++++++++++++++++++++-------- EnjoyableApplicationDelegate.h | 4 - EnjoyableApplicationDelegate.m | 23 +- NJDeviceController.h | 9 +- NJDeviceController.m | 6 + NJMappingsController.h | 18 +- NJMappingsController.m | 28 +- NJOutputController.m | 4 +- 8 files changed, 587 insertions(+), 189 deletions(-) diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index 1a87bd7..2e2b440 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -16,13 +16,13 @@ NSButtonCell NSCustomObject NSCustomView - NSDrawer NSMatrix NSMenu NSMenuItem NSOutlineView NSPopUpButton NSPopUpButtonCell + NSPopover NSScrollView NSScroller NSSegmentedCell @@ -36,6 +36,7 @@ NSToolbarFlexibleSpaceItem NSToolbarItem NSView + NSViewController NSWindowTemplate @@ -319,50 +320,116 @@ YES NO YES - 1 - 2 + 2 + 1 - + - 42CA6E7F-AC4A-4681-98B6-B9901269E463 + 4AC66688-76E8-47ED-AC0A-7462220A4019 - - Start/Stop - - - - NSImage - NSGoRightTemplate + Custom View + Custom View + + + + 268 + {{0, 14}, {140, 25}} + + + _NS:9 + YES + + -2080374784 + 134217728 + (default) + + LucidaGrande + 13 + 1044 + + _NS:9 + + -2034483200 + 163 + + NSImage + NSListViewTemplate + + + + 400 + 75 + + NO + - {0, 0} - {0, 0} + {13, 25} + {141, 25} YES - YES - -1 + NO + 0 YES 0 - + - A03535DA-B573-44B2-86A0-5E261E68FC16 + 94389EFE-310F-4DB5-95F6-D4AEE8839979 - - Configurations - - - - NSImage - NSListViewTemplate + Custom View + Custom View + + + + 268 + {{5, 14}, {67, 25}} + + + _NS:9 + YES + + 67108864 + 0 + + _NS:9 + + + + 32 + + NSImage + NSPathTemplate + + + Show and remap inputs + YES + 0 + + + 32 + + NSImage + NSActionTemplate + + + Run mapped actions + 1 + 0 + + + 4 + + NO + - {0, 0} - {0, 0} + {67, 25} + {67, 25} YES YES - -1 + 0 YES 0 @@ -394,22 +461,22 @@ - - - + + + - + - + {640, 300} - + 256 @@ -433,7 +500,8 @@ 256 {200, 298} - + + YES NO YES @@ -474,11 +542,7 @@ 67108928 2624 Text Cell - - LucidaGrande - 13 - 1044 - + 6 @@ -532,6 +596,7 @@ {{1, 1}, {200, 298}} + @@ -542,6 +607,7 @@ -2147483392 {{1, 1}, {8, 298}} + NO @@ -553,6 +619,7 @@ -2147483392 {{-100, -100}, {473, 15}} + NO 1 @@ -563,7 +630,8 @@ {202, 300} - + + 150034 @@ -576,6 +644,7 @@ {202, 300} + NSView @@ -588,6 +657,7 @@ 265 {{227, 123}, {180, 24}} + _NS:9 YES @@ -624,6 +694,7 @@ 265 {{227, 55}, {180, 24}} + _NS:9 YES @@ -655,6 +726,7 @@ 265 {{227, 89}, {180, 24}} + _NS:9 YES @@ -687,6 +759,7 @@ 265 {{229, 190}, {176, 24}} + _NS:9 NJKeyInputField @@ -696,6 +769,7 @@ 265 {{226, 156}, {182, 26}} + YES @@ -728,6 +802,7 @@ 268 {{20, 16}, {201, 236}} + NO 7 @@ -872,6 +947,7 @@ 266 {{0, 269}, {429, 17}} + YES @@ -895,6 +971,7 @@ 10 {{12, 258}, {405, 5}} + {0, 0} @@ -921,27 +998,31 @@ {{211, 0}, {429, 300}} + NSView {640, 300} + YES {640, 300} + + {{0, 0}, {1440, 878}} - {640, 369} + {640, 355} {10000000000000, 10000000000000} Enjoyable YES - + 256 @@ -955,8 +1036,9 @@ 256 - {320, 418} + {196, 256} + YES NO @@ -968,9 +1050,9 @@ - 317 - 40 - 1000 + 190 + 190 + 190 75497536 2048 @@ -991,8 +1073,6 @@ - 3 - YES YES @@ -1002,7 +1082,7 @@ 20 - 46170112 + 48267264 1 @@ -1011,11 +1091,12 @@ NO 0 1 - 1 + -1 - {{1, 1}, {320, 418}} + {{2, 2}, {196, 256}} + @@ -1026,7 +1107,8 @@ -2147483392 {{306, 1}, {15, 403}} - + + NO _doScroller: @@ -1035,20 +1117,22 @@ -2147483392 - {{1, 404}, {305, 15}} + {{-100, -100}, {366, 16}} - + + NO 1 _doScroller: - 0.99688480000000002 + 0.98123324396782841 - {{0, 34}, {322, 420}} + {{0, 54}, {200, 260}} - - 133682 + + + 150035 @@ -1059,9 +1143,10 @@ - 260 - {{10, 4}, {39, 28}} + 292 + {{20, 19}, {39, 28}} + YES @@ -1085,9 +1170,10 @@ - 260 - {{57, 4}, {39, 28}} + 292 + {{67, 19}, {39, 28}} + YES 603979776 @@ -1109,21 +1195,12 @@ NO - {322, 454} + {200, 314} + + NSView - - - {200, 100} - {100, 0} - {400, 10000} - 2 - 0.0 - 15 - - - EnjoyableApplicationDelegate @@ -1136,6 +1213,15 @@ NJOutputController + + + + 0 + 1 + 0.0 + 0.0 + YES + @@ -1219,38 +1305,6 @@ 370 - - - parentWindow - - - - 454 - - - - contentView - - - - 455 - - - - toggle: - - - - 498 - - - - toggle: - - - - 811 - delegate @@ -1291,13 +1345,21 @@ 826 + + + translatingEventsChanged: + + + + 858 + - drawer - - + translatingEventsSetting + + - 486 + 859 @@ -1315,14 +1377,6 @@ 607 - - - activeButton - - - - 609 - toggleActivity: @@ -1331,14 +1385,6 @@ 610 - - - toggleActivity: - - - - 611 - dockMenuBase @@ -1427,6 +1473,30 @@ 827 + + + mappingPressed: + + + + 855 + + + + popover + + + + 856 + + + + popoverActivate + + + + 857 + dataSource @@ -1563,6 +1633,30 @@ 818 + + + view + + + + 854 + + + + contentViewController + + + + 852 + + + + delegate + + + + 853 + @@ -1757,18 +1851,13 @@ 451 + - Drawer Content View - - 452 - - - 453 @@ -1828,17 +1917,12 @@ 487 - - + + - - 495 - - - 507 @@ -1882,11 +1966,6 @@ - - 608 - - - 652 @@ -2109,11 +2188,6 @@ - - 790 - - - 810 @@ -2134,6 +2208,64 @@ + + 837 + + + + + + + + 835 + + + + + + + + 836 + + + + + 842 + + + + + + + + 840 + + + + + + + + 841 + + + + + 849 + + + + + 850 + + + Popover View Controller + + + 851 + + + @@ -2161,7 +2293,6 @@ {{114, 276}, {770, 487}} com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2172,7 +2303,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2183,7 +2313,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2220,23 +2349,118 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - 828 + 859 + + EnjoyableApplicationDelegate + NSObject + + NSMenuItem + NSMenu + NSDrawer + NJDeviceController + NJMappingsController + NJOutputController + + + + activeMenuItem + NSMenuItem + + + dockMenuBase + NSMenu + + + drawer + NSDrawer + + + inputController + NJDeviceController + + + mappingsController + NJMappingsController + + + outputController + NJOutputController + + + + IBProjectSource + ./Classes/EnjoyableApplicationDelegate.h + + + + NJDeviceController + NSObject + + translatingEventsChanged: + id + + + translatingEventsChanged: + + translatingEventsChanged: + id + + + + NJMappingsController + NSOutlineView + NJOutputController + NSSegmentedControl + + + + mappingsController + NJMappingsController + + + outlineView + NSOutlineView + + + outputController + NJOutputController + + + translatingEventsSetting + NSSegmentedControl + + + + IBProjectSource + ./Classes/NJDeviceController.h + + NJKeyInputField NSTextField @@ -2256,6 +2480,153 @@ ./Classes/NJKeyInputField.h + + NJMappingsController + NSObject + + id + id + id + id + id + + + + addPressed: + id + + + exportPressed: + id + + + importPressed: + id + + + mappingPressed: + id + + + removePressed: + id + + + + NJOutputController + NSPopover + NSButton + NSButton + NSTableView + + + + outputController + NJOutputController + + + popover + NSPopover + + + popoverActivate + NSButton + + + removeButton + NSButton + + + tableView + NSTableView + + + + IBProjectSource + ./Classes/NJMappingsController.h + + + + NJOutputController + NSObject + + id + id + id + id + + + + mbtnChanged: + id + + + mdirChanged: + id + + + radioChanged: + id + + + sdirChanged: + id + + + + NJDeviceController + NJKeyInputField + NSPopUpButton + NJMappingsController + NSSegmentedControl + NSSegmentedControl + NSMatrix + NSSegmentedControl + NSTextField + + + + inputController + NJDeviceController + + + keyInput + NJKeyInputField + + + mappingPopup + NSPopUpButton + + + mappingsController + NJMappingsController + + + mouseBtnSelect + NSSegmentedControl + + + mouseDirSelect + NSSegmentedControl + + + radioButtons + NSMatrix + + + scrollDirSelect + NSSegmentedControl + + + title + NSTextField + + + + IBProjectSource + ./Classes/NJOutputController.h + + 0 @@ -2263,11 +2634,12 @@ YES 3 + {15, 15} {8, 8} - {9, 9} {11, 10} {11, 11} {10, 3} + {13, 10} {16, 15} {8, 8} diff --git a/EnjoyableApplicationDelegate.h b/EnjoyableApplicationDelegate.h index 6a198e6..17737e8 100644 --- a/EnjoyableApplicationDelegate.h +++ b/EnjoyableApplicationDelegate.h @@ -11,9 +11,6 @@ @class NJMappingsController; @interface EnjoyableApplicationDelegate : NSObject { - IBOutlet NSDrawer *drawer; - IBOutlet NSWindow *mainWindow; - IBOutlet NSToolbarItem *activeButton; IBOutlet NSMenuItem *activeMenuItem; IBOutlet NSMenu *dockMenuBase; } @@ -22,7 +19,6 @@ @property (nonatomic, strong) IBOutlet NJOutputController *outputController; @property (nonatomic, strong) IBOutlet NJMappingsController *mappingsController; -- (IBAction)toggleActivity:(id)sender; - (void)mappingsChanged; @end diff --git a/EnjoyableApplicationDelegate.m b/EnjoyableApplicationDelegate.m index 23324d3..74e8265 100644 --- a/EnjoyableApplicationDelegate.m +++ b/EnjoyableApplicationDelegate.m @@ -43,7 +43,6 @@ while (![dockMenuBase itemAtIndex:mappingsMenuIndex - 1].isSeparatorItem) --mappingsMenuIndex; - [drawer open]; self.outputController.enabled = NO; [self.inputController setup]; [self.mappingsController load]; @@ -54,23 +53,19 @@ } - (void)eventTranslationActivated:(NSNotification *)note { - activeButton.image = [NSImage imageNamed:@"NSStopProgressFreestandingTemplate"]; - activeMenuItem.state = [note.object translatingEvents]; [NSWorkspace.sharedWorkspace.notificationCenter - addObserver:self - selector:@selector(didSwitchApplication:) - name:NSWorkspaceDidActivateApplicationNotification - object:nil]; + addObserver:self + selector:@selector(didSwitchApplication:) + name:NSWorkspaceDidActivateApplicationNotification + object:nil]; NSLog(@"Listening for application changes."); } - (void)eventTranslationDeactivated:(NSNotification *)note { - activeButton.image = [NSImage imageNamed:@"NSGoRightTemplate"]; - activeMenuItem.state = [note.object translatingEvents]; [NSWorkspace.sharedWorkspace.notificationCenter - removeObserver:self - name:NSWorkspaceDidActivateApplicationNotification - object:nil]; + removeObserver:self + name:NSWorkspaceDidActivateApplicationNotification + object:nil]; NSLog(@"Ignoring application changes."); } @@ -83,7 +78,7 @@ while (dockMenuBase.numberOfItems > removeFrom) [dockMenuBase removeItemAtIndex:dockMenuBase.numberOfItems - 1]; int added = 0; - for (NJMapping *mapping in self.mappingsController.mappings) { + for (NJMapping *mapping in self.mappingsController) { NSString *keyEquiv = ++added < 10 ? @(added).stringValue : @""; [dockMenuBase addItemWithTitle:mapping.name action:@selector(chooseMapping:) @@ -102,7 +97,7 @@ - (void)chooseMapping:(id)sender { NSInteger idx = [dockMenuBase indexOfItem:sender] - mappingsMenuIndex; - NJMapping *chosen = self.mappingsController.mappings[idx]; + NJMapping *chosen = self.mappingsController[idx]; [_mappingsController activateMapping:chosen]; } diff --git a/NJDeviceController.h b/NJDeviceController.h index 2769222..cfa6d99 100644 --- a/NJDeviceController.h +++ b/NJDeviceController.h @@ -15,14 +15,17 @@ IBOutlet NSOutlineView *outlineView; IBOutlet NJOutputController *outputController; IBOutlet NJMappingsController *mappingsController; + IBOutlet NSSegmentedControl *translatingEventsSetting; } -- (void)setup; -- (NJDevice *)findDeviceByRef:(IOHIDDeviceRef)device; - @property (nonatomic, readonly) NJInput *selectedInput; @property (nonatomic, assign) NSPoint mouseLoc; @property (nonatomic, assign) BOOL frontWindowOnly; @property (nonatomic, assign) BOOL translatingEvents; +- (void)setup; +- (NJDevice *)findDeviceByRef:(IOHIDDeviceRef)device; + +- (IBAction)translatingEventsChanged:(id)sender; + @end diff --git a/NJDeviceController.m b/NJDeviceController.m index e68cfdb..f5da6dd 100644 --- a/NJDeviceController.m +++ b/NJDeviceController.m @@ -224,6 +224,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn - (void)setTranslatingEvents:(BOOL)translatingEvents { if (translatingEvents != _translatingEvents) { _translatingEvents = translatingEvents; + translatingEventsSetting.selectedSegment = !!translatingEvents; NSString *name = translatingEvents ? NJEventTranslationActivated : NJEventTranslationDeactivated; @@ -232,4 +233,9 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn } } +- (IBAction)translatingEventsChanged:(id)sender { + self.translatingEvents = translatingEventsSetting.selectedSegment; +} + + @end diff --git a/NJMappingsController.h b/NJMappingsController.h index d793714..4867943 100644 --- a/NJMappingsController.h +++ b/NJMappingsController.h @@ -11,26 +11,30 @@ @interface NJMappingsController : NSObject { + NSOpenSavePanelDelegate, + NSFastEnumeration> +{ IBOutlet NSButton *removeButton; IBOutlet NSTableView *tableView; IBOutlet NJOutputController *outputController; + IBOutlet NSButton *popoverActivate; + IBOutlet NSPopover *popover; } @property (nonatomic, readonly) NJMapping *currentMapping; @property (nonatomic, readonly) NSArray *mappings; - (NJMapping *)objectForKeyedSubscript:(NSString *)name; +- (NJMapping *)objectAtIndexedSubscript:(NSUInteger)idx; +- (void)activateMapping:(NJMapping *)mapping; +- (void)activateMappingForProcess:(NSString *)processName; +- (void)save; +- (void)load; - +- (IBAction)mappingPressed:(id)sender; - (IBAction)addPressed:(id)sender; - (IBAction)removePressed:(id)sender; - (IBAction)importPressed:(id)sender; - (IBAction)exportPressed:(id)sender; -- (void)activateMapping:(NJMapping *)mapping; -- (void)activateMappingForProcess:(NSString *)processName; - -- (void)save; -- (void)load; @end diff --git a/NJMappingsController.m b/NJMappingsController.m index fe96462..193edfe 100644 --- a/NJMappingsController.m +++ b/NJMappingsController.m @@ -36,6 +36,19 @@ return nil; } +- (NJMapping *)objectAtIndexedSubscript:(NSUInteger)idx { + return idx < _mappings.count ? _mappings[idx] : nil; +} + +- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state + objects:(__unsafe_unretained id [])buffer + count:(NSUInteger)len { + return [_mappings countByEnumeratingWithState:state + objects:buffer + count:len]; +} + + - (void)activateMappingForProcess:(NSString *)processName { NJMapping *oldMapping = manualMapping; NJMapping *newMapping = self[processName]; @@ -54,6 +67,7 @@ _currentMapping = mapping; [removeButton setEnabled:_mappings[0] != mapping]; [outputController loadCurrent]; + popoverActivate.title = _currentMapping.name; [NSNotificationCenter.defaultCenter postNotificationName:NJEventMappingChanged object:_currentMapping]; [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:[_mappings indexOfObject:mapping]] byExtendingSelection:NO]; @@ -86,11 +100,15 @@ } - (id)tableView:(NSTableView *)view objectValueForTableColumn:(NSTableColumn *)column row:(NSInteger)index { - return [_mappings[index] name]; + return self[index].name; } -- (void)tableView:(NSTableView *)view setObjectValue:(NSString *)obj forTableColumn:(NSTableColumn *)col row:(NSInteger)index { - [(NJMapping *)_mappings[index] setName:obj]; +- (void)tableView:(NSTableView *)view + setObjectValue:(NSString *)obj + forTableColumn:(NSTableColumn *)col + row:(NSInteger)index { + self[index].name = obj; + [self save]; [tableView reloadData]; [(EnjoyableApplicationDelegate *)NSApplication.sharedApplication.delegate mappingsChanged]; } @@ -284,4 +302,8 @@ }]; } +- (IBAction)mappingPressed:(id)sender { + [popover showRelativeToRect:popoverActivate.bounds ofView:popoverActivate preferredEdge:NSMinXEdge]; +} + @end diff --git a/NJOutputController.m b/NJOutputController.m index 6725125..8f942c6 100644 --- a/NJOutputController.m +++ b/NJOutputController.m @@ -116,7 +116,7 @@ break; case 2: { NJOutputMapping *c = [[NJOutputMapping alloc] init]; - c.mapping = mappingsController.mappings[mappingPopup.indexOfSelectedItem]; + c.mapping = mappingsController[mappingPopup.indexOfSelectedItem]; return c; } case 3: { @@ -222,7 +222,7 @@ - (void)refreshMappings { NSInteger initialIndex = mappingPopup.indexOfSelectedItem; [mappingPopup.menu removeAllItems]; - for (NJMapping *mapping in mappingsController.mappings) { + for (NJMapping *mapping in mappingsController) { NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:mapping.name action:@selector(mappingChosen:) keyEquivalent:@""]; -- 2.30.2