Reimplement snapshot dir browser for async

This commit is contained in:
vladest 2017-08-15 15:55:36 +02:00
parent 9aace9e67d
commit e9ed05c3ba
3 changed files with 29 additions and 18 deletions

View file

@ -174,8 +174,7 @@ void WindowScriptingInterface::ensureReticleVisible() const {
/// \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::browseDir(const QString& title, const QString& directory) {
void WindowScriptingInterface::browseDir(const QString& title, const QString& directory) {
ensureReticleVisible();
QString path = directory;
if (path.isEmpty()) {
@ -184,11 +183,19 @@ QScriptValue WindowScriptingInterface::browseDir(const QString& title, const QSt
#ifndef Q_OS_WIN
path = fixupPathForMac(directory);
#endif
QString result = OffscreenUi::getExistingDirectory(nullptr, title, path);
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 browseDirChanged(result);
});
OffscreenUi::getExistingDirectoryAsync(nullptr, title, path);
}
/// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current

View file

@ -53,7 +53,7 @@ public slots:
QScriptValue confirm(const QString& message = "");
QScriptValue prompt(const QString& message = "", const QString& defaultText = "");
CustomPromptResult customPrompt(const QVariant& config);
QScriptValue browseDir(const QString& title = "", const QString& directory = "");
void browseDir(const QString& title = "", const QString& directory = "");
QScriptValue browse(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
QScriptValue save(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
QScriptValue browseAssets(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
@ -87,7 +87,7 @@ signals:
void announcement(const QString& message);
void messageBoxClosed(int id, int button);
void browseDirChanged(QString browseDir);
// triggered when window size or position changes
void geometryChanged(QRect geometry);

View file

@ -120,15 +120,8 @@ function onMessage(message) {
openLoginWindow();
break;
case 'chooseSnapshotLocation':
var snapshotPath = Window.browseDir("Choose Snapshots Directory", "", "");
if (snapshotPath) { // not cancelled
Snapshot.setSnapshotsLocation(snapshotPath);
tablet.emitScriptEvent(JSON.stringify({
type: "snapshot",
action: "snapshotLocationChosen"
}));
}
Window.browseDirChanged.connect(snapshotDirChanged);
Window.browseDir("Choose Snapshots Directory", "", "");
break;
case 'openSettings':
if ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar", false))
@ -579,6 +572,17 @@ function stillSnapshotTaken(pathStillSnapshot, notify) {
});
}
function snapshotDirChanged(snapshotPath) {
Window.browseDirChanged.disconnect(snapshotDirChanged);
if (snapshotPath !== "") { // not cancelled
Snapshot.setSnapshotsLocation(snapshotPath);
tablet.emitScriptEvent(JSON.stringify({
type: "snapshot",
action: "snapshotLocationChosen"
}));
}
}
function processingGifStarted(pathStillSnapshot) {
Window.processingGifStarted.disconnect(processingGifStarted);
Window.processingGifCompleted.connect(processingGifCompleted);