Folded delegation int MPPathControl

This commit is contained in:
Michael Starke
2018-11-30 17:20:24 +01:00
parent 3cf3e25156
commit 714bdf782d
5 changed files with 53 additions and 42 deletions

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@@ -25,12 +25,12 @@
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="403" height="219"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
<view key="contentView" id="2">
<view key="contentView" misplaced="YES" id="2">
<rect key="frame" x="0.0" y="0.0" width="403" height="219"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<pathControl verticalHuggingPriority="750" allowsExpansionToolTips="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4">
<rect key="frame" x="105" y="87" width="242" height="26"/>
<pathControl verticalHuggingPriority="750" allowsExpansionToolTips="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4" customClass="MPPathControl">
<rect key="frame" x="105" y="87" width="242" height="25"/>
<pathCell key="cell" selectable="YES" editable="YES" alignment="left" pathStyle="popUp" id="23">
<font key="font" metaFont="system"/>
</pathCell>
@@ -44,7 +44,7 @@
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6">
<rect key="frame" x="108" y="59" width="236" height="25"/>
<rect key="frame" x="108" y="60" width="236" height="23"/>
<buttonCell key="cell" type="roundTextured" title="Generate Keyfile" bezelStyle="texturedRounded" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="21">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@@ -54,7 +54,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="7">
<rect key="frame" x="352" y="153" width="31" height="25"/>
<rect key="frame" x="352" y="153" width="31" height="23"/>
<constraints>
<constraint firstAttribute="width" constant="31" id="59"/>
</constraints>
@@ -64,7 +64,7 @@
</buttonCell>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8">
<rect key="frame" x="352" y="88" width="31" height="25"/>
<rect key="frame" x="352" y="89" width="31" height="23"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="NSStopProgressTemplate" imagePosition="only" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="19">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@@ -74,7 +74,7 @@
</connections>
</button>
<secureTextField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9" customClass="HNHUISecureTextField">
<rect key="frame" x="108" y="153" width="236" height="24"/>
<rect key="frame" x="108" y="152" width="236" height="24"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="200" id="Gin-yR-DMk"/>
</constraints>
@@ -88,7 +88,7 @@
</secureTextFieldCell>
</secureTextField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="10">
<rect key="frame" x="51" y="123" width="51" height="17"/>
<rect key="frame" x="51" y="122" width="51" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Repeat:" id="16">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -96,7 +96,7 @@
</textFieldCell>
</textField>
<secureTextField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="11" customClass="HNHUISecureTextField">
<rect key="frame" x="108" y="119" width="236" height="24"/>
<rect key="frame" x="108" y="118" width="236" height="24"/>
<secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="Repeat Password" drawsBackground="YES" usesSingleLineMode="YES" id="15">
<font key="font" size="13" name="Menlo-Regular"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -107,7 +107,7 @@
</secureTextFieldCell>
</secureTextField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="12">
<rect key="frame" x="158" y="185" width="136" height="14"/>
<rect key="frame" x="158" y="184" width="136" height="14"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Missmatching Passwords" id="14">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
@@ -138,7 +138,7 @@ Gw
</connections>
</button>
<button horizontalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="yKc-I9-uzv">
<rect key="frame" x="18" y="156" width="84" height="18"/>
<rect key="frame" x="18" y="155" width="84" height="18"/>
<buttonCell key="cell" type="check" title="Password:" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="OQz-DA-SoY">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>

View File

@@ -50,9 +50,6 @@ DQ
<pathCell key="cell" selectable="YES" editable="YES" alignment="left" pathStyle="popUp" id="242">
<font key="font" metaFont="system"/>
</pathCell>
<connections>
<outlet property="delegate" destination="-2" id="aKL-AU-RZc"/>
</connections>
</pathControl>
<imageView translatesAutoresizingMaskIntoConstraints="NO" id="262">
<rect key="frame" x="230" y="241" width="48" height="48"/>

View File

@@ -31,7 +31,7 @@
#import "NSError+Messages.h"
@interface MPPasswordInputController () <NSPathControlDelegate>
@interface MPPasswordInputController ()
@property (weak) IBOutlet HNHUISecureTextField *passwordTextField;
@property (weak) IBOutlet MPPathControl *keyPathControl;
@@ -76,7 +76,6 @@
[self.enablePasswordCheckBox bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(enablePassword)) options:nil];
[self.togglePasswordButton bind:NSEnabledBinding toObject:self withKeyPath:NSStringFromSelector(@selector(enablePassword)) options:nil];
[self.passwordTextField bind:NSEnabledBinding toObject:self withKeyPath:NSStringFromSelector(@selector(enablePassword)) options:nil];
self.keyPathControl.delegate = self;
[self _reset];
}
@@ -111,26 +110,6 @@
}
}
#pragma mark NSPathControlDelegate
-(void)pathControl:(NSPathControl *)pathControl willPopUpMenu:(NSMenu *)menu {
if(pathControl != self.keyPathControl) {
return;
}
if(!self.keyPathControl.URL) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(50 * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
[menu cancelTracking];
});
[self.keyPathControl showOpenPanel:self];
}
return;
}
- (void)pathControl:(NSPathControl *)pathControl willDisplayOpenPanel:(NSOpenPanel *)openPanel {
openPanel.animationBehavior = NSWindowAnimationBehaviorDocumentWindow;
openPanel.canChooseDirectories = NO;
openPanel.allowsMultipleSelection = NO;
openPanel.prompt = NSLocalizedString(@"CHOOSE_FILE_BUTTON_TITLE", @"Button title in the key file selection dialog for selecting a key");
}
#pragma mark -
#pragma mark Private
- (IBAction)_submit:(id)sender {

View File

@@ -10,7 +10,7 @@
NS_ASSUME_NONNULL_BEGIN
@interface MPPathControl : NSPathControl
@interface MPPathControl : NSPathControl <NSPathControlDelegate>
- (IBAction)showOpenPanel:(id _Nullable)sender;

View File

@@ -10,14 +10,25 @@
@implementation MPPathControl
/*- (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event {
- (instancetype)initWithFrame:(NSRect)frameRect {
self = [super initWithFrame:frameRect];
self.delegate = self;
return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
self.delegate = self;
return self;
}
- (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event {
if(!self.URL) {
[menu cancelTracking];
[self _showOpenPanel];
[self showOpenPanel:nil];
};
return;
}
*/
- (void)showOpenPanel:(id)sender {
NSOpenPanel *panel = [NSOpenPanel openPanel];
@@ -31,4 +42,28 @@
}];
}
- (void)pathControl:(NSPathControl *)pathControl willPopUpMenu:(NSMenu *)menu {
if(pathControl != self) {
return;
}
if(@available(macOS 10.11, *)) {
NSLog(@"Skipping 10.10 pathControl:willPopUpMenu");
}
else {
if(!self.URL) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(50 * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
[menu cancelTracking];
});
[self showOpenPanel:self];
}
}
}
- (void)pathControl:(NSPathControl *)pathControl willDisplayOpenPanel:(NSOpenPanel *)openPanel {
openPanel.animationBehavior = NSWindowAnimationBehaviorDocumentWindow;
openPanel.canChooseDirectories = NO;
openPanel.allowsMultipleSelection = NO;
openPanel.prompt = NSLocalizedString(@"CHOOSE_FILE_BUTTON_TITLE", @"Button title in the key file selection dialog for selecting a key");
}
@end