forked from quickshell/quickshell
core/reloader: fix file watcher compatibility with vim
This commit is contained in:
parent
4e92d82992
commit
7ad3671dd1
|
@ -4,6 +4,8 @@
|
||||||
#include <qcontainerfwd.h>
|
#include <qcontainerfwd.h>
|
||||||
#include <qcoreapplication.h>
|
#include <qcoreapplication.h>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
|
#include <qdir.h>
|
||||||
|
#include <qfileinfo.h>
|
||||||
#include <qfilesystemwatcher.h>
|
#include <qfilesystemwatcher.h>
|
||||||
#include <qhash.h>
|
#include <qhash.h>
|
||||||
#include <qlogging.h>
|
#include <qlogging.h>
|
||||||
|
@ -117,13 +119,21 @@ void EngineGeneration::setWatchingFiles(bool watching) {
|
||||||
|
|
||||||
for (auto& file: this->scanner.scannedFiles) {
|
for (auto& file: this->scanner.scannedFiles) {
|
||||||
this->watcher->addPath(file);
|
this->watcher->addPath(file);
|
||||||
|
this->watcher->addPath(QFileInfo(file).dir().absolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
this->watcher,
|
this->watcher,
|
||||||
&QFileSystemWatcher::fileChanged,
|
&QFileSystemWatcher::fileChanged,
|
||||||
this,
|
this,
|
||||||
&EngineGeneration::filesChanged
|
&EngineGeneration::onFileChanged
|
||||||
|
);
|
||||||
|
|
||||||
|
QObject::connect(
|
||||||
|
this->watcher,
|
||||||
|
&QFileSystemWatcher::directoryChanged,
|
||||||
|
this,
|
||||||
|
&EngineGeneration::onDirectoryChanged
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -134,6 +144,24 @@ void EngineGeneration::setWatchingFiles(bool watching) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EngineGeneration::onFileChanged(const QString& name) {
|
||||||
|
if (!this->watcher->files().contains(name)) {
|
||||||
|
this->deletedWatchedFiles.push_back(name);
|
||||||
|
} else {
|
||||||
|
emit this->filesChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EngineGeneration::onDirectoryChanged() {
|
||||||
|
// try to find any files that were just deleted from a replace operation
|
||||||
|
for (auto& file: this->deletedWatchedFiles) {
|
||||||
|
if (QFileInfo(file).exists()) {
|
||||||
|
emit this->filesChanged();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EngineGeneration::registerIncubationController(QQmlIncubationController* controller) {
|
void EngineGeneration::registerIncubationController(QQmlIncubationController* controller) {
|
||||||
auto* obj = dynamic_cast<QObject*>(controller);
|
auto* obj = dynamic_cast<QObject*>(controller);
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
ShellRoot* root = nullptr;
|
ShellRoot* root = nullptr;
|
||||||
SingletonRegistry singletonRegistry;
|
SingletonRegistry singletonRegistry;
|
||||||
QFileSystemWatcher* watcher = nullptr;
|
QFileSystemWatcher* watcher = nullptr;
|
||||||
|
QVector<QString> deletedWatchedFiles;
|
||||||
DelayedQmlIncubationController delayedIncubationController;
|
DelayedQmlIncubationController delayedIncubationController;
|
||||||
bool reloadComplete = false;
|
bool reloadComplete = false;
|
||||||
|
|
||||||
|
@ -50,6 +51,8 @@ signals:
|
||||||
void reloadFinished();
|
void reloadFinished();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void onFileChanged(const QString& name);
|
||||||
|
void onDirectoryChanged();
|
||||||
void incubationControllerDestroyed();
|
void incubationControllerDestroyed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue