Add touchbar support (#862)

* Add touchbar support for the password input

* Add touchbar support for entry list

* Set NSTouchBarItemIdentifier as static strings

* Simplify touchbar initialization in NSTextView

* Remove colored buttons in touchbar to adhere to the Human Interface Guidelines

* Add search action to touchbar

* Create a TouchBarButtonCreator

* Enable Touchbar customization

* Fix typo

* Add customizationLabel to all buttons

* Use localised strings instead of hardcoded

* Add a popover touchbar for editing

* Update localisation

* Set the bezel color of the show password button to selected if toggled
This commit is contained in:
Veit-Hendrik Schlenker
2019-07-10 12:00:38 +02:00
committed by Michael Starke
parent 30a68fc9e3
commit 2d98c480da
12 changed files with 293 additions and 2 deletions

View File

@@ -26,13 +26,20 @@
#import "MPDocument.h"
#import "MPSettingsHelper.h"
#import "MPPathControl.h"
#import "MPTouchBarButtonCreator.h"
#import "HNHUi/HNHUi.h"
#import "NSError+Messages.h"
static NSTouchBarCustomizationIdentifier touchBarIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.passwordInput";
static NSTouchBarItemIdentifier touchBarChooseKeyfileIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.passwordInput.chooseKeyfile";
static NSTouchBarItemIdentifier touchBarShowPasswordIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.passwordInput.showPassword";
static NSTouchBarItemIdentifier touchBarUnlockIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.passwordInput.unlock";
@interface MPPasswordInputController ()
@property (strong) NSButton *showPasswordButton;
@property (weak) IBOutlet HNHUISecureTextField *passwordTextField;
@property (weak) IBOutlet MPPathControl *keyPathControl;
@property (weak) IBOutlet NSImageView *messageImageView;
@@ -177,4 +184,36 @@
self.messageInfoTextField.hidden = NO;
}
- (NSTouchBar *)makeTouchBar {
NSTouchBar *touchBar = [[NSTouchBar alloc] init];
touchBar.delegate = self;
touchBar.customizationIdentifier = touchBarIdentifier;
NSArray<NSTouchBarItemIdentifier> *defaultItemIdentifiers = @[touchBarShowPasswordIdentifier, touchBarChooseKeyfileIdentifier, NSTouchBarItemIdentifierFlexibleSpace,touchBarUnlockIdentifier];
touchBar.defaultItemIdentifiers = defaultItemIdentifiers;
touchBar.customizationAllowedItemIdentifiers = defaultItemIdentifiers;
return touchBar;
}
- (NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier API_AVAILABLE(macos(10.12.2)) {
if (identifier == touchBarChooseKeyfileIdentifier) {
return [MPTouchBarButtonCreator touchBarButtonWithTitleAndImage:NSLocalizedString(@"TOUCHBAR_CHOOSE_KEYFILE","Touchbar button label for choosing the keyfile") identifier:touchBarChooseKeyfileIdentifier image:[NSImage imageNamed:NSImageNameTouchBarFolderTemplate] target:self.keyPathControl selector:@selector(showOpenPanel:) customizationLabel:NSLocalizedString(@"TOUCHBAR_CHOOSE_KEYFILE","Touchbar button label for choosing the keyfile")];
} else if (identifier == touchBarShowPasswordIdentifier) {
NSTouchBarItem *item = [MPTouchBarButtonCreator touchBarButtonWithTitleAndImage:NSLocalizedString(@"TOUCHBAR_SHOW_PASSWORD","Touchbar button label for showing the password") identifier:touchBarShowPasswordIdentifier image:[NSImage imageNamed:NSImageNameTouchBarQuickLookTemplate] target:self selector:@selector(toggleShowPassword) customizationLabel:NSLocalizedString(@"TOUCHBAR_SHOW_PASSWORD","Touchbar button label for showing the password")];
_showPasswordButton = (NSButton *) item.view;
return item;
} else if (identifier == touchBarUnlockIdentifier) {
return [MPTouchBarButtonCreator touchBarButtonWithImage:[NSImage imageNamed:NSImageNameLockUnlockedTemplate] identifier:touchBarUnlockIdentifier target:self selector:@selector(_submit:) customizationLabel:NSLocalizedString(@"TOUCHBAR_UNLOCK_DATABASE","Touchbar button label for unlocking the database")];
} else {
return nil;
}
}
- (void)toggleShowPassword {
self.showPassword = !self.showPassword;
if (@available(macOS 10.12.2, *)) {
_showPasswordButton.bezelColor = self.showPassword ? [NSColor selectedControlColor] : [NSColor controlColor];
}
}
@end