mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
Reworked WindowScriptingInterface browse method for async methods
This commit is contained in:
parent
8afdb27c1b
commit
273261ee57
3 changed files with 42 additions and 32 deletions
|
@ -203,8 +203,7 @@ void WindowScriptingInterface::browseDir(const QString& title, const QString& di
|
|||
/// \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::browse(const QString& title, const QString& directory, const QString& nameFilter) {
|
||||
void WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) {
|
||||
ensureReticleVisible();
|
||||
QString path = directory;
|
||||
if (path.isEmpty()) {
|
||||
|
@ -213,11 +212,19 @@ QScriptValue WindowScriptingInterface::browse(const QString& title, const QStrin
|
|||
#ifndef Q_OS_WIN
|
||||
path = fixupPathForMac(directory);
|
||||
#endif
|
||||
QString result = OffscreenUi::getOpenFileName(nullptr, title, path, nameFilter);
|
||||
if (!result.isEmpty()) {
|
||||
setPreviousBrowseLocation(QFileInfo(result).absolutePath());
|
||||
}
|
||||
return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result);
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
|
||||
this, [=] (QString result) {
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
|
||||
this, nullptr);
|
||||
if (!result.isEmpty()) {
|
||||
setPreviousBrowseLocation(QFileInfo(result).absolutePath());
|
||||
}
|
||||
emit openFileChanged(result);
|
||||
});
|
||||
|
||||
OffscreenUi::getOpenFileNameAsync(nullptr, title, path, nameFilter);
|
||||
}
|
||||
|
||||
/// Display a save file dialog. If `directory` is an invalid file or directory the browser will start at the current
|
||||
|
|
|
@ -54,7 +54,7 @@ public slots:
|
|||
QScriptValue prompt(const QString& message = "", const QString& defaultText = "");
|
||||
CustomPromptResult customPrompt(const QVariant& config);
|
||||
void browseDir(const QString& title = "", const QString& directory = "");
|
||||
QScriptValue browse(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
|
||||
void browse(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
|
||||
void save(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
|
||||
void browseAssets(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
|
||||
void showAssetServer(const QString& upload = "");
|
||||
|
@ -89,7 +89,8 @@ signals:
|
|||
void messageBoxClosed(int id, int button);
|
||||
void browseDirChanged(QString browseDir);
|
||||
void assetsDirChanged(QString assetsDir);
|
||||
void saveFileChanged(QString saveFile);
|
||||
void saveFileChanged(QString filename);
|
||||
void openFileChanged(QString filename);
|
||||
|
||||
// triggered when window size or position changes
|
||||
void geometryChanged(QRect geometry);
|
||||
|
|
|
@ -431,17 +431,8 @@ var toolBar = (function () {
|
|||
});
|
||||
|
||||
addButton("importEntitiesButton", "assets-01.svg", function() {
|
||||
var importURL = null;
|
||||
var fullPath = Window.browse("Select Model to Import", "", "*.json");
|
||||
if (fullPath) {
|
||||
importURL = "file:///" + fullPath;
|
||||
}
|
||||
if (importURL) {
|
||||
if (!isActive && (Entities.canRez() && Entities.canRezTmp())) {
|
||||
toolBar.toggle();
|
||||
}
|
||||
importSVO(importURL);
|
||||
}
|
||||
Window.openFileChanged.connect(onFileOpenChanged);
|
||||
Window.browse("Select Model to Import", "", "*.json");
|
||||
});
|
||||
|
||||
addButton("openAssetBrowserButton", "assets-01.svg", function() {
|
||||
|
@ -1468,6 +1459,20 @@ function onFileSaveChanged(filename) {
|
|||
}
|
||||
}
|
||||
|
||||
function onFileOpenChanged(filename) {
|
||||
Window.openFileChanged.disconnect(onFileOpenChanged);
|
||||
var importURL = null;
|
||||
if (filename !== "") {
|
||||
importURL = "file:///" + filename;
|
||||
}
|
||||
if (importURL) {
|
||||
if (!isActive && (Entities.canRez() && Entities.canRezTmp())) {
|
||||
toolBar.toggle();
|
||||
}
|
||||
importSVO(importURL);
|
||||
}
|
||||
}
|
||||
|
||||
function handeMenuEvent(menuItem) {
|
||||
if (menuItem === "Allow Selecting of Small Models") {
|
||||
allowSmallModels = Menu.isOptionChecked("Allow Selecting of Small Models");
|
||||
|
@ -1489,21 +1494,18 @@ function handeMenuEvent(menuItem) {
|
|||
Window.save("Select Where to Save", "", "*.json");
|
||||
}
|
||||
} else if (menuItem === "Import Entities" || menuItem === "Import Entities from URL") {
|
||||
var importURL = null;
|
||||
if (menuItem === "Import Entities") {
|
||||
var fullPath = Window.browse("Select Model to Import", "", "*.json");
|
||||
if (fullPath) {
|
||||
importURL = "file:///" + fullPath;
|
||||
}
|
||||
Window.openFileChanged.connect(onFileOpenChanged);
|
||||
Window.browse("Select Model to Import", "", "*.json");
|
||||
} else {
|
||||
importURL = Window.prompt("URL of SVO to import", "");
|
||||
}
|
||||
|
||||
if (importURL) {
|
||||
if (!isActive && (Entities.canRez() && Entities.canRezTmp())) {
|
||||
toolBar.toggle();
|
||||
var importURL = Window.prompt("URL of SVO to import", "");
|
||||
if (importURL) {
|
||||
if (!isActive && (Entities.canRez() && Entities.canRezTmp())) {
|
||||
toolBar.toggle();
|
||||
}
|
||||
importSVO(importURL);
|
||||
}
|
||||
importSVO(importURL);
|
||||
|
||||
}
|
||||
} else if (menuItem === "Entity List...") {
|
||||
entityListTool.toggleVisible();
|
||||
|
|
Loading…
Reference in a new issue