iOS: filter edit menu actions depending on selection state

When showing an edit menu on iOS, UIKit will always populate
the menu with actions according to what the current first
responder supports. But it doesn't make sense to show all the
actions every time the menu opens, so introduce some filtering
depending on selection state.

Change-Id: I943a09928233a3a10de003fe15ed8fd8b6fc1e18
Reviewed-by: Markus Goetz (Woboq GmbH) <markus@woboq.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
bb10
Richard Moe Gustavsen 2015-11-25 12:30:41 +01:00 committed by Simon Hausmann
parent e98922bbde
commit 7bee5fa2ce
1 changed files with 26 additions and 0 deletions

View File

@ -364,6 +364,32 @@
[self sendKeyPressRelease:key modifiers:modifiers];
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
bool isEditAction = (action == @selector(cut:)
|| action == @selector(copy:)
|| action == @selector(paste:)
|| action == @selector(delete:)
|| action == @selector(toggleBoldface:)
|| action == @selector(toggleItalics:)
|| action == @selector(toggleUnderline:)
|| action == @selector(undo)
|| action == @selector(redo));
bool isSelectAction = (action == @selector(select:)
|| action == @selector(selectAll:)
|| action == @selector(paste:)
|| action == @selector(undo)
|| action == @selector(redo));
const bool unknownAction = !isEditAction && !isSelectAction;
const bool hasSelection = ![self selectedTextRange].empty;
if (unknownAction)
return [super canPerformAction:action withSender:sender];
return (hasSelection && isEditAction) || (!hasSelection && isSelectAction);
}
- (void)cut:(id)sender
{
Q_UNUSED(sender);