Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 7 files). Show all
Unified · Split
| @@ -53,6 +53,15 @@ QScriptValue WindowScriptingInterface::browse(const QString& title, const QStrin · 52 unmodified lines | |||
| 53 | return retVal; | 53 | return retVal; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | QScriptValue WindowScriptingInterface::save(const QString& title, const QString& directory, const QString& nameFilter) { | ||
| 57 | QScriptValue retVal; | ||
| 58 | QMetaObject::invokeMethod(this, "showBrowse", Qt::BlockingQueuedConnection, | ||
| 59 | Q_RETURN_ARG(QScriptValue, retVal), | ||
| 60 | Q_ARG(const QString&, title), Q_ARG(const QString&, directory), Q_ARG(const QString&, nameFilter), | ||
| 61 | Q_ARG(QFileDialog::AcceptMode, QFileDialog::AcceptSave)); | ||
| 62 | return retVal; | ||
| 63 | } | ||
| 64 | |||
| 56 | /// Display an alert box | 65 | /// Display an alert box |
| 57 | /// \param const QString& message message to display | 66 | /// \param const QString& message message to display |
| 58 | /// \return QScriptValue::UndefinedValue | 67 | /// \return QScriptValue::UndefinedValue |
| @@ -93,18 +102,29 @@ QScriptValue WindowScriptingInterface::showPrompt(const QString& message, const · 34 unmodified lines | |||
| 93 | /// \param const QString& directory directory to start the file browser at | 102 | /// \param const QString& directory directory to start the file browser at |
| 94 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` | 103 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` |
| 95 | /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` | 104 | /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` |
| 96 | QScriptValue WindowScriptingInterface::showBrowse(const QString& title, const QString& directory, const QString& nameFilter) { | 105 | QScriptValue WindowScriptingInterface::showBrowse(const QString& title, const QString& directory, const QString& nameFilter, |
| 106 | QFileDialog::AcceptMode acceptMode) { | ||
| 97 | // On OS X `directory` does not work as expected unless a file is included in the path, so we append a bogus | 107 | // On OS X `directory` does not work as expected unless a file is included in the path, so we append a bogus |
| 98 | // filename if the directory is valid. | 108 | // filename if the directory is valid. |
| 99 | QString path = ""; | 109 | QString path = ""; |
| 100 | QFileInfo fileInfo = QFileInfo(directory); | 110 | QFileInfo fileInfo = QFileInfo(directory); |
| 111 | qDebug() << "File: " << directory << fileInfo.isFile(); | ||
| 101 | if (fileInfo.isDir()) { | 112 | if (fileInfo.isDir()) { |
| 102 | fileInfo.setFile(directory, "__HIFI_INVALID_FILE__"); | 113 | fileInfo.setFile(directory, "__HIFI_INVALID_FILE__"); |
| 103 | path = fileInfo.filePath(); | 114 | path = fileInfo.filePath(); |
| 104 | } | 115 | } |
| 105 | 116 | ||
| 106 | QFileDialog fileDialog(Application::getInstance()->getWindow(), title, path, nameFilter); | 117 | QFileDialog fileDialog(Application::getInstance()->getWindow(), title, path, nameFilter); |
| 107 | fileDialog.setFileMode(QFileDialog::ExistingFile); | 118 | // fileDialog.setFileMode(QFileDialog::ExistingFile); |
| 119 | fileDialog.setAcceptMode(acceptMode); | ||
| 120 | qDebug() << "Opening!"; | ||
| 121 | QUrl fileUrl(directory); | ||
| 122 | if (acceptMode == QFileDialog::AcceptSave) { | ||
| 123 | fileDialog.setFileMode(QFileDialog::Directory); | ||
| 124 | fileDialog.selectFile(fileUrl.fileName()); | ||
| 125 | // qDebug() << "Setting filename!"; | ||
| 126 | // fileDialog.setLabelText(QFileDialog::FileName, fileUrl.fileName()); | ||
| 127 | } | ||
| 108 | if (fileDialog.exec()) { | 128 | if (fileDialog.exec()) { |
| 109 | return QScriptValue(fileDialog.selectedFiles().first()); | 129 | return QScriptValue(fileDialog.selectedFiles().first()); |
| 110 | } | 130 | } |