I've been working on it for a long time, and tried following two methods.However, neither succeeds.
subclassing
NSSecureTextField
and overriding-(BOOL)becomeFirstResponder
and-(void)textDidEndEditing:
.-(BOOL) becomeFirstResponder { NSMenu *mainMenu = [[NSApplication sharedApplication]mainMenu]; NSMenu *appMenu = [[mainMenu itemAtIndex:2]submenu]; NSLog(@"%@", [appMenu title]); for (NSMenuItem *item in [appMenu itemArray]) { if ([[item title] isEqual: @"Paste"]) { NSLog(@"%@", [item title]); [item setEnabled:NO]; } } return [super becomeFirstResponder]; } - (void)textDidEndEditing:(NSNotification *)notification { NSMenu *mainMenu = [[NSApplication sharedApplication]mainMenu]; NSMenu *appMenu = [[mainMenu itemAtIndex:2]submenu]; NSLog(@"%@", [appMenu title]); for (NSMenuItem *item in [appMenu itemArray]) { if ([[item title] isEqual: @"Paste"]) { NSLog(@"%@", [item title]); [item setEnabled:YES]; } } }
adding protocol
NSUserInterfaceValidation
to a subclass ofNSSecureTextField
(Maybe it's not the correct target to implement this protocol,because breakpoints in this function would never be triggered).- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)anItem { SEL theAction = [anItem action]; if (theAction == @selector(paste:)) { return NO; } return [super validateUserInterfaceItem:anItem]; }