From 3e8ebea95b634c7ded9ee0b884768155e9e7f686 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 23 Jun 2017 09:08:19 +0200 Subject: [PATCH] Cocoa: Reset the target + action for a menuitem after showing a dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To make it more reliable and efficient we now do the reverse of what we are doing when redirecting the items. This will ensure that the actions are correctly reset to the original target and action. The original approach of updateMenubarImmediately() was not always doing this and it also does other unnecessary things as a result when all we need is to just reset the things we changed. Change-Id: Icefa38d47ec9434894f05caeed75fbf8bdfecb93 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoamenubar.mm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index 82c405baa66..4cdf004dd1b 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -303,7 +303,23 @@ void QCocoaMenuBar::resetKnownMenuItemsToQt() // Undo the effect of redirectKnownMenuItemsToFirstResponder(): // set the menu items' actions to itemFired and their targets to // the QCocoaMenuDelegate. - updateMenuBarImmediately(); + foreach (QCocoaMenuBar *mb, static_menubars) { + foreach (QCocoaMenu *m, mb->m_menus) { + foreach (QCocoaMenuItem *i, m->items()) { + switch (i->effectiveRole()) { + case QPlatformMenuItem::CutRole: + case QPlatformMenuItem::CopyRole: + case QPlatformMenuItem::PasteRole: + case QPlatformMenuItem::SelectAllRole: + [i->nsItem() setTarget:m->nsMenu().delegate]; + [i->nsItem() setAction:@selector(itemFired:)]; + break; + default: + break; + } + } + } + } } void QCocoaMenuBar::updateMenuBarImmediately()