mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 00:10:52 +02:00
Remember last directory used for Window.browse() and Window.save()
Use last directory if not specified in method call. Default to desktop.
This commit is contained in:
parent
cf6945b403
commit
58f89c88a2
3 changed files with 39 additions and 4 deletions
|
@ -14,6 +14,8 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QScriptValue>
|
#include <QScriptValue>
|
||||||
|
|
||||||
|
#include <SettingHandle.h>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "DomainHandler.h"
|
#include "DomainHandler.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
@ -23,6 +25,10 @@
|
||||||
|
|
||||||
#include "WindowScriptingInterface.h"
|
#include "WindowScriptingInterface.h"
|
||||||
|
|
||||||
|
static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||||
|
static const QString LAST_BROWSE_LOCATION_SETTING = "LastBrowseLocation";
|
||||||
|
|
||||||
|
|
||||||
WindowScriptingInterface::WindowScriptingInterface() {
|
WindowScriptingInterface::WindowScriptingInterface() {
|
||||||
const DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
|
const DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
|
||||||
connect(&domainHandler, &DomainHandler::connectedToDomain, this, &WindowScriptingInterface::domainChanged);
|
connect(&domainHandler, &DomainHandler::connectedToDomain, this, &WindowScriptingInterface::domainChanged);
|
||||||
|
@ -101,6 +107,14 @@ QString fixupPathForMac(const QString& directory) {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString WindowScriptingInterface::getPreviousBrowseLocation() const {
|
||||||
|
return Setting::Handle<QString>(LAST_BROWSE_LOCATION_SETTING, DESKTOP_LOCATION).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowScriptingInterface::setPreviousBrowseLocation(const QString& location) {
|
||||||
|
Setting::Handle<QVariant>(LAST_BROWSE_LOCATION_SETTING).set(location);
|
||||||
|
}
|
||||||
|
|
||||||
/// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current
|
/// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current
|
||||||
/// working directory.
|
/// working directory.
|
||||||
/// \param const QString& title title of the window
|
/// \param const QString& title title of the window
|
||||||
|
@ -108,8 +122,17 @@ QString fixupPathForMac(const QString& directory) {
|
||||||
/// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog`
|
/// \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`
|
/// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue`
|
||||||
QScriptValue WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) {
|
QScriptValue WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) {
|
||||||
QString path = fixupPathForMac(directory);
|
QString path = directory;
|
||||||
|
if (path == "") {
|
||||||
|
path = getPreviousBrowseLocation();
|
||||||
|
}
|
||||||
|
#ifndef Q_OS_WIN
|
||||||
|
path = fixupPathForMac(directory);
|
||||||
|
#endif
|
||||||
QString result = OffscreenUi::getOpenFileName(nullptr, title, path, nameFilter);
|
QString result = OffscreenUi::getOpenFileName(nullptr, title, path, nameFilter);
|
||||||
|
if (!result.isEmpty()) {
|
||||||
|
setPreviousBrowseLocation(QFileInfo(result).absolutePath());
|
||||||
|
}
|
||||||
return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result);
|
return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,8 +143,17 @@ QScriptValue WindowScriptingInterface::browse(const QString& title, const QStrin
|
||||||
/// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog`
|
/// \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`
|
/// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue`
|
||||||
QScriptValue WindowScriptingInterface::save(const QString& title, const QString& directory, const QString& nameFilter) {
|
QScriptValue WindowScriptingInterface::save(const QString& title, const QString& directory, const QString& nameFilter) {
|
||||||
QString path = fixupPathForMac(directory);
|
QString path = directory;
|
||||||
|
if (path == "") {
|
||||||
|
path = getPreviousBrowseLocation();
|
||||||
|
}
|
||||||
|
#ifndef Q_OS_WIN
|
||||||
|
path = fixupPathForMac(directory);
|
||||||
|
#endif
|
||||||
QString result = OffscreenUi::getSaveFileName(nullptr, title, path, nameFilter);
|
QString result = OffscreenUi::getSaveFileName(nullptr, title, path, nameFilter);
|
||||||
|
if (!result.isEmpty()) {
|
||||||
|
setPreviousBrowseLocation(QFileInfo(result).absolutePath());
|
||||||
|
}
|
||||||
return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result);
|
return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,10 @@ signals:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
WebWindowClass* doCreateWebWindow(const QString& title, const QString& url, int width, int height);
|
WebWindowClass* doCreateWebWindow(const QString& title, const QString& url, int width, int height);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString getPreviousBrowseLocation() const;
|
||||||
|
void setPreviousBrowseLocation(const QString& location);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_WindowScriptingInterface_h
|
#endif // hifi_WindowScriptingInterface_h
|
||||||
|
|
|
@ -1221,8 +1221,7 @@ function handeMenuEvent(menuItem) {
|
||||||
if (!selectionManager.hasSelection()) {
|
if (!selectionManager.hasSelection()) {
|
||||||
Window.alert("No entities have been selected.");
|
Window.alert("No entities have been selected.");
|
||||||
} else {
|
} else {
|
||||||
var filename = "entities__" + Window.location.hostname + ".svo.json";
|
var filename = Window.save("Select Where to Save", "", "*.json")
|
||||||
filename = Window.save("Select Where to Save", filename, "*.json")
|
|
||||||
if (filename) {
|
if (filename) {
|
||||||
var success = Clipboard.exportEntities(filename, selectionManager.selections);
|
var success = Clipboard.exportEntities(filename, selectionManager.selections);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
|
Loading…
Reference in a new issue