From ce838f6b7a3e48ffadf1e0a6633e3bf3b0a27dcf Mon Sep 17 00:00:00 2001 From: Chhom Seng Date: Wed, 1 Jan 2014 18:03:25 -0700 Subject: [PATCH] Implemented context menu validation. --- MacPass/MPEntryViewController.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index 89f6db35..afc15647 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -469,6 +469,23 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; if(![document validateMenuItem:menuItem]) { return NO; } + + // CS: don't know how to iterate through KPKEntry properties to check for blanks so just check the declared properties + KPKEntry *targetEntry = [self _clickedOrSelectedEntry]; + MPActionType actionType = [MPActionHelper typeForAction:[menuItem action]]; + + if (([[targetEntry username] length] == 0) && (actionType == MPActionCopyUsername)) { + return NO; + } + + if (([[targetEntry password] length] == 0) && (actionType == MPActionCopyPassword)) { + return NO; + } + + if (([[targetEntry url] length] == 0) && (actionType == MPActionCopyURL || actionType == MPActionOpenURL)) { + return NO; + } + return YES; /* TODO handle _clickedOrSlectedEnty */ }