From 7bee5fa2ce5ef7ed3f1da1a336c21a74ceeaec7c Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 25 Nov 2015 12:30:41 +0100 Subject: iOS: filter edit menu actions depending on selection state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiostextresponder.mm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/plugins/platforms/ios') diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm index 434ba2edc6..770dadd3e4 100644 --- a/src/plugins/platforms/ios/qiostextresponder.mm +++ b/src/plugins/platforms/ios/qiostextresponder.mm @@ -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); -- cgit v1.2.3