Utilize Q_FORWARD_DECLARE_OBJC_CLASS in QCocoaFileDialogHelper.
Change-Id: I94ae91ac8fb625de4a328c6628ce0ab45919708f Reviewed-by: Jake Petroules <jake.petroules@petroules.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
This commit is contained in:
parent
50430a8392
commit
3b1de67fde
@ -37,6 +37,8 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <qpa/qplatformdialoghelper.h>
|
#include <qpa/qplatformdialoghelper.h>
|
||||||
|
|
||||||
|
Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate));
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QFileDialog;
|
class QFileDialog;
|
||||||
@ -73,7 +75,7 @@ public:
|
|||||||
void QNSOpenSavePanelDelegate_filterSelected(int menuIndex);
|
void QNSOpenSavePanelDelegate_filterSelected(int menuIndex);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void *mDelegate;
|
QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *mDelegate;
|
||||||
QUrl mDir;
|
QUrl mDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -77,8 +77,6 @@ QT_USE_NAMESPACE
|
|||||||
|
|
||||||
typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions;
|
typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions;
|
||||||
|
|
||||||
@class QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate);
|
|
||||||
|
|
||||||
@interface QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate)
|
@interface QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate)
|
||||||
: NSObject<NSOpenSavePanelDelegate>
|
: NSObject<NSOpenSavePanelDelegate>
|
||||||
{
|
{
|
||||||
@ -568,7 +566,7 @@ QCocoaFileDialogHelper::~QCocoaFileDialogHelper()
|
|||||||
if (!mDelegate)
|
if (!mDelegate)
|
||||||
return;
|
return;
|
||||||
QCocoaAutoReleasePool pool;
|
QCocoaAutoReleasePool pool;
|
||||||
[reinterpret_cast<QNSOpenSavePanelDelegate *>(mDelegate) release];
|
[mDelegate release];
|
||||||
mDelegate = 0;
|
mDelegate = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -604,18 +602,16 @@ extern void qt_mac_to_pascal_string(QString s, Str255 str, TextEncoding encoding
|
|||||||
|
|
||||||
void QCocoaFileDialogHelper::setDirectory(const QUrl &directory)
|
void QCocoaFileDialogHelper::setDirectory(const QUrl &directory)
|
||||||
{
|
{
|
||||||
QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate);
|
if (mDelegate)
|
||||||
if (delegate)
|
[mDelegate->mSavePanel setDirectoryURL:[NSURL fileURLWithPath:QCFString::toNSString(directory.toLocalFile())]];
|
||||||
[delegate->mSavePanel setDirectoryURL:[NSURL fileURLWithPath:QCFString::toNSString(directory.toLocalFile())]];
|
|
||||||
else
|
else
|
||||||
mDir = directory;
|
mDir = directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl QCocoaFileDialogHelper::directory() const
|
QUrl QCocoaFileDialogHelper::directory() const
|
||||||
{
|
{
|
||||||
QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate);
|
if (mDelegate) {
|
||||||
if (delegate) {
|
QString path = QCFString::toQString([[mDelegate->mSavePanel directoryURL] path]).normalized(QString::NormalizationForm_C);
|
||||||
QString path = QCFString::toQString([[delegate->mSavePanel directoryURL] path]).normalized(QString::NormalizationForm_C);
|
|
||||||
return QUrl::fromLocalFile(path);
|
return QUrl::fromLocalFile(path);
|
||||||
}
|
}
|
||||||
return mDir;
|
return mDir;
|
||||||
@ -634,25 +630,23 @@ void QCocoaFileDialogHelper::selectFile(const QUrl &filename)
|
|||||||
|
|
||||||
QList<QUrl> QCocoaFileDialogHelper::selectedFiles() const
|
QList<QUrl> QCocoaFileDialogHelper::selectedFiles() const
|
||||||
{
|
{
|
||||||
QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate);
|
if (mDelegate)
|
||||||
if (delegate)
|
return [mDelegate selectedFiles];
|
||||||
return [delegate selectedFiles];
|
|
||||||
return QList<QUrl>();
|
return QList<QUrl>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCocoaFileDialogHelper::setFilter()
|
void QCocoaFileDialogHelper::setFilter()
|
||||||
{
|
{
|
||||||
QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate);
|
if (!mDelegate)
|
||||||
if (!delegate)
|
|
||||||
return;
|
return;
|
||||||
const SharedPointerFileDialogOptions &opts = options();
|
const SharedPointerFileDialogOptions &opts = options();
|
||||||
[delegate->mSavePanel setTitle:QCFString::toNSString(opts->windowTitle())];
|
[mDelegate->mSavePanel setTitle:QCFString::toNSString(opts->windowTitle())];
|
||||||
if (opts->isLabelExplicitlySet(QFileDialogOptions::Accept))
|
if (opts->isLabelExplicitlySet(QFileDialogOptions::Accept))
|
||||||
[delegate->mSavePanel setPrompt:[delegate strip:opts->labelText(QFileDialogOptions::Accept)]];
|
[mDelegate->mSavePanel setPrompt:[mDelegate strip:opts->labelText(QFileDialogOptions::Accept)]];
|
||||||
if (opts->isLabelExplicitlySet(QFileDialogOptions::FileName))
|
if (opts->isLabelExplicitlySet(QFileDialogOptions::FileName))
|
||||||
[delegate->mSavePanel setNameFieldLabel:[delegate strip:opts->labelText(QFileDialogOptions::FileName)]];
|
[mDelegate->mSavePanel setNameFieldLabel:[mDelegate strip:opts->labelText(QFileDialogOptions::FileName)]];
|
||||||
|
|
||||||
[delegate updateProperties];
|
[mDelegate updateProperties];
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCocoaFileDialogHelper::selectNameFilter(const QString &filter)
|
void QCocoaFileDialogHelper::selectNameFilter(const QString &filter)
|
||||||
@ -661,22 +655,20 @@ void QCocoaFileDialogHelper::selectNameFilter(const QString &filter)
|
|||||||
return;
|
return;
|
||||||
const int index = options()->nameFilters().indexOf(filter);
|
const int index = options()->nameFilters().indexOf(filter);
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate);
|
if (!mDelegate) {
|
||||||
if (!delegate) {
|
|
||||||
options()->setInitiallySelectedNameFilter(filter);
|
options()->setInitiallySelectedNameFilter(filter);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
[delegate->mPopUpButton selectItemAtIndex:index];
|
[mDelegate->mPopUpButton selectItemAtIndex:index];
|
||||||
[delegate filterChanged:nil];
|
[mDelegate filterChanged:nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QCocoaFileDialogHelper::selectedNameFilter() const
|
QString QCocoaFileDialogHelper::selectedNameFilter() const
|
||||||
{
|
{
|
||||||
QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate);
|
if (!mDelegate)
|
||||||
if (!delegate)
|
|
||||||
return options()->initiallySelectedNameFilter();
|
return options()->initiallySelectedNameFilter();
|
||||||
int index = [delegate->mPopUpButton indexOfSelectedItem];
|
int index = [mDelegate->mPopUpButton indexOfSelectedItem];
|
||||||
if (index >= options()->nameFilters().count())
|
if (index >= options()->nameFilters().count())
|
||||||
return QString();
|
return QString();
|
||||||
return index != -1 ? options()->nameFilters().at(index) : QString();
|
return index != -1 ? options()->nameFilters().at(index) : QString();
|
||||||
@ -723,13 +715,12 @@ void QCocoaFileDialogHelper::createNSOpenSavePanelDelegate()
|
|||||||
bool QCocoaFileDialogHelper::showCocoaFilePanel(Qt::WindowModality windowModality, QWindow *parent)
|
bool QCocoaFileDialogHelper::showCocoaFilePanel(Qt::WindowModality windowModality, QWindow *parent)
|
||||||
{
|
{
|
||||||
createNSOpenSavePanelDelegate();
|
createNSOpenSavePanelDelegate();
|
||||||
QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate);
|
if (!mDelegate)
|
||||||
if (!delegate)
|
|
||||||
return false;
|
return false;
|
||||||
if (windowModality == Qt::NonModal)
|
if (windowModality == Qt::NonModal)
|
||||||
[delegate showModelessPanel];
|
[mDelegate showModelessPanel];
|
||||||
else if (windowModality == Qt::WindowModal && parent)
|
else if (windowModality == Qt::WindowModal && parent)
|
||||||
[delegate showWindowModalSheet:parent];
|
[mDelegate showWindowModalSheet:parent];
|
||||||
// no need to show a Qt::ApplicationModal dialog here, since it will be done in _q_platformRunNativeAppModalPanel()
|
// no need to show a Qt::ApplicationModal dialog here, since it will be done in _q_platformRunNativeAppModalPanel()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -741,8 +732,7 @@ bool QCocoaFileDialogHelper::hideCocoaFilePanel()
|
|||||||
// open regarding whether or not to go native:
|
// open regarding whether or not to go native:
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate);
|
[mDelegate closePanel];
|
||||||
[delegate closePanel];
|
|
||||||
// Even when we hide it, we are still using a
|
// Even when we hide it, we are still using a
|
||||||
// native dialog, so return true:
|
// native dialog, so return true:
|
||||||
return true;
|
return true;
|
||||||
@ -756,8 +746,7 @@ void QCocoaFileDialogHelper::exec()
|
|||||||
// yet been reactivated (regardless if [NSApp run] is still on the stack)),
|
// yet been reactivated (regardless if [NSApp run] is still on the stack)),
|
||||||
// showing a native modal dialog will fail.
|
// showing a native modal dialog will fail.
|
||||||
QCocoaAutoReleasePool pool;
|
QCocoaAutoReleasePool pool;
|
||||||
QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate);
|
if ([mDelegate runApplicationModalPanel])
|
||||||
if ([delegate runApplicationModalPanel])
|
|
||||||
emit accept();
|
emit accept();
|
||||||
else
|
else
|
||||||
emit reject();
|
emit reject();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user