From 92c83e0fa0c484bad6a6ab9fa4b49e57415d9aa7 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Mon, 11 Dec 2017 17:05:57 +0100 Subject: [PATCH] pressing down on search field will move to entries list --- MacPass/MPToolbarDelegate.h | 2 +- MacPass/MPToolbarDelegate.m | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/MacPass/MPToolbarDelegate.h b/MacPass/MPToolbarDelegate.h index 01ef1473..cedb83b0 100644 --- a/MacPass/MPToolbarDelegate.h +++ b/MacPass/MPToolbarDelegate.h @@ -24,7 +24,7 @@ @class MPDocument; -@interface MPToolbarDelegate : NSObject +@interface MPToolbarDelegate : NSObject @property (weak, readonly) NSSearchField *searchField; @property (weak) NSToolbar *toolbar; diff --git a/MacPass/MPToolbarDelegate.m b/MacPass/MPToolbarDelegate.m index b7e9355d..59816dcb 100644 --- a/MacPass/MPToolbarDelegate.m +++ b/MacPass/MPToolbarDelegate.m @@ -171,7 +171,8 @@ NSString *const MPToolbarItemHistory = @"TOOLBAR_HISTORY"; item.minSize = NSMakeSize(140, 32); item.maxSize = NSMakeSize(240, 32); NSMenu *templateMenu = [self _allocateSearchMenuTemplate]; - [searchField.cell setSearchMenuTemplate:templateMenu]; + searchField.searchMenuTemplate = templateMenu; + ((NSTextField *)searchField).delegate = self; self.searchField = searchField; } else { @@ -224,6 +225,15 @@ NSString *const MPToolbarItemHistory = @"TOOLBAR_HISTORY"; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didEnterSearch:) name:MPDocumentDidEnterSearchNotification object:document]; } +#pragma mark - NSSearchFieldDelegate +- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector { + if(commandSelector == @selector(moveDown:)) { + [[NSApp targetForAction:@selector(focusEntries:) to:nil from:self] focusEntries:self]; + } + return NO; +} + +#pragma mark - Private - (NSString *)_localizedLabelForToolbarItemIdentifier:(NSString *)identifier { static NSDictionary *labelDict; static dispatch_once_t onceToken;