mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:21:16 +02:00
Add Window.browse to scripting environment
This commit is contained in:
parent
76a8afaf88
commit
5a5e628536
2 changed files with 37 additions and 1 deletions
|
@ -9,8 +9,10 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QDir>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
|
@ -43,6 +45,14 @@ QScriptValue WindowScriptingInterface::prompt(const QString& message, const QStr
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QScriptValue WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) {
|
||||||
|
QScriptValue retVal;
|
||||||
|
QMetaObject::invokeMethod(this, "showBrowse", Qt::BlockingQueuedConnection,
|
||||||
|
Q_RETURN_ARG(QScriptValue, retVal),
|
||||||
|
Q_ARG(const QString&, title), Q_ARG(const QString&, directory), Q_ARG(const QString&, nameFilter));
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
/// Display an alert box
|
/// Display an alert box
|
||||||
/// \param const QString& message message to display
|
/// \param const QString& message message to display
|
||||||
/// \return QScriptValue::UndefinedValue
|
/// \return QScriptValue::UndefinedValue
|
||||||
|
@ -76,6 +86,30 @@ QScriptValue WindowScriptingInterface::showPrompt(const QString& message, const
|
||||||
return QScriptValue::NullValue;
|
return QScriptValue::NullValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Display a file dialog. If `directory` is an invalid file or directory the browser will start at the current
|
||||||
|
/// working directory.
|
||||||
|
/// \param const QString& title title of the window
|
||||||
|
/// \param const QString& directory directory to start the file browser at
|
||||||
|
/// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog`
|
||||||
|
/// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue`
|
||||||
|
QScriptValue WindowScriptingInterface::showBrowse(const QString& title, const QString& directory, const QString& nameFilter) {
|
||||||
|
// On OS X `directory` does not work as expected unless a file is included in the path, so we append a bogus
|
||||||
|
// filename if the directory is valid.
|
||||||
|
QString path = "";
|
||||||
|
QFileInfo fileInfo = QFileInfo(directory);
|
||||||
|
if (fileInfo.isDir()) {
|
||||||
|
fileInfo.setFile(directory, "__HIFI_INVALID_FILE__");
|
||||||
|
path = fileInfo.filePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
QFileDialog fileDialog(Application::getInstance()->getWindow(), title, path, nameFilter);
|
||||||
|
fileDialog.setFileMode(QFileDialog::ExistingFile);
|
||||||
|
if (fileDialog.exec()) {
|
||||||
|
return QScriptValue(fileDialog.selectedFiles().first());
|
||||||
|
}
|
||||||
|
return QScriptValue::NullValue;
|
||||||
|
}
|
||||||
|
|
||||||
int WindowScriptingInterface::getInnerWidth() {
|
int WindowScriptingInterface::getInnerWidth() {
|
||||||
return Application::getInstance()->getWindow()->geometry().width();
|
return Application::getInstance()->getWindow()->geometry().width();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,11 +30,13 @@ public slots:
|
||||||
QScriptValue alert(const QString& message = "");
|
QScriptValue alert(const QString& message = "");
|
||||||
QScriptValue confirm(const QString& message = "");
|
QScriptValue confirm(const QString& message = "");
|
||||||
QScriptValue prompt(const QString& message = "", const QString& defaultText = "");
|
QScriptValue prompt(const QString& message = "", const QString& defaultText = "");
|
||||||
|
QScriptValue browse(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
QScriptValue showAlert(const QString& message);
|
QScriptValue showAlert(const QString& message);
|
||||||
QScriptValue showConfirm(const QString& message);
|
QScriptValue showConfirm(const QString& message);
|
||||||
QScriptValue showPrompt(const QString& message, const QString& defaultText);
|
QScriptValue showPrompt(const QString& message, const QString& defaultText);
|
||||||
|
QScriptValue showBrowse(const QString& title, const QString& directory, const QString& nameFilter);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_WindowScriptingInterface_h
|
#endif // hifi_WindowScriptingInterface_h
|
||||||
|
|
Loading…
Reference in a new issue