summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2014-03-31 14:17:29 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-07 08:30:24 +0200
commitb5eb850e0deb61ff71e26a5a2d0e070b91306aa2 (patch)
tree957dcbb14ee657afd74348cd4fd0179650401e5b /src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
parenta7f98a7ac01a9faa08d1119cf4d5550c50e00005 (diff)
OSX: add several menuitem roles to support menu shortcuts in dialogs
Now menu items and key shortcuts for Cut, Copy, Paste and Select All work in the standard ways in dialogs such as the file dialog, provided that the corresponding QActions have been created and added to the menu. This depends on new roles to identify each menu item which is so broadly applicable that it should work even when a native widget has focus; but the role will be auto-detected, just as we were already doing for application menu items such as Quit, About and Preferences. When the QFileDialog is opened, it will call redirectKnownMenuItemsToFirstResponder() which will make only those "special" menu items have the standard actions and nil targets. When the dialog is dismissed, those NSMenuItems must be reverted by calling resetKnownMenuItemsToQt(), because to invoke a QAction, the NSMenuItem's action should be itemFired and the target should be the QCocoaMenuDelegate. Task-number: QTBUG-17291 Change-Id: I501375ca6fa13fac75d4b4fdcede993ec2329cc7 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
index 8728ab8764..2b7b8109ad 100644
--- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
@@ -52,6 +52,7 @@
#include <private/qguiapplication_p.h>
#include "qt_mac_p.h"
#include "qcocoahelpers.h"
+#include "qcocoamenubar.h"
#include <qregexp.h>
#include <qbuffer.h>
#include <qdebug.h>
@@ -225,6 +226,7 @@ static QString strippedText(QString s)
|| [self panel:nil shouldShowFilename:filepath];
[self updateProperties];
+ QCocoaMenuBar::redirectKnownMenuItemsToFirstResponder();
[mOpenPanel setAllowedFileTypes:nil];
[mSavePanel setNameFieldStringValue:selectable ? QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.fileName()) : @""];
@@ -250,7 +252,9 @@ static QString strippedText(QString s)
// cleanup of modal sessions. Do this before showing the native dialog, otherwise it will
// close down during the cleanup.
qApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
+ QCocoaMenuBar::redirectKnownMenuItemsToFirstResponder();
mReturnCode = [mSavePanel runModal];
+ QCocoaMenuBar::resetKnownMenuItemsToQt();
QAbstractEventDispatcher::instance()->interrupt();
return (mReturnCode == NSOKButton);
@@ -269,6 +273,7 @@ static QString strippedText(QString s)
|| [self panel:nil shouldShowFilename:filepath];
[self updateProperties];
+ QCocoaMenuBar::redirectKnownMenuItemsToFirstResponder();
[mSavePanel setDirectoryURL: [NSURL fileURLWithPath:mCurrentDir]];
[mSavePanel setNameFieldStringValue:selectable ? QCFString::toNSString(info.fileName()) : @""];
@@ -583,6 +588,7 @@ void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_selectionChanged(const QSt
void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_panelClosed(bool accepted)
{
+ QCocoaMenuBar::resetKnownMenuItemsToQt();
if (accepted) {
emit accept();
} else {