Moved constants into MPTouchBarButtonCreator, adjusted naming of constants to current convention

This commit is contained in:
Michael Starke
2019-07-12 13:26:21 +02:00
parent 02840548ba
commit a5c97469eb
4 changed files with 65 additions and 46 deletions

View File

@@ -47,18 +47,6 @@
#import "KeePassKit/KeePassKit.h"
static NSTouchBarCustomizationIdentifier touchBarIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow";
static NSTouchBarItemIdentifier touchBarSearchIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.search";
static NSTouchBarItemIdentifier touchBarEditPopoverIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.editPopover";
static NSTouchBarItemIdentifier touchBarCopyUsernameIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.copyUsername";
static NSTouchBarItemIdentifier touchBarCopyPasswordIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.copyPassword";
static NSTouchBarItemIdentifier touchBarPerformAutotypeIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.performAutotype";
static NSTouchBarItemIdentifier touchBarLockIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.lock";
static NSTouchBarItemIdentifier secondaryTouchBarNewEntryIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.newEntry";
static NSTouchBarItemIdentifier secondaryTouchBarNewGroupIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.newGroup";
static NSTouchBarItemIdentifier secondaryTouchBarDeleteIdentifier = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.delete";
typedef NS_ENUM(NSUInteger, MPAlertContext) {
MPAlertLossySaveWarning,
};
@@ -669,8 +657,8 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
- (NSTouchBar *)makeTouchBar {
NSTouchBar *touchBar = [[NSTouchBar alloc] init];
touchBar.delegate = self;
touchBar.customizationIdentifier = touchBarIdentifier;
NSArray<NSTouchBarItemIdentifier> *defaultItemIdentifiers = @[touchBarSearchIdentifier, touchBarEditPopoverIdentifier, touchBarCopyUsernameIdentifier, touchBarCopyPasswordIdentifier, touchBarPerformAutotypeIdentifier, NSTouchBarItemIdentifierFlexibleSpace, touchBarLockIdentifier];
touchBar.customizationIdentifier = MPTouchBarCustomizationIdentifierDocument;
NSArray<NSTouchBarItemIdentifier> *defaultItemIdentifiers = @[MPTouchBarItemIdentifierSearch, MPTouchBarItemIdentifierEditPopover, MPTouchBarItemIdentifierCopyUsername, MPTouchBarItemIdentifierCopyPassword, MPTouchBarItemIdentifierPerformAutotype, NSTouchBarItemIdentifierFlexibleSpace, MPTouchBarItemIdentifierLock];
touchBar.defaultItemIdentifiers = defaultItemIdentifiers;
touchBar.customizationAllowedItemIdentifiers = defaultItemIdentifiers;
return touchBar;
@@ -678,74 +666,74 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
- (NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier API_AVAILABLE(macos(10.12.2)) {
#pragma mark primary touchbar elements
if([identifier isEqualToString:touchBarSearchIdentifier]) {
if([identifier isEqualToString:MPTouchBarItemIdentifierSearch]) {
return [MPTouchBarButtonCreator touchBarButtonWithImage:[NSImage imageNamed:NSImageNameTouchBarSearchTemplate]
identifier:touchBarSearchIdentifier
identifier:MPTouchBarItemIdentifierSearch
target:self
selector:@selector(focusSearchField)
customizationLabel:NSLocalizedString(@"TOUCHBAR_SEARCH","Touchbar button label for searching the database")];
}
if([identifier isEqualToString:touchBarEditPopoverIdentifier]) {
if([identifier isEqualToString:MPTouchBarItemIdentifierEditPopover]) {
NSTouchBar *secondaryTouchBar = [[NSTouchBar alloc] init];
secondaryTouchBar.delegate = self;
secondaryTouchBar.defaultItemIdentifiers = @[secondaryTouchBarNewEntryIdentifier, secondaryTouchBarNewGroupIdentifier, secondaryTouchBarDeleteIdentifier];
secondaryTouchBar.defaultItemIdentifiers = @[MPTouchBarItemIdentifierNewEntry, MPTouchBarItemIdentifierNewGroup, MPTouchBarItemIdentifierDelete];
return [MPTouchBarButtonCreator popoverTouchBarButton:NSLocalizedString(@"TOUCHBAR_EDIT","Touchbar button label for opening the popover to edit")
identifier:touchBarEditPopoverIdentifier
identifier:MPTouchBarItemIdentifierEditPopover
popoverTouchBar:secondaryTouchBar
customizationLabel:NSLocalizedString(@"TOUCHBAR_EDIT","Touchbar button label for opening the popover to edit")];
}
if([identifier isEqualToString:touchBarCopyUsernameIdentifier]) {
if([identifier isEqualToString:MPTouchBarItemIdentifierCopyUsername]) {
return [MPTouchBarButtonCreator touchBarButtonWithTitle:NSLocalizedString(@"TOUCHBAR_COPY_USERNAME","Touchbar button label for copying the username")
identifier:touchBarCopyUsernameIdentifier
identifier:MPTouchBarItemIdentifierCopyUsername
target:self
selector:@selector(copyUsername:)
customizationLabel:NSLocalizedString(@"TOUCHBAR_COPY_USERNAME","Touchbar button label for copying the username")];
}
if([identifier isEqualToString:touchBarCopyPasswordIdentifier]) {
if([identifier isEqualToString:MPTouchBarItemIdentifierCopyPassword]) {
return [MPTouchBarButtonCreator touchBarButtonWithTitle:NSLocalizedString(@"TOUCHBAR_COPY_PASSWORD","Touchbar button label for copying the password")
identifier:touchBarCopyPasswordIdentifier
identifier:MPTouchBarItemIdentifierCopyPassword
target:self
selector:@selector(copyPassword:)
customizationLabel:NSLocalizedString(@"TOUCHBAR_COPY_PASSWORD","Touchbar button label for copying the password")];
}
if([identifier isEqualToString:touchBarPerformAutotypeIdentifier]) {
if([identifier isEqualToString:MPTouchBarItemIdentifierPerformAutotype]) {
return [MPTouchBarButtonCreator touchBarButtonWithTitle:NSLocalizedString(@"TOUCHBAR_PERFORM_AUTOTYPE","Touchbar button label for performing autotype")
identifier:touchBarPerformAutotypeIdentifier
identifier:MPTouchBarItemIdentifierPerformAutotype
target:self
selector:@selector(performAutotypeForEntry:)
customizationLabel:NSLocalizedString(@"TOUCHBAR_PERFORM_AUTOTYPE","Touchbar button label for performing autotype")];
}
if([identifier isEqualToString:touchBarLockIdentifier]) {
if([identifier isEqualToString:MPTouchBarItemIdentifierLock]) {
return [MPTouchBarButtonCreator touchBarButtonWithImage:[NSImage imageNamed:NSImageNameLockUnlockedTemplate]
identifier:touchBarLockIdentifier
identifier:MPTouchBarItemIdentifierLock
target:self
selector:@selector(lock:)
customizationLabel:NSLocalizedString(@"TOUCHBAR_LOCK_DATABASE","Touchbar button label for locking the database")];
}
#pragma mark secondary/popover touchbar elements
if([identifier isEqualToString:secondaryTouchBarNewEntryIdentifier]) {
if([identifier isEqualToString:MPTouchBarItemIdentifierNewEntry]) {
return [MPTouchBarButtonCreator touchBarButtonWithTitleAndImage:NSLocalizedString(@"TOUCHBAR_NEW_ENTRY","Touchbar button label for creating a new item")
identifier:secondaryTouchBarNewEntryIdentifier
identifier:MPTouchBarItemIdentifierNewEntry
image:[MPIconHelper icon:MPIconAddEntry]
target:self
selector:@selector(createEntry:)
customizationLabel:NSLocalizedString(@"TOUCHBAR_NEW_ENTRY","Touchbar button label for creating a new item")];
}
if([identifier isEqualToString:secondaryTouchBarNewGroupIdentifier]) {
if([identifier isEqualToString:MPTouchBarItemIdentifierNewGroup]) {
return [MPTouchBarButtonCreator touchBarButtonWithTitleAndImage:NSLocalizedString(@"TOUCHBAR_NEW_GROUP","Touchbar button label for creating a new group")
identifier:secondaryTouchBarNewGroupIdentifier
identifier:MPTouchBarItemIdentifierNewGroup
image:[MPIconHelper icon:MPIconAddFolder]
target:self
selector:@selector(createGroup:)
customizationLabel:NSLocalizedString(@"TOUCHBAR_NEW_GROUP","Touchbar button label for creating a new group")];
}
if([identifier isEqualToString:secondaryTouchBarDeleteIdentifier]) {
if([identifier isEqualToString:MPTouchBarItemIdentifierDelete]) {
return [MPTouchBarButtonCreator touchBarButtonWithTitleAndImageAndColor:NSLocalizedString(@"TOUCHBAR_DELETE","Touchbar button label for deleting elements")
identifier:secondaryTouchBarDeleteIdentifier
identifier:MPTouchBarItemIdentifierDelete
image:[MPIconHelper icon:MPIconTrash]
color:NSColor.systemRedColor
target:self

View File

@@ -32,11 +32,6 @@
#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;
@@ -188,22 +183,22 @@ static NSTouchBarItemIdentifier touchBarUnlockIdentifier = @"com.hicknhacksoftwa
- (NSTouchBar *)makeTouchBar {
NSTouchBar *touchBar = [[NSTouchBar alloc] init];
touchBar.delegate = self;
touchBar.customizationIdentifier = touchBarIdentifier;
NSArray<NSTouchBarItemIdentifier> *defaultItemIdentifiers = @[touchBarShowPasswordIdentifier, touchBarChooseKeyfileIdentifier, NSTouchBarItemIdentifierFlexibleSpace,touchBarUnlockIdentifier];
touchBar.customizationIdentifier = MPTouchBarCustomizationIdentifierPasswordInput;
NSArray<NSTouchBarItemIdentifier> *defaultItemIdentifiers = @[MPTouchBarItemIdentifierShowPassword, MPTouchBarItemIdentifierChooseKeyfile, NSTouchBarItemIdentifierFlexibleSpace,MPTouchBarItemIdentifierUnlock];
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")];
if (identifier == MPTouchBarItemIdentifierChooseKeyfile) {
return [MPTouchBarButtonCreator touchBarButtonWithTitleAndImage:NSLocalizedString(@"TOUCHBAR_CHOOSE_KEYFILE","Touchbar button label for choosing the keyfile") identifier:MPTouchBarItemIdentifierChooseKeyfile 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 == MPTouchBarItemIdentifierShowPassword) {
NSTouchBarItem *item = [MPTouchBarButtonCreator touchBarButtonWithTitleAndImage:NSLocalizedString(@"TOUCHBAR_SHOW_PASSWORD","Touchbar button label for showing the password") identifier:MPTouchBarItemIdentifierShowPassword 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 if (identifier == MPTouchBarItemIdentifierUnlock) {
return [MPTouchBarButtonCreator touchBarButtonWithImage:[NSImage imageNamed:NSImageNameLockUnlockedTemplate] identifier:MPTouchBarItemIdentifierUnlock target:self selector:@selector(_submit:) customizationLabel:NSLocalizedString(@"TOUCHBAR_UNLOCK_DATABASE","Touchbar button label for unlocking the database")];
} else {
return nil;
}

View File

@@ -9,6 +9,24 @@
@interface MPTouchBarButtonCreator: NSObject
APPKIT_EXTERN NSTouchBarCustomizationIdentifier MPTouchBarCustomizationIdentifierPasswordInput;
APPKIT_EXTERN NSTouchBarItemIdentifier MPTouchBarItemIdentifierChooseKeyfile;
APPKIT_EXTERN NSTouchBarItemIdentifier MPTouchBarItemIdentifierShowPassword;
APPKIT_EXTERN NSTouchBarItemIdentifier MPTouchBarItemIdentifierUnlock;
APPKIT_EXTERN NSTouchBarCustomizationIdentifier MPTouchBarCustomizationIdentifierDocument;
APPKIT_EXTERN NSTouchBarItemIdentifier MPTouchBarItemIdentifierSearch;
APPKIT_EXTERN NSTouchBarItemIdentifier MPTouchBarItemIdentifierEditPopover;
APPKIT_EXTERN NSTouchBarItemIdentifier MPTouchBarItemIdentifierCopyUsername;
APPKIT_EXTERN NSTouchBarItemIdentifier MPTouchBarItemIdentifierCopyPassword;
APPKIT_EXTERN NSTouchBarItemIdentifier MPTouchBarItemIdentifierPerformAutotype;
APPKIT_EXTERN NSTouchBarItemIdentifier MPTouchBarItemIdentifierLock;
APPKIT_EXTERN NSTouchBarItemIdentifier MPTouchBarItemIdentifierNewEntry;
APPKIT_EXTERN NSTouchBarItemIdentifier MPTouchBarItemIdentifierNewGroup;
APPKIT_EXTERN NSTouchBarItemIdentifier MPTouchBarItemIdentifierDelete;
+ (NSTouchBarItem *)touchBarButtonWithTitle:(NSString *)title identifier:(NSTouchBarItemIdentifier)identifier target:(id)target selector:(SEL)selector customizationLabel:(NSString *)customizationLabel API_AVAILABLE(macos(10.12.2));
+ (NSTouchBarItem *)touchBarButtonWithTitleAndImage:(NSString *)title identifier:(NSTouchBarItemIdentifier)identifier image:(NSImage *)image target:(id)target selector:(SEL)selector customizationLabel:(NSString *)customizationLabel API_AVAILABLE(macos(10.12.2));

View File

@@ -8,6 +8,24 @@
#import "MPTouchBarButtonCreator.h"
NSTouchBarCustomizationIdentifier MPTouchBarCustomizationIdentifierPasswordInput = @"com.hicknhacksoftware.MacPass.TouchBar.passwordInput";
NSTouchBarItemIdentifier MPTouchBarItemIdentifierChooseKeyfile = @"com.hicknhacksoftware.MacPass.TouchBar.passwordInput.chooseKeyfile";
NSTouchBarItemIdentifier MPTouchBarItemIdentifierShowPassword = @"com.hicknhacksoftware.MacPass.TouchBar.passwordInput.showPassword";
NSTouchBarItemIdentifier MPTouchBarItemIdentifierUnlock = @"com.hicknhacksoftware.MacPass.TouchBar.passwordInput.unlock";
NSTouchBarCustomizationIdentifier MPTouchBarCustomizationIdentifierDocument = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow";
NSTouchBarItemIdentifier MPTouchBarItemIdentifierSearch = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.search";
NSTouchBarItemIdentifier MPTouchBarItemIdentifierEditPopover = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.editPopover";
NSTouchBarItemIdentifier MPTouchBarItemIdentifierCopyUsername = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.copyUsername";
NSTouchBarItemIdentifier MPTouchBarItemIdentifierCopyPassword = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.copyPassword";
NSTouchBarItemIdentifier MPTouchBarItemIdentifierPerformAutotype = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.performAutotype";
NSTouchBarItemIdentifier MPTouchBarItemIdentifierLock = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.lock";
NSTouchBarItemIdentifier MPTouchBarItemIdentifierNewEntry = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.newEntry";
NSTouchBarItemIdentifier MPTouchBarItemIdentifierNewGroup = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.newGroup";
NSTouchBarItemIdentifier MPTouchBarItemIdentifierDelete = @"com.hicknhacksoftware.MacPass.TouchBar.documentWindow.delete";
@implementation MPTouchBarButtonCreator
+ (NSTouchBarItem *)touchBarButtonWithTitle:(NSString *)title identifier:(NSTouchBarItemIdentifier)identifier target:(id)target selector:(SEL)selector customizationLabel:(NSString *)customizationLabel API_AVAILABLE(macos(10.12.2)){