diff --git a/MacPass/Base.lproj/GeneralPreferences.xib b/MacPass/Base.lproj/GeneralPreferences.xib index 327233be..9bec4daa 100644 --- a/MacPass/Base.lproj/GeneralPreferences.xib +++ b/MacPass/Base.lproj/GeneralPreferences.xib @@ -1,8 +1,8 @@ - + - + @@ -11,6 +11,7 @@ + @@ -19,7 +20,6 @@ - @@ -29,9 +29,9 @@ - + - + @@ -49,7 +49,7 @@ - + @@ -77,7 +77,7 @@ - + @@ -113,7 +113,7 @@ - + Enabling this compromises security. If enabled, your preferences will contain mappings from database to keyfile. Key locations for databases without a password will not be saved. @@ -122,7 +122,7 @@ - + Disabling this compromises security. If enabled, anything copied to the Clipboard in MacPass will be available on your connected iOS devices. You should clear the clipboard on those devices manually. @@ -211,7 +211,7 @@ - + - + @@ -248,7 +248,7 @@ - + @@ -275,9 +275,9 @@ - + - + @@ -301,10 +301,10 @@ - + - + @@ -338,7 +338,7 @@ - + diff --git a/MacPass/Base.lproj/IntegrationPreferences.xib b/MacPass/Base.lproj/IntegrationPreferences.xib index 07213981..ea5b1f9f 100644 --- a/MacPass/Base.lproj/IntegrationPreferences.xib +++ b/MacPass/Base.lproj/IntegrationPreferences.xib @@ -1,8 +1,8 @@ - + - + @@ -26,19 +26,19 @@ - + - + - + - + - + Autotype might not work properly. Some issues where found that prevent Autotype or Global Autotype to work. Please run the Autotype Doctor to fix those issues. @@ -47,7 +47,7 @@ - + - + @@ -75,7 +75,7 @@ - + diff --git a/MacPass/MPPreferencesWindowController.h b/MacPass/MPPreferencesWindowController.h index 82fe1a46..bada4b1b 100644 --- a/MacPass/MPPreferencesWindowController.h +++ b/MacPass/MPPreferencesWindowController.h @@ -26,12 +26,13 @@ typedef NS_ENUM(NSUInteger, MPPreferencesTab) { MPPreferencesTabGeneral, + MPPreferencesTabIntegration, MPPreferencesTabWorkflow, MPPreferencesTabUpdate, MPPreferencesTabPlugins }; -@interface MPPreferencesWindowController : NSWindowController +@interface MPPreferencesWindowController : NSWindowController - (void)showPreferences; - (void)showPreferencesTab:(MPPreferencesTab)tab; diff --git a/MacPass/MPPreferencesWindowController.m b/MacPass/MPPreferencesWindowController.m index 1d280418..2e200493 100644 --- a/MacPass/MPPreferencesWindowController.m +++ b/MacPass/MPPreferencesWindowController.m @@ -30,13 +30,9 @@ #import "MPUpdatePreferencesController.h" #import "MPPluginPreferencesController.h" -@interface MPPreferencesWindowController () { - NSString *lastIdentifier; -} +@interface MPPreferencesWindowController () -@property (strong, nonatomic) NSMutableDictionary *preferencesController; -@property (strong, nonatomic) NSMutableDictionary *toolbarItems; -@property (strong) NSArray *defaultToolbarItems; +@property (strong) NSTabViewController *tabViewController; @end @@ -49,67 +45,47 @@ -(id)init { self = [super initWithWindow:nil]; if(self) { - NSToolbar *tb = [[NSToolbar alloc] initWithIdentifier:@"PreferencesToolBar"]; - tb.allowsUserCustomization = NO; - tb.displayMode = NSToolbarDisplayModeIconAndLabel; - _preferencesController = [[NSMutableDictionary alloc] initWithCapacity:5]; - _toolbarItems = [[NSMutableDictionary alloc] initWithCapacity:5]; - lastIdentifier = nil; + _tabViewController = [[NSTabViewController alloc] init]; + _tabViewController.tabStyle = NSTabViewControllerTabStyleToolbar; + _tabViewController.transitionOptions = NSViewControllerTransitionNone | NSViewControllerTransitionAllowUserInteraction; + + self.contentViewController = self.tabViewController; [self _setupDefaultPreferencesTabs]; - - tb.delegate = self; - self.window.toolbar = tb; } return self; } - (void)showPreferences { - if(self.defaultToolbarItems.count > 0) { - [self _showPreferencesTabWithIdentifier:self.defaultToolbarItems[0]]; - } + [self showPreferencesTab:MPPreferencesTabGeneral]; } - (void)_showPreferencesTabWithIdentifier:(NSString *)identifier { if(nil == identifier) { @throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Identifier cannot be nil" userInfo:nil]; } - id tab = self.preferencesController[identifier]; - if(tab == nil){ - NSLog(@"Warning. Unknown settingscontroller for identifier: %@. Did you miss to add the controller?", identifier); - return; + + NSInteger index = [self.tabViewController.tabView indexOfTabViewItemWithIdentifier:identifier]; + /* fall back to first index if requested identifier is not know */ + if(index == NSNotFound) { + index = 0; } - self.window.toolbar.selectedItemIdentifier = identifier; - if([tab respondsToSelector:@selector(label)]) { - self.window.title = [tab label]; + + NSTabViewItem *item = self.tabViewController.tabViewItems[index]; + + if(item.label.length > 0) { + self.window.title = item.label; } else { - self.window.title = [tab identifier]; + self.window.title = item.identifier; } - /* Access the view before calling the willShoTab to make sure the view is fully loaded */ - NSView *tabView = [(NSViewController *)tab view]; - if([tab respondsToSelector:@selector(willShowTab)]) { - [tab willShowTab]; + if([item.viewController respondsToSelector:@selector(willShowTab)]) { + [(id)item.viewController willShowTab]; } - NSView *contentView = self.window.contentView; - if( contentView.subviews.count == 1) { - [contentView.subviews.firstObject removeFromSuperview]; - } - [contentView addSubview:tabView]; - [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[tabView]-0-|" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings(tabView)]]; - [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[tabView]-0-|" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings(tabView)]]; - - [contentView layout]; - [contentView layoutSubtreeIfNeeded]; - if([tab respondsToSelector:@selector(didShowTab)]) { - [tab didShowTab]; + self.tabViewController.selectedTabViewItemIndex = index; + if([item.viewController respondsToSelector:@selector(didShowTab)]) { + [(id)item.viewController didShowTab]; } [self.window makeKeyAndOrderFront:nil]; } @@ -120,6 +96,9 @@ case MPPreferencesTabPlugins: tabClass = MPPluginPreferencesController.class; break; + case MPPreferencesTabIntegration: + tabClass = MPIntegrationPreferencesController.class; + break; case MPPreferencesTabUpdate: tabClass = MPUpdatePreferencesController.class; break; @@ -132,98 +111,39 @@ break; } NSString *identifier; - for(id tab in self.preferencesController.allValues) { - if([tab isKindOfClass:tabClass]) { - identifier = tab.identifier; + for(NSTabViewItem *tabViewItem in self.tabViewController.tabViewItems) { + if([tabViewItem.viewController isKindOfClass:tabClass]) { + identifier = tabViewItem.identifier; break; } } [self _showPreferencesTabWithIdentifier:identifier]; } -- (void)_addSettingsTab:(id)tabController { - if(NO == [tabController conformsToProtocol:@protocol(MPPreferencesTab)]) { - NSException *protocollException = [NSException exceptionWithName:NSInvalidArgumentException - reason:@"Controller must conform to MPSettingsTabProtrocoll" - userInfo:nil]; - @throw protocollException; - } - if(NO == [tabController isKindOfClass:[NSViewController class]]) { - NSException *controllerException = [NSException exceptionWithName:NSInvalidArgumentException - reason:@"Controller is no NSViewController" - userInfo:nil]; - @throw controllerException; - } - NSString *identifier = tabController.identifier; - if(nil != self.preferencesController[identifier]) { - NSLog(@"Warning: Settingscontroller with identifier %@ already present!", identifier); - } - else { - self.preferencesController[identifier] = tabController; - } -} - - (void)_setupDefaultPreferencesTabs { - NSArray *controllers = @[ [[MPGeneralPreferencesController alloc] init], + NSArray*> *controllers = @[ [[MPGeneralPreferencesController alloc] init], [[MPIntegrationPreferencesController alloc] init], [[MPWorkflowPreferencesController alloc] init], [[MPUpdatePreferencesController alloc] init], [[MPPluginPreferencesController alloc] init] ]; - NSMutableArray *identifier = [[NSMutableArray alloc] initWithCapacity:controllers.count]; - for(id controller in controllers) { - [self _addSettingsTab:controller]; - [identifier addObject:controller.identifier]; - } - self.defaultToolbarItems = [identifier copy]; -} - -- (void)_showSettingsTab:(id)sender { - if([sender respondsToSelector:@selector(itemIdentifier)]) { - NSString *identfier = [sender itemIdentifier]; - [self _showPreferencesTabWithIdentifier:identfier]; + for(NSViewController *controller in controllers) { + NSString *identifier = controller.identifier; + if([self.tabViewController tabViewItemForViewController:controller]) { + NSLog(@"Skipping adding tabViewController %@ since it's already been added before", controller); + continue; + } + if(NSNotFound != [self.tabViewController.tabView indexOfTabViewItemWithIdentifier:identifier]) { + NSLog(@"Warning: Duplicate identifiers %@ used for different tabs. Skipping adding %@ since the identifier is not unique", identifier, controller); + } + NSTabViewItem *item = [NSTabViewItem tabViewItemWithViewController:controller]; + item.identifier = controller.identifier; + if([controller respondsToSelector:@selector(label)]) { + item.label = controller.label; + } + if([controller respondsToSelector:@selector(image)]) { + item.image = controller.image; + } + [self.tabViewController addTabViewItem:item]; } } - -#pragma mark NSToolbarDelegate - -- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar { - return self.preferencesController.allKeys; -} - -- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar { - return self.defaultToolbarItems; -} - -- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar { - return self.preferencesController.allKeys; -} - -- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag { - NSToolbarItem *item = self.toolbarItems[itemIdentifier]; - if(nil == item) { - item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier]; - /* - Setup the item to use the controllers label if one is present - and supports the appropriate @optional protocol messages - */ - id tab = self.preferencesController[itemIdentifier]; - if([tab respondsToSelector:@selector(label)]) { - item.label = [tab label]; - } - else { - item.label = itemIdentifier; - } - if([tab respondsToSelector:@selector(image)]) { - item.image = [tab image]; - } - else { - item.image = [NSImage imageNamed:NSImageNameCaution]; - } - - item.action = @selector(_showSettingsTab:); - self.toolbarItems[itemIdentifier] = item; - } - return item; -} - @end diff --git a/MacPass/PreferencesWindow.xib b/MacPass/PreferencesWindow.xib index d823a61c..3772b63a 100644 --- a/MacPass/PreferencesWindow.xib +++ b/MacPass/PreferencesWindow.xib @@ -1,8 +1,8 @@ - + - + @@ -21,7 +21,7 @@ - +