mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-23 05:29:26 +00:00
Moved to using NSTabViewController for preferences instead of rolling our own implementation
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15702" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15705" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15702"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
@@ -11,6 +11,7 @@
|
||||
<outlet property="clearPasteboardOnQuitCheckButton" destination="447" id="520"/>
|
||||
<outlet property="clearPasteboardTimeoutPopup" destination="419" id="521"/>
|
||||
<outlet property="enableAutosaveCheckButton" destination="lz3-4U-UMI" id="L5y-58-IgH"/>
|
||||
<outlet property="faviconDownloadMethodPopup" destination="OfU-6f-oTU" id="OfU-6f-oTU-outlet"/>
|
||||
<outlet property="fileChangeStrategyPopup" destination="wIu-Sh-2a2" id="oJo-dA-lEE"/>
|
||||
<outlet property="idleTimeOutPopup" destination="584" id="809"/>
|
||||
<outlet property="lockOnLogoutCheckButton" destination="5SP-Vi-1sn" id="yaI-LH-R5A"/>
|
||||
@@ -19,7 +20,6 @@
|
||||
<outlet property="preventUniversalClipboardSupportCheckButton" destination="nqZ-rB-mFS" id="sbx-rl-reT"/>
|
||||
<outlet property="rememberKeyFileCheckButton" destination="bSt-Wf-FNZ" id="aQm-EA-yAN"/>
|
||||
<outlet property="reopenLastDatabase" destination="530" id="878"/>
|
||||
<outlet property="faviconDownloadMethodPopup" destination="OfU-6f-oTU" id="OfU-6f-oTU-outlet"/>
|
||||
<outlet property="view" destination="1" id="82"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
@@ -29,9 +29,9 @@
|
||||
<rect key="frame" x="0.0" y="0.0" width="406" height="669"/>
|
||||
<subviews>
|
||||
<box autoresizesSubviews="NO" verticalHuggingPriority="500" borderType="line" title="Security" translatesAutoresizingMaskIntoConstraints="NO" id="465">
|
||||
<rect key="frame" x="17" y="16" width="377" height="381"/>
|
||||
<rect key="frame" x="17" y="146" width="372" height="381"/>
|
||||
<view key="contentView" id="mNh-3L-Z6E">
|
||||
<rect key="frame" x="3" y="3" width="371" height="363"/>
|
||||
<rect key="frame" x="3" y="3" width="366" height="363"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="431">
|
||||
@@ -49,7 +49,7 @@
|
||||
<rect key="frame" x="138" y="332" width="143" height="21"/>
|
||||
<popUpButtonCell key="cell" type="push" title="Never" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="429" id="420">
|
||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<font key="font" metaFont="menu"/>
|
||||
<menu key="menu" title="ClipboardClearInterval" id="421">
|
||||
<items>
|
||||
<menuItem title="Never" state="on" id="429">
|
||||
@@ -77,7 +77,7 @@
|
||||
<rect key="frame" x="111" y="192" width="125" height="25"/>
|
||||
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="585">
|
||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<font key="font" metaFont="menu"/>
|
||||
<menu key="menu" title="LockTimes" id="586">
|
||||
<items>
|
||||
<menuItem title="Never" id="804"/>
|
||||
@@ -113,7 +113,7 @@
|
||||
</buttonCell>
|
||||
</button>
|
||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5cV-xX-SUU">
|
||||
<rect key="frame" x="18" y="41" width="335" height="56"/>
|
||||
<rect key="frame" x="18" y="41" width="330" height="56"/>
|
||||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" id="ACh-7H-42N">
|
||||
<font key="font" metaFont="smallSystem"/>
|
||||
<string key="title">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.</string>
|
||||
@@ -122,7 +122,7 @@
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="oQr-FC-HkN">
|
||||
<rect key="frame" x="171" y="5" width="190" height="32"/>
|
||||
<rect key="frame" x="166" y="5" width="190" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Clear all stored locations" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="8Ri-2s-c39">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -146,7 +146,7 @@
|
||||
</buttonCell>
|
||||
</button>
|
||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hy4-RL-dAa">
|
||||
<rect key="frame" x="18" y="224" width="335" height="56"/>
|
||||
<rect key="frame" x="18" y="224" width="330" height="56"/>
|
||||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" id="JGX-Tp-KJk">
|
||||
<font key="font" metaFont="smallSystem"/>
|
||||
<string key="title">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.</string>
|
||||
@@ -211,7 +211,7 @@
|
||||
<box autoresizesSubviews="NO" verticalHuggingPriority="500" borderType="line" title="File Handling" translatesAutoresizingMaskIntoConstraints="NO" id="888">
|
||||
<rect key="frame" x="17" y="529" width="372" height="128"/>
|
||||
<view key="contentView" id="cpg-tt-SHE">
|
||||
<rect key="frame" x="3" y="3" width="371" height="110"/>
|
||||
<rect key="frame" x="3" y="3" width="366" height="110"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<button verticalHuggingPriority="252" translatesAutoresizingMaskIntoConstraints="NO" id="530">
|
||||
@@ -229,7 +229,7 @@
|
||||
</buttonCell>
|
||||
</button>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3Bo-Ml-1KB">
|
||||
<rect key="frame" x="18" y="44" width="335" height="14"/>
|
||||
<rect key="frame" x="18" y="44" width="330" height="14"/>
|
||||
<textFieldCell key="cell" controlSize="small" title="Close and open all documents for changes to take effect" id="ya5-ps-c4W">
|
||||
<font key="font" metaFont="smallSystem"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
@@ -248,7 +248,7 @@
|
||||
<rect key="frame" x="111" y="13" width="38" height="25"/>
|
||||
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="1R2-5t-LWk">
|
||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<font key="font" metaFont="menu"/>
|
||||
<menu key="menu" id="DQY-17-yKP"/>
|
||||
</popUpButtonCell>
|
||||
</popUpButton>
|
||||
@@ -275,9 +275,9 @@
|
||||
</constraints>
|
||||
</box>
|
||||
<box autoresizesSubviews="NO" verticalHuggingPriority="500" borderType="line" title="Network" translatesAutoresizingMaskIntoConstraints="NO" id="wD1-ag-7V5">
|
||||
<rect key="frame" x="17" y="16" width="372" height="125"/>
|
||||
<rect key="frame" x="17" y="16" width="372" height="126"/>
|
||||
<view key="contentView" id="bQD-ZX-d0i">
|
||||
<rect key="frame" x="3" y="3" width="366" height="109"/>
|
||||
<rect key="frame" x="3" y="3" width="366" height="108"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="fl5-Xu-nZP">
|
||||
@@ -301,10 +301,10 @@
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<popUpButton verticalHuggingPriority="750" horizontalCompressionResistancePriority="749" translatesAutoresizingMaskIntoConstraints="NO" id="OfU-6f-oTU">
|
||||
<rect key="frame" x="131" y="76" width="147" height="25"/>
|
||||
<rect key="frame" x="131" y="76" width="38" height="25"/>
|
||||
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="mdi-Go-1bJ">
|
||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<font key="font" metaFont="menu"/>
|
||||
<menu key="menu" id="Xnp-a8-ePw"/>
|
||||
</popUpButtonCell>
|
||||
</popUpButton>
|
||||
@@ -338,7 +338,7 @@
|
||||
<constraint firstAttribute="trailing" secondItem="wD1-ag-7V5" secondAttribute="trailing" constant="20" id="ccK-FL-7Wx"/>
|
||||
<constraint firstItem="465" firstAttribute="top" secondItem="888" secondAttribute="bottom" constant="6" id="wyH-HB-i2U"/>
|
||||
</constraints>
|
||||
<point key="canvasLocation" x="-461" y="-156.5"/>
|
||||
<point key="canvasLocation" x="-535" y="-327"/>
|
||||
</customView>
|
||||
</objects>
|
||||
</document>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15705" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
@@ -26,19 +26,19 @@
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<customView translatesAutoresizingMaskIntoConstraints="NO" id="1">
|
||||
<rect key="frame" x="0.0" y="0.0" width="400" height="449"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="400" height="448"/>
|
||||
<subviews>
|
||||
<box autoresizesSubviews="NO" verticalHuggingPriority="500" borderType="line" title="Autotype" translatesAutoresizingMaskIntoConstraints="NO" id="P9N-HM-wER">
|
||||
<rect key="frame" x="17" y="115" width="366" height="314"/>
|
||||
<rect key="frame" x="17" y="115" width="366" height="313"/>
|
||||
<view key="contentView" id="faU-Ok-HJ3">
|
||||
<rect key="frame" x="3" y="3" width="360" height="296"/>
|
||||
<rect key="frame" x="3" y="3" width="360" height="295"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<stackView orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" translatesAutoresizingMaskIntoConstraints="NO" id="j52-9L-k7c">
|
||||
<rect key="frame" x="16" y="17" width="328" height="269"/>
|
||||
<rect key="frame" x="16" y="17" width="328" height="268"/>
|
||||
<beginningViews>
|
||||
<textField verticalHuggingPriority="750" fixedFrame="YES" preferredMaxLayoutWidth="328" translatesAutoresizingMaskIntoConstraints="NO" id="hMJ-Mo-xOM">
|
||||
<rect key="frame" x="-2" y="227" width="332" height="42"/>
|
||||
<rect key="frame" x="-2" y="226" width="332" height="42"/>
|
||||
<textFieldCell key="cell" controlSize="small" id="H37-ku-aTc">
|
||||
<font key="font" metaFont="smallSystem"/>
|
||||
<string key="title">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.</string>
|
||||
@@ -47,7 +47,7 @@
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jai-b6-Qv4">
|
||||
<rect key="frame" x="-6" y="191" width="177" height="32"/>
|
||||
<rect key="frame" x="-6" y="190" width="177" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Run Autotype Doctor…" bezelStyle="rounded" alignment="center" borderStyle="border" inset="2" id="NP0-R3-m6n">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -57,17 +57,17 @@
|
||||
</connections>
|
||||
</button>
|
||||
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="tik-Ar-FJg">
|
||||
<rect key="frame" x="-2" y="174" width="162" height="18"/>
|
||||
<rect key="frame" x="-2" y="173" width="162" height="18"/>
|
||||
<buttonCell key="cell" type="check" title="Enable global Autotype" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="1qb-Rd-jYu">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
</button>
|
||||
<stackView orientation="horizontal" alignment="centerY" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="d6A-Vb-CMt">
|
||||
<rect key="frame" x="0.0" y="146" width="328" height="22"/>
|
||||
<rect key="frame" x="0.0" y="146" width="328" height="21"/>
|
||||
<beginningViews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="buI-Wb-o3V">
|
||||
<rect key="frame" x="-2" y="3" width="57" height="17"/>
|
||||
<rect key="frame" x="-2" y="3" width="57" height="16"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Shortcut" id="6oN-CH-T0O">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
@@ -75,7 +75,7 @@
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Kvg-he-3c8" customClass="DDHotKeyTextField">
|
||||
<rect key="frame" x="61" y="0.0" width="136" height="22"/>
|
||||
<rect key="frame" x="61" y="0.0" width="136" height="21"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="89" id="Mia-b8-HCZ"/>
|
||||
</constraints>
|
||||
|
||||
@@ -26,12 +26,13 @@
|
||||
|
||||
typedef NS_ENUM(NSUInteger, MPPreferencesTab) {
|
||||
MPPreferencesTabGeneral,
|
||||
MPPreferencesTabIntegration,
|
||||
MPPreferencesTabWorkflow,
|
||||
MPPreferencesTabUpdate,
|
||||
MPPreferencesTabPlugins
|
||||
};
|
||||
|
||||
@interface MPPreferencesWindowController : NSWindowController <NSToolbarDelegate>
|
||||
@interface MPPreferencesWindowController : NSWindowController
|
||||
|
||||
- (void)showPreferences;
|
||||
- (void)showPreferencesTab:(MPPreferencesTab)tab;
|
||||
|
||||
@@ -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<MPPreferencesTab> 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<MPPreferencesTab>)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<MPPreferencesTab>)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<MPPreferencesTab> 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<MPPreferencesTab>)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<NSViewController<MPPreferencesTab>*> *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<MPPreferencesTab> 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<MPPreferencesTab> *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<MPPreferencesTab> 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
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15705" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
@@ -21,7 +21,7 @@
|
||||
<rect key="frame" x="0.0" y="0.0" width="400" height="700"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</view>
|
||||
<point key="canvasLocation" x="67" y="-65"/>
|
||||
<point key="canvasLocation" x="-81" y="-210"/>
|
||||
</window>
|
||||
</objects>
|
||||
</document>
|
||||
|
||||
Reference in New Issue
Block a user