Merge pull request #8334 from ctrlaltdavid/21015

refresh file dialog when directory content changes
This commit is contained in:
Seth Alves 2016-08-03 08:11:40 -07:00 committed by GitHub
commit cc7322a0de
3 changed files with 34 additions and 1 deletions

View file

@ -87,6 +87,15 @@ ModalWindow {
currentSelection.text = d.capitalizeDrive(helper.urlToPath(initialFolder)); 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(); fileTableView.forceActiveFocus();
} }
@ -343,12 +352,14 @@ ModalWindow {
onFolderChanged: { onFolderChanged: {
if (folder === rootFolder) { if (folder === rootFolder) {
model = driveListModel; model = driveListModel;
helper.monitorDirectory("");
update(); update();
} else { } else {
var needsUpdate = model === driveListModel && folder === folderListModel.folder; var needsUpdate = model === driveListModel && folder === folderListModel.folder;
model = folderListModel; model = folderListModel;
folderListModel.folder = folder; folderListModel.folder = folder;
helper.monitorDirectory(helper.urlToPath(folder));
if (needsUpdate) { if (needsUpdate) {
update(); update();

View file

@ -115,3 +115,15 @@ QList<QUrl> FileDialogHelper::urlToList(const QUrl& url) {
return results; 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);
}
}

View file

@ -9,11 +9,12 @@
#ifndef hifi_ui_FileDialogHelper_h #ifndef hifi_ui_FileDialogHelper_h
#define hifi_ui_FileDialogHelper_h #define hifi_ui_FileDialogHelper_h
#include <QtCore/QFileSystemWatcher>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QStandardPaths> #include <QtCore/QStandardPaths>
#include <QtCore/QUrl>
#include <QtCore/QString> #include <QtCore/QString>
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtCore/QUrl>
class FileDialogHelper : public QObject { class FileDialogHelper : public QObject {
@ -61,6 +62,15 @@ public:
Q_INVOKABLE QList<QUrl> urlToList(const QUrl& url); Q_INVOKABLE QList<QUrl> urlToList(const QUrl& url);
Q_INVOKABLE void openDirectory(const QString& path); Q_INVOKABLE void openDirectory(const QString& path);
Q_INVOKABLE void monitorDirectory(const QString& path);
signals:
void contentsChanged();
private:
QFileSystemWatcher _fsWatcher;
QString _fsWatcherPath;
}; };