From 3cf3e2515679cbd7d41f2f43c75dc2911befeb8d Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Thu, 29 Nov 2018 23:42:32 +0100 Subject: [PATCH] Using custom MPPathControl to remove double click to show chooser (fixes #54 and #855) --- MacPass.xcodeproj/project.pbxproj | 6 ++++ .../xcshareddata/xcschemes/MacPass.xcscheme | 5 +++ MacPass/Base.lproj/PasswordInputView.xib | 2 +- MacPass/MPPasswordInputController.m | 28 ++++++++++++--- MacPass/MPPathControl.h | 19 +++++++++++ MacPass/MPPathControl.m | 34 +++++++++++++++++++ 6 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 MacPass/MPPathControl.h create mode 100644 MacPass/MPPathControl.m diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 41e462e7..f1af43c0 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -230,6 +230,7 @@ 4CC0D2CE17974A47000B4BDA /* MPCustomFieldTableViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC0D2CD17974A47000B4BDA /* MPCustomFieldTableViewDelegate.m */; }; 4CC0D2D117974A5A000B4BDA /* MPAttachmentTableViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC0D2D017974A5A000B4BDA /* MPAttachmentTableViewDelegate.m */; }; 4CC281891C0F675B00B9174D /* HNHUi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CC281881C0F675B00B9174D /* HNHUi.framework */; }; + 4CC59C2721AF0893005E8D6B /* MPPathControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC59C2621AF0893005E8D6B /* MPPathControl.m */; }; 4CC663E7216F7A7100E33965 /* MPPluginRepositoryBrowserViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC663E5216F7A7100E33965 /* MPPluginRepositoryBrowserViewController.m */; }; 4CC663E8216F7A7100E33965 /* PluginRepositoryBrowserView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CC663E6216F7A7100E33965 /* PluginRepositoryBrowserView.xib */; }; 4CC6DB7A17D23719002C6091 /* KPKNode+IconImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC6DB7917D23719002C6091 /* KPKNode+IconImage.m */; }; @@ -768,6 +769,8 @@ 4CC0D2CF17974A5A000B4BDA /* MPAttachmentTableViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAttachmentTableViewDelegate.h; sourceTree = ""; }; 4CC0D2D017974A5A000B4BDA /* MPAttachmentTableViewDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAttachmentTableViewDelegate.m; sourceTree = ""; }; 4CC281881C0F675B00B9174D /* HNHUi.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HNHUi.framework; path = Carthage/Build/Mac/HNHUi.framework; sourceTree = ""; }; + 4CC59C2521AF0893005E8D6B /* MPPathControl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPPathControl.h; sourceTree = ""; }; + 4CC59C2621AF0893005E8D6B /* MPPathControl.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPPathControl.m; sourceTree = ""; }; 4CC663E4216F7A7100E33965 /* MPPluginRepositoryBrowserViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPPluginRepositoryBrowserViewController.h; sourceTree = ""; }; 4CC663E5216F7A7100E33965 /* MPPluginRepositoryBrowserViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPPluginRepositoryBrowserViewController.m; sourceTree = ""; }; 4CC663E6216F7A7100E33965 /* PluginRepositoryBrowserView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PluginRepositoryBrowserView.xib; sourceTree = ""; }; @@ -1624,6 +1627,8 @@ 4C63B8FA17A3154D0091BD72 /* MPContextButton.m */, 4C57AE1217BA422B00CA4F34 /* MPSegmentedContextCell.h */, 4C57AE1317BA422B00CA4F34 /* MPSegmentedContextCell.m */, + 4CC59C2521AF0893005E8D6B /* MPPathControl.h */, + 4CC59C2621AF0893005E8D6B /* MPPathControl.m */, ); name = Controls; sourceTree = ""; @@ -2049,6 +2054,7 @@ 4C4FCE15177CFE6B00BBF7AE /* MPCustomFieldTableCellView.m in Sources */, 4C4B728518E4B9B400A1A5D5 /* MPDockTileHelper.m in Sources */, 4C5FE9AE17843CE20001D5A8 /* MPSelectedAttachmentTableCellView.m in Sources */, + 4CC59C2721AF0893005E8D6B /* MPPathControl.m in Sources */, 4C3666411787327E00B249F1 /* MPDocument+Attachments.m in Sources */, 4CF6C3021FBF39BF0055AD03 /* MPPluginTabelCellView.m in Sources */, 4C10412C178CDD44001B5239 /* NSDate+Humanized.m in Sources */, diff --git a/MacPass.xcodeproj/xcshareddata/xcschemes/MacPass.xcscheme b/MacPass.xcodeproj/xcshareddata/xcschemes/MacPass.xcscheme index d08a07da..8b4f400c 100644 --- a/MacPass.xcodeproj/xcshareddata/xcschemes/MacPass.xcscheme +++ b/MacPass.xcodeproj/xcshareddata/xcschemes/MacPass.xcscheme @@ -96,6 +96,11 @@ value = "YES" isEnabled = "YES"> + + diff --git a/MacPass/Base.lproj/PasswordInputView.xib b/MacPass/Base.lproj/PasswordInputView.xib index dd9db85b..46e46907 100644 --- a/MacPass/Base.lproj/PasswordInputView.xib +++ b/MacPass/Base.lproj/PasswordInputView.xib @@ -45,7 +45,7 @@ DQ - + diff --git a/MacPass/MPPasswordInputController.m b/MacPass/MPPasswordInputController.m index 62266d0a..078c0e6e 100644 --- a/MacPass/MPPasswordInputController.m +++ b/MacPass/MPPasswordInputController.m @@ -25,15 +25,16 @@ #import "MPDocumentWindowController.h" #import "MPDocument.h" #import "MPSettingsHelper.h" +#import "MPPathControl.h" #import "HNHUi/HNHUi.h" #import "NSError+Messages.h" -@interface MPPasswordInputController () +@interface MPPasswordInputController () @property (weak) IBOutlet HNHUISecureTextField *passwordTextField; -@property (weak) IBOutlet NSPathControl *keyPathControl; +@property (weak) IBOutlet MPPathControl *keyPathControl; @property (weak) IBOutlet NSImageView *messageImageView; @property (weak) IBOutlet NSTextField *messageInfoTextField; @property (weak) IBOutlet NSButton *togglePasswordButton; @@ -75,8 +76,7 @@ [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.passwordTextField setNextKeyView:self.keyPathControl]; + self.keyPathControl.delegate = self; [self _reset]; } @@ -111,11 +111,29 @@ } } +#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 { - if(!self.completionHandler) { return; } diff --git a/MacPass/MPPathControl.h b/MacPass/MPPathControl.h new file mode 100644 index 00000000..bdd73892 --- /dev/null +++ b/MacPass/MPPathControl.h @@ -0,0 +1,19 @@ +// +// MPPathControl.h +// MacPass +// +// Created by Michael Starke on 28.11.18. +// Copyright © 2018 HicknHack Software GmbH. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface MPPathControl : NSPathControl + +- (IBAction)showOpenPanel:(id _Nullable)sender; + +@end + +NS_ASSUME_NONNULL_END diff --git a/MacPass/MPPathControl.m b/MacPass/MPPathControl.m new file mode 100644 index 00000000..b9aa1915 --- /dev/null +++ b/MacPass/MPPathControl.m @@ -0,0 +1,34 @@ +// +// MPPathControl.m +// MacPass +// +// Created by Michael Starke on 28.11.18. +// Copyright © 2018 HicknHack Software GmbH. All rights reserved. +// + +#import "MPPathControl.h" + +@implementation MPPathControl + +/*- (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event { + if(!self.URL) { + [menu cancelTracking]; + [self _showOpenPanel]; + }; + return; +} +*/ + +- (void)showOpenPanel:(id)sender { + NSOpenPanel *panel = [NSOpenPanel openPanel]; + if([self.delegate respondsToSelector:@selector(pathControl:willDisplayOpenPanel:)]) { + [self.delegate pathControl:self willDisplayOpenPanel:panel]; + } + [panel beginWithCompletionHandler:^(NSModalResponse result) { + if(result == NSModalResponseOK) { + self.URL = panel.URLs.firstObject; + } + }]; +} + +@end