Use last directory if not specified in method call. Default to desktop.
Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -14,6 +14,8 @@ · 13 unmodified lines | ||
| 14 | 14 | #include <QMessageBox> |
| 15 | 15 | #include <QScriptValue> |
| 16 | 16 | |
| 17 | +#include <SettingHandle.h> | |
| 18 | + | |
| 17 | 19 | #include "Application.h" |
| 18 | 20 | #include "DomainHandler.h" |
| 19 | 21 | #include "MainWindow.h" |
| @@ -23,6 +25,10 @@ · 3 unmodified lines | ||
| 23 | 25 | |
| 24 | 26 | #include "WindowScriptingInterface.h" |
| 25 | 27 | |
| 28 | +static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | |
| 29 | +static const QString LAST_BROWSE_LOCATION_SETTING = "LastBrowseLocation"; | |
| 30 | + | |
| 31 | + | |
| 26 | 32 | WindowScriptingInterface::WindowScriptingInterface() { |
| 27 | 33 | const DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler(); |
| 28 | 34 | connect(&domainHandler, &DomainHandler::connectedToDomain, this, &WindowScriptingInterface::domainChanged); |
| @@ -101,6 +107,14 @@ QString fixupPathForMac(const QString& directory) { · 72 unmodified lines | ||
| 101 | 107 | return path; |
| 102 | 108 | } |
| 103 | 109 | |
| 110 | +QString WindowScriptingInterface::getPreviousBrowseLocation() const { | |
| 111 | + return Setting::Handle<QString>(LAST_BROWSE_LOCATION_SETTING, DESKTOP_LOCATION).get(); | |
| 112 | +} | |
| 113 | + | |
| 114 | +void WindowScriptingInterface::setPreviousBrowseLocation(const QString& location) { | |
| 115 | + Setting::Handle<QVariant>(LAST_BROWSE_LOCATION_SETTING).set(location); | |
| 116 | +} | |
| 117 | + | |
| 104 | 118 | /// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current |
| 105 | 119 | /// working directory. |
| 106 | 120 | /// \param const QString& title title of the window |
| @@ -108,8 +122,17 @@ QString fixupPathForMac(const QString& directory) { · 1 unmodified line | ||
| 108 | 122 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` |
| 109 | 123 | /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` |
| 110 | 124 | QScriptValue WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) { |
| 111 | − QString path = fixupPathForMac(directory); | |
| 125 | + QString path = directory; | |
| 126 | + if (path == "") { | |
| 127 | + path = getPreviousBrowseLocation(); | |
| 128 | + } | |
| 129 | +#ifndef Q_OS_WIN | |
| 130 | + path = fixupPathForMac(directory); | |
| 131 | +#endif | |
| 112 | 132 | QString result = OffscreenUi::getOpenFileName(nullptr, title, path, nameFilter); |
| 133 | + if (!result.isEmpty()) { | |
| 134 | + setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | |
| 135 | + } | |
| 113 | 136 | return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); |
| 114 | 137 | } |
| 115 | 138 | |
| @@ -120,8 +143,17 @@ QScriptValue WindowScriptingInterface::browse(const QString& title, const QStrin · 4 unmodified lines | ||
| 120 | 143 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` |
| 121 | 144 | /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` |
| 122 | 145 | QScriptValue WindowScriptingInterface::save(const QString& title, const QString& directory, const QString& nameFilter) { |
| 123 | − QString path = fixupPathForMac(directory); | |
| 146 | + QString path = directory; | |
| 147 | + if (path == "") { | |
| 148 | + path = getPreviousBrowseLocation(); | |
| 149 | + } | |
| 150 | +#ifndef Q_OS_WIN | |
| 151 | + path = fixupPathForMac(directory); | |
| 152 | +#endif | |
| 124 | 153 | QString result = OffscreenUi::getSaveFileName(nullptr, title, path, nameFilter); |
| 154 | + if (!result.isEmpty()) { | |
| 155 | + setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | |
| 156 | + } | |
| 125 | 157 | return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); |
| 126 | 158 | } |
| 127 | 159 | |