Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 2 files). Show all
Unified · Split
| @@ -9,8 +9,10 @@ · 8 unmodified lines | |||
| 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html |
| 10 | // | 10 | // |
| 11 | 11 | ||
| 12 | #include <QMessageBox> | 12 | #include <QDir> |
| 13 | #include <QFileDialog> | ||
| 13 | #include <QInputDialog> | 14 | #include <QInputDialog> |
| 15 | #include <QMessageBox> | ||
| 14 | 16 | ||
| 15 | #include "Application.h" | 17 | #include "Application.h" |
| 16 | #include "Menu.h" | 18 | #include "Menu.h" |
| @@ -43,6 +45,14 @@ QScriptValue WindowScriptingInterface::prompt(const QString& message, const QStr · 26 unmodified lines | |||
| 43 | return retVal; | 45 | return retVal; |
| 44 | } | 46 | } |
| 45 | 47 | ||
| 48 | QScriptValue WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) { | ||
| 49 | QScriptValue retVal; | ||
| 50 | QMetaObject::invokeMethod(this, "showBrowse", Qt::BlockingQueuedConnection, | ||
| 51 | Q_RETURN_ARG(QScriptValue, retVal), | ||
| 52 | Q_ARG(const QString&, title), Q_ARG(const QString&, directory), Q_ARG(const QString&, nameFilter)); | ||
| 53 | return retVal; | ||
| 54 | } | ||
| 55 | |||
| 46 | /// Display an alert box | 56 | /// Display an alert box |
| 47 | /// \param const QString& message message to display | 57 | /// \param const QString& message message to display |
| 48 | /// \return QScriptValue::UndefinedValue | 58 | /// \return QScriptValue::UndefinedValue |
| @@ -76,6 +86,30 @@ QScriptValue WindowScriptingInterface::showPrompt(const QString& message, const · 27 unmodified lines | |||
| 76 | return QScriptValue::NullValue; | 86 | return QScriptValue::NullValue; |
| 77 | } | 87 | } |
| 78 | 88 | ||
| 89 | /// Display a file dialog. If `directory` is an invalid file or directory the browser will start at the current | ||
| 90 | /// working directory. | ||
| 91 | /// \param const QString& title title of the window | ||
| 92 | /// \param const QString& directory directory to start the file browser at | ||
| 93 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` | ||
| 94 | /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` | ||
| 95 | QScriptValue WindowScriptingInterface::showBrowse(const QString& title, const QString& directory, const QString& nameFilter) { | ||
| 96 | // On OS X `directory` does not work as expected unless a file is included in the path, so we append a bogus | ||
| 97 | // filename if the directory is valid. | ||
| 98 | QString path = ""; | ||
| 99 | QFileInfo fileInfo = QFileInfo(directory); | ||
| 100 | if (fileInfo.isDir()) { | ||
| 101 | fileInfo.setFile(directory, "__HIFI_INVALID_FILE__"); | ||
| 102 | path = fileInfo.filePath(); | ||
| 103 | } | ||
| 104 | |||
| 105 | QFileDialog fileDialog(Application::getInstance()->getWindow(), title, path, nameFilter); | ||
| 106 | fileDialog.setFileMode(QFileDialog::ExistingFile); | ||
| 107 | if (fileDialog.exec()) { | ||
| 108 | return QScriptValue(fileDialog.selectedFiles().first()); | ||
| 109 | } | ||
| 110 | return QScriptValue::NullValue; | ||
| 111 | } | ||
| 112 | |||
| 79 | int WindowScriptingInterface::getInnerWidth() { | 113 | int WindowScriptingInterface::getInnerWidth() { |
| 80 | return Application::getInstance()->getWindow()->geometry().width(); | 114 | return Application::getInstance()->getWindow()->geometry().width(); |
| 81 | } | 115 | } |