From e222ebf37905a2233d52788c96c5bd6b7d37b475 Mon Sep 17 00:00:00 2001 From: michael starke Date: Tue, 18 Mar 2014 03:12:24 +0100 Subject: [PATCH] fixed #157. cmd+delete now triggers the delete action --- MacPass/MPActionHelper.h | 6 ++++++ MacPass/MPActionHelper.m | 11 +++++++++++ MacPass/MPContextMenuHelper.m | 2 +- MacPass/MPEntryViewController.m | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/MacPass/MPActionHelper.h b/MacPass/MPActionHelper.h index fb79d526..25ae8642 100644 --- a/MacPass/MPActionHelper.h +++ b/MacPass/MPActionHelper.h @@ -44,5 +44,11 @@ typedef NS_ENUM(NSUInteger, MPActionType) { * @return MPActionTpype for action, if no match was found MPUnknownAction is returned */ + (MPActionType)typeForAction:(SEL)action; +/** + * Returns the key equivalent for the given action type + * @param type Action to get the equivalent for + * @return NSString containing the key equivalent for this action. If none is present, an empty NString is returned + */ ++ (NSString *)keyEquivalentForAction:(MPActionType)type; @end diff --git a/MacPass/MPActionHelper.m b/MacPass/MPActionHelper.m index 6d81f121..2b8c98e6 100644 --- a/MacPass/MPActionHelper.m +++ b/MacPass/MPActionHelper.m @@ -42,6 +42,17 @@ return NSSelectorFromString(actionDict[@(type)]); } ++ (NSString *)keyEquivalentForAction:(MPActionType)type { + static NSDictionary *keyEquivalentDictionary; + static unichar backspaceCharacter = NSBackspaceCharacter; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + keyEquivalentDictionary = @{ @(MPActionDelete): [[NSString alloc] initWithCharacters:&backspaceCharacter length:1] }; + }); + NSString *keyEquivalent = keyEquivalentDictionary[@(type)]; + return keyEquivalent ? keyEquivalent : @""; +} + + (MPActionType)typeForAction:(SEL)action { NSString *selectorString = NSStringFromSelector(action); NSArray *selectors = [[self _actionDictionary] allValues]; diff --git a/MacPass/MPContextMenuHelper.m b/MacPass/MPContextMenuHelper.m index d1d1eaa0..d1fb6597 100644 --- a/MacPass/MPContextMenuHelper.m +++ b/MacPass/MPContextMenuHelper.m @@ -56,7 +56,7 @@ static void MPContextmenuHelperBeginSection(NSMutableArray *items) { if(insertDelete) { NSMenuItem *delete = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"DELETE", @"") action:[MPActionHelper actionOfType:MPActionDelete] - keyEquivalent:@""]; + keyEquivalent:[MPActionHelper keyEquivalentForAction:MPActionDelete]]; [items addObject:delete]; } diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index c540d133..ef41b396 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -308,7 +308,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; MPDocument *document = [notification object]; if(!document.selectedGroup) { - /* No group, this only can happen in filtering, just return */ + /* TODO: handle deleted item */ return; } /*