mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 16:55:07 +02:00
Merge pull request #8334 from ctrlaltdavid/21015
refresh file dialog when directory content changes
This commit is contained in:
commit
cc7322a0de
3 changed files with 34 additions and 1 deletions
|
@ -87,6 +87,15 @@ ModalWindow {
|
|||
currentSelection.text = d.capitalizeDrive(helper.urlToPath(initialFolder));
|
||||
}
|
||||
|
||||
helper.contentsChanged.connect(function() {
|
||||
if (folderListModel) {
|
||||
// Make folderListModel refresh.
|
||||
var save = folderListModel.folder;
|
||||
folderListModel.folder = "";
|
||||
folderListModel.folder = save;
|
||||
}
|
||||
});
|
||||
|
||||
fileTableView.forceActiveFocus();
|
||||
}
|
||||
|
||||
|
@ -343,12 +352,14 @@ ModalWindow {
|
|||
onFolderChanged: {
|
||||
if (folder === rootFolder) {
|
||||
model = driveListModel;
|
||||
helper.monitorDirectory("");
|
||||
update();
|
||||
} else {
|
||||
var needsUpdate = model === driveListModel && folder === folderListModel.folder;
|
||||
|
||||
model = folderListModel;
|
||||
folderListModel.folder = folder;
|
||||
helper.monitorDirectory(helper.urlToPath(folder));
|
||||
|
||||
if (needsUpdate) {
|
||||
update();
|
||||
|
|
|
@ -115,3 +115,15 @@ QList<QUrl> FileDialogHelper::urlToList(const QUrl& url) {
|
|||
return results;
|
||||
}
|
||||
|
||||
void FileDialogHelper::monitorDirectory(const QString& path) {
|
||||
if (!_fsWatcherPath.isEmpty()) {
|
||||
_fsWatcher.removePath(_fsWatcherPath);
|
||||
_fsWatcherPath = "";
|
||||
}
|
||||
|
||||
if (!path.isEmpty()) {
|
||||
_fsWatcher.addPath(path);
|
||||
_fsWatcherPath = path;
|
||||
connect(&_fsWatcher, &QFileSystemWatcher::directoryChanged, this, &FileDialogHelper::contentsChanged);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,12 @@
|
|||
#ifndef hifi_ui_FileDialogHelper_h
|
||||
#define hifi_ui_FileDialogHelper_h
|
||||
|
||||
#include <QtCore/QFileSystemWatcher>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QStandardPaths>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QUrl>
|
||||
|
||||
|
||||
class FileDialogHelper : public QObject {
|
||||
|
@ -61,6 +62,15 @@ public:
|
|||
Q_INVOKABLE QList<QUrl> urlToList(const QUrl& url);
|
||||
|
||||
Q_INVOKABLE void openDirectory(const QString& path);
|
||||
|
||||
Q_INVOKABLE void monitorDirectory(const QString& path);
|
||||
|
||||
signals:
|
||||
void contentsChanged();
|
||||
|
||||
private:
|
||||
QFileSystemWatcher _fsWatcher;
|
||||
QString _fsWatcherPath;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue