From 2381acfde94ce99f57a688c88be3dc4ba01b3b65 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Wed, 10 Jul 2019 12:27:34 +0200 Subject: [PATCH] Codestyle. Do not use == for string compare --- MacPass/MPDocumentWindowController.h | 3 +- MacPass/MPDocumentWindowController.m | 93 +++++++++++++++++++++------- 2 files changed, 73 insertions(+), 23 deletions(-) diff --git a/MacPass/MPDocumentWindowController.h b/MacPass/MPDocumentWindowController.h index 92b55dce..e02521b4 100644 --- a/MacPass/MPDocumentWindowController.h +++ b/MacPass/MPDocumentWindowController.h @@ -39,8 +39,7 @@ @property (readonly, strong) MPInspectorViewController *inspectorViewController; @property (readonly, strong) MPToolbarDelegate *toolbarDelegate; -#pragma mark Search -- (NSSearchField *)searchField; +@property (readonly, nonatomic, strong) NSSearchField *searchField; - (void)showEntries; - (void)showPasswordInput; diff --git a/MacPass/MPDocumentWindowController.m b/MacPass/MPDocumentWindowController.m index 6af5a923..10cb573b 100644 --- a/MacPass/MPDocumentWindowController.m +++ b/MacPass/MPDocumentWindowController.m @@ -677,37 +677,88 @@ 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 == touchBarSearchIdentifier) { - return [MPTouchBarButtonCreator touchBarButtonWithImage:[NSImage imageNamed:NSImageNameTouchBarSearchTemplate] identifier:touchBarSearchIdentifier target:self selector:@selector(focusSearchField) customizationLabel:NSLocalizedString(@"TOUCHBAR_SEARCH","Touchbar button label for searching the database")]; - } else if (identifier == touchBarEditPopoverIdentifier) { +#pragma mark primary touchbar elements + if([identifier isEqualToString:touchBarSearchIdentifier]) { + return [MPTouchBarButtonCreator touchBarButtonWithImage:[NSImage imageNamed:NSImageNameTouchBarSearchTemplate] + identifier:touchBarSearchIdentifier + target:self + selector:@selector(focusSearchField) + customizationLabel:NSLocalizedString(@"TOUCHBAR_SEARCH","Touchbar button label for searching the database")]; + } + + if(identifier == touchBarEditPopoverIdentifier) { NSTouchBar *secondaryTouchBar = [[NSTouchBar alloc] init]; secondaryTouchBar.delegate = self; secondaryTouchBar.defaultItemIdentifiers = @[secondaryTouchBarNewEntryIdentifier, secondaryTouchBarNewGroupIdentifier, secondaryTouchBarDeleteIdentifier]; - return [MPTouchBarButtonCreator popoverTouchBarButton:NSLocalizedString(@"TOUCHBAR_EDIT","Touchbar button label for opening the popover to edit") identifier:touchBarEditPopoverIdentifier popoverTouchBar:secondaryTouchBar customizationLabel:NSLocalizedString(@"TOUCHBAR_EDIT","Touchbar button label for opening the popover to edit")]; - } else if (identifier == touchBarCopyUsernameIdentifier) { - return [MPTouchBarButtonCreator touchBarButtonWithTitle:NSLocalizedString(@"TOUCHBAR_COPY_USERNAME","Touchbar button label for copying the username") identifier:touchBarCopyUsernameIdentifier target:self selector:@selector(copyUsername:) customizationLabel:NSLocalizedString(@"TOUCHBAR_COPY_USERNAME","Touchbar button label for copying the username")]; - } else if (identifier == touchBarCopyPasswordIdentifier) { - return [MPTouchBarButtonCreator touchBarButtonWithTitle:NSLocalizedString(@"TOUCHBAR_COPY_PASSWORD","Touchbar button label for copying the password") identifier:touchBarCopyPasswordIdentifier target:self selector:@selector(copyPassword:) customizationLabel:NSLocalizedString(@"TOUCHBAR_COPY_PASSWORD","Touchbar button label for copying the password")]; - } else if (identifier == touchBarPerformAutotypeIdentifier) { - return [MPTouchBarButtonCreator touchBarButtonWithTitle:NSLocalizedString(@"TOUCHBAR_PERFORM_AUTOTYPE","Touchbar button label for performing autotype") identifier:touchBarPerformAutotypeIdentifier target:self selector:@selector(performAutotypeForEntry:) customizationLabel:NSLocalizedString(@"TOUCHBAR_PERFORM_AUTOTYPE","Touchbar button label for performing autotype")]; - } else if (identifier == touchBarLockIdentifier) { - return [MPTouchBarButtonCreator touchBarButtonWithImage:[NSImage imageNamed:NSImageNameLockUnlockedTemplate] identifier:touchBarLockIdentifier target:self selector:@selector(lock:) customizationLabel:NSLocalizedString(@"TOUCHBAR_LOCK_DATABASE","Touchbar button label for locking the database")]; + return [MPTouchBarButtonCreator popoverTouchBarButton:NSLocalizedString(@"TOUCHBAR_EDIT","Touchbar button label for opening the popover to edit") + identifier:touchBarEditPopoverIdentifier + popoverTouchBar:secondaryTouchBar + customizationLabel:NSLocalizedString(@"TOUCHBAR_EDIT","Touchbar button label for opening the popover to edit")]; + } + + if(identifier == touchBarCopyUsernameIdentifier) { + return [MPTouchBarButtonCreator touchBarButtonWithTitle:NSLocalizedString(@"TOUCHBAR_COPY_USERNAME","Touchbar button label for copying the username") + identifier:touchBarCopyUsernameIdentifier + target:self + selector:@selector(copyUsername:) + customizationLabel:NSLocalizedString(@"TOUCHBAR_COPY_USERNAME","Touchbar button label for copying the username")]; + } + + if (identifier == touchBarCopyPasswordIdentifier) { + return [MPTouchBarButtonCreator touchBarButtonWithTitle:NSLocalizedString(@"TOUCHBAR_COPY_PASSWORD","Touchbar button label for copying the password") + identifier:touchBarCopyPasswordIdentifier + target:self + selector:@selector(copyPassword:) + customizationLabel:NSLocalizedString(@"TOUCHBAR_COPY_PASSWORD","Touchbar button label for copying the password")]; + } + + if (identifier == touchBarPerformAutotypeIdentifier) { + return [MPTouchBarButtonCreator touchBarButtonWithTitle:NSLocalizedString(@"TOUCHBAR_PERFORM_AUTOTYPE","Touchbar button label for performing autotype") + identifier:touchBarPerformAutotypeIdentifier + target:self + selector:@selector(performAutotypeForEntry:) + customizationLabel:NSLocalizedString(@"TOUCHBAR_PERFORM_AUTOTYPE","Touchbar button label for performing autotype")]; + } + else if (identifier == touchBarLockIdentifier) { + return [MPTouchBarButtonCreator touchBarButtonWithImage:[NSImage imageNamed:NSImageNameLockUnlockedTemplate] + identifier:touchBarLockIdentifier + target:self + selector:@selector(lock:) + customizationLabel:NSLocalizedString(@"TOUCHBAR_LOCK_DATABASE","Touchbar button label for locking the database")]; } #pragma mark secondary/popover touchbar elements - else if (identifier == secondaryTouchBarNewEntryIdentifier) { - return [MPTouchBarButtonCreator touchBarButtonWithTitleAndImage:NSLocalizedString(@"TOUCHBAR_NEW_ENTRY","Touchbar button label for creating a new item") identifier:secondaryTouchBarNewEntryIdentifier image:[MPIconHelper icon:MPIconAddEntry] target:self selector:@selector(createEntry:) customizationLabel:NSLocalizedString(@"TOUCHBAR_NEW_ENTRY","Touchbar button label for creating a new item")]; - } else if (identifier == secondaryTouchBarNewGroupIdentifier) { - return [MPTouchBarButtonCreator touchBarButtonWithTitleAndImage:NSLocalizedString(@"TOUCHBAR_NEW_GROUP","Touchbar button label for creating a new group") identifier:secondaryTouchBarNewGroupIdentifier image:[MPIconHelper icon:MPIconAddFolder] target:self selector:@selector(createGroup:) customizationLabel:NSLocalizedString(@"TOUCHBAR_NEW_GROUP","Touchbar button label for creating a new group")]; - } else if (identifier == secondaryTouchBarDeleteIdentifier) { - return [MPTouchBarButtonCreator touchBarButtonWithTitleAndImageAndColor:NSLocalizedString(@"TOUCHBAR_DELETE","Touchbar button label for deleting elements") identifier:secondaryTouchBarDeleteIdentifier image:[MPIconHelper icon:MPIconTrash] color:[NSColor systemRedColor] target:self selector:@selector(delete:) customizationLabel:NSLocalizedString(@"TOUCHBAR_DELETE","Touchbar button label for deleting elements")]; - } else { + else if(identifier == secondaryTouchBarNewEntryIdentifier) { + return [MPTouchBarButtonCreator touchBarButtonWithTitleAndImage:NSLocalizedString(@"TOUCHBAR_NEW_ENTRY","Touchbar button label for creating a new item") + identifier:secondaryTouchBarNewEntryIdentifier + image:[MPIconHelper icon:MPIconAddEntry] + target:self + selector:@selector(createEntry:) + customizationLabel:NSLocalizedString(@"TOUCHBAR_NEW_ENTRY","Touchbar button label for creating a new item")]; + } + else if (identifier == secondaryTouchBarNewGroupIdentifier) { + return [MPTouchBarButtonCreator touchBarButtonWithTitleAndImage:NSLocalizedString(@"TOUCHBAR_NEW_GROUP","Touchbar button label for creating a new group") + identifier:secondaryTouchBarNewGroupIdentifier + image:[MPIconHelper icon:MPIconAddFolder] + target:self + selector:@selector(createGroup:) + customizationLabel:NSLocalizedString(@"TOUCHBAR_NEW_GROUP","Touchbar button label for creating a new group")]; + } + else if (identifier == secondaryTouchBarDeleteIdentifier) { + return [MPTouchBarButtonCreator touchBarButtonWithTitleAndImageAndColor:NSLocalizedString(@"TOUCHBAR_DELETE","Touchbar button label for deleting elements") + identifier:secondaryTouchBarDeleteIdentifier + image:[MPIconHelper icon:MPIconTrash] + color:NSColor.systemRedColor + target:self + selector:@selector(delete:) + customizationLabel:NSLocalizedString(@"TOUCHBAR_DELETE","Touchbar button label for deleting elements")]; + } + else { return nil; } } - (void)focusSearchField { - [self.window makeFirstResponder:[self searchField]]; + [self.window makeFirstResponder:self.searchField]; } @end