diff --git a/src/core/generation.cpp b/src/core/generation.cpp index 77e4a9cb..a0b465f8 100644 --- a/src/core/generation.cpp +++ b/src/core/generation.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include #include @@ -117,13 +119,21 @@ void EngineGeneration::setWatchingFiles(bool watching) { for (auto& file: this->scanner.scannedFiles) { this->watcher->addPath(file); + this->watcher->addPath(QFileInfo(file).dir().absolutePath()); } QObject::connect( this->watcher, &QFileSystemWatcher::fileChanged, this, - &EngineGeneration::filesChanged + &EngineGeneration::onFileChanged + ); + + QObject::connect( + this->watcher, + &QFileSystemWatcher::directoryChanged, + this, + &EngineGeneration::onDirectoryChanged ); } } 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) { auto* obj = dynamic_cast(controller); diff --git a/src/core/generation.hpp b/src/core/generation.hpp index 11ebf0be..3c8f3997 100644 --- a/src/core/generation.hpp +++ b/src/core/generation.hpp @@ -40,6 +40,7 @@ public: ShellRoot* root = nullptr; SingletonRegistry singletonRegistry; QFileSystemWatcher* watcher = nullptr; + QVector deletedWatchedFiles; DelayedQmlIncubationController delayedIncubationController; bool reloadComplete = false; @@ -50,6 +51,8 @@ signals: void reloadFinished(); private slots: + void onFileChanged(const QString& name); + void onDirectoryChanged(); void incubationControllerDestroyed(); private: