mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 01:04:06 +02:00
Open file async implemented
This commit is contained in:
parent
b604b1bbac
commit
ac7aa609f2
3 changed files with 31 additions and 15 deletions
|
@ -6774,12 +6774,15 @@ void Application::openUrl(const QUrl& url) const {
|
|||
|
||||
void Application::loadDialog() {
|
||||
auto scriptEngines = DependencyManager::get<ScriptEngines>();
|
||||
QString fileNameString = OffscreenUi::getOpenFileName(
|
||||
_glWidget, tr("Open Script"), getPreviousScriptLocation(), tr("JavaScript Files (*.js)"));
|
||||
if (!fileNameString.isEmpty() && QFile(fileNameString).exists()) {
|
||||
setPreviousScriptLocation(QFileInfo(fileNameString).absolutePath());
|
||||
DependencyManager::get<ScriptEngines>()->loadScript(fileNameString, true, false, false, true); // Don't load from cache
|
||||
}
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, this, [=] (QString response) {
|
||||
if (!response.isEmpty() && QFile(response).exists()) {
|
||||
setPreviousScriptLocation(QFileInfo(response).absolutePath());
|
||||
DependencyManager::get<ScriptEngines>()->loadScript(response, true, false, false, true); // Don't load from cache
|
||||
}
|
||||
});
|
||||
OffscreenUi::getOpenFileNameAsync(_glWidget, tr("Open Script"), getPreviousScriptLocation(),
|
||||
tr("JavaScript Files (*.js)"));
|
||||
}
|
||||
|
||||
QString Application::getPreviousScriptLocation() {
|
||||
|
|
|
@ -645,6 +645,9 @@ private slots:
|
|||
void onSelectedFile(QVariant file) {
|
||||
_result = file;
|
||||
_finished = true;
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
emit offscreenUi->fileDialogResponse(_result.toUrl().toLocalFile());
|
||||
offscreenUi->removeModalDialog(qobject_cast<QObject*>(this));
|
||||
disconnect(_dialog);
|
||||
}
|
||||
};
|
||||
|
@ -680,7 +683,7 @@ QString OffscreenUi::fileDialog(const QVariantMap& properties) {
|
|||
return result.toUrl().toLocalFile();
|
||||
}
|
||||
|
||||
QQuickItem *OffscreenUi::fileDialogAsync(const QVariantMap& properties) {
|
||||
void OffscreenUi::fileDialogAsync(const QVariantMap& properties) {
|
||||
QVariant buildDialogResult;
|
||||
bool invokeResult;
|
||||
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||
|
@ -699,10 +702,14 @@ QQuickItem *OffscreenUi::fileDialogAsync(const QVariantMap& properties) {
|
|||
|
||||
if (!invokeResult) {
|
||||
qWarning() << "Failed to create file open dialog";
|
||||
return nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
return qvariant_cast<QQuickItem*>(buildDialogResult);
|
||||
FileDialogListener* fileDialogListener = new FileDialogListener(qvariant_cast<QQuickItem*>(buildDialogResult));
|
||||
QObject* fileModalDialog = qobject_cast<QObject*>(fileDialogListener);
|
||||
_modalDialogListeners.push_back(fileModalDialog);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QString OffscreenUi::fileOpenDialog(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) {
|
||||
|
@ -727,7 +734,7 @@ QString OffscreenUi::fileOpenDialog(const QString& caption, const QString& dir,
|
|||
return fileDialog(map);
|
||||
}
|
||||
|
||||
QString OffscreenUi::fileOpenDialogAsync(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) {
|
||||
void OffscreenUi::fileOpenDialogAsync(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QString result;
|
||||
BLOCKING_INVOKE_METHOD(this, "fileOpenDialogAsync",
|
||||
|
@ -737,7 +744,7 @@ QString OffscreenUi::fileOpenDialogAsync(const QString& caption, const QString&
|
|||
Q_ARG(QString, filter),
|
||||
Q_ARG(QString*, selectedFilter),
|
||||
Q_ARG(QFileDialog::Options, options));
|
||||
return result;
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME support returning the selected filter... somehow?
|
||||
|
@ -746,7 +753,7 @@ QString OffscreenUi::fileOpenDialogAsync(const QString& caption, const QString&
|
|||
map.insert("dir", QUrl::fromLocalFile(dir));
|
||||
map.insert("filter", filter);
|
||||
map.insert("options", static_cast<int>(options));
|
||||
return fileDialog(map);
|
||||
fileDialogAsync(map);
|
||||
}
|
||||
|
||||
QString OffscreenUi::fileSaveDialog(const QString& caption, const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options) {
|
||||
|
@ -799,6 +806,10 @@ QString OffscreenUi::getOpenFileName(void* ignored, const QString &caption, cons
|
|||
return DependencyManager::get<OffscreenUi>()->fileOpenDialog(caption, dir, filter, selectedFilter, options);
|
||||
}
|
||||
|
||||
void OffscreenUi::getOpenFileNameAsync(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) {
|
||||
return DependencyManager::get<OffscreenUi>()->fileOpenDialogAsync(caption, dir, filter, selectedFilter, options);
|
||||
}
|
||||
|
||||
QString OffscreenUi::getSaveFileName(void* ignored, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options) {
|
||||
return DependencyManager::get<OffscreenUi>()->fileSaveDialog(caption, dir, filter, selectedFilter, options);
|
||||
}
|
||||
|
|
|
@ -149,14 +149,16 @@ public:
|
|||
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
|
||||
|
||||
Q_INVOKABLE QString fileOpenDialog(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
|
||||
Q_INVOKABLE QString fileOpenDialogAsync(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
|
||||
Q_INVOKABLE void fileOpenDialogAsync(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
|
||||
Q_INVOKABLE QString fileSaveDialog(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
|
||||
Q_INVOKABLE QString existingDirectoryDialog(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
|
||||
|
||||
Q_INVOKABLE QString assetOpenDialog(const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
|
||||
|
||||
// Compatibility with QFileDialog::getOpenFileName
|
||||
static QString getOpenFileName(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
|
||||
static QString getOpenFileName(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
|
||||
static void getOpenFileNameAsync(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
|
||||
|
||||
// Compatibility with QFileDialog::getSaveFileName
|
||||
static QString getSaveFileName(void* ignored, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = 0, QFileDialog::Options options = 0);
|
||||
// Compatibility with QFileDialog::getExistingDirectory
|
||||
|
@ -197,7 +199,7 @@ public slots:
|
|||
|
||||
private:
|
||||
QString fileDialog(const QVariantMap& properties);
|
||||
QQuickItem* fileDialogAsync(const QVariantMap &properties);
|
||||
void fileDialogAsync(const QVariantMap &properties);
|
||||
QString assetDialog(const QVariantMap& properties);
|
||||
|
||||
QQuickItem* _desktop { nullptr };
|
||||
|
|
Loading…
Reference in a new issue