Fix scripts.inc file watches accumulating

This commit is contained in:
GriffinR
2025-06-09 12:02:56 -04:00
parent a3d3a6c176
commit 6648fa33b1
3 changed files with 7 additions and 7 deletions

View File

@@ -87,6 +87,7 @@ public:
QStringList getScriptLabels(Event::Group group = Event::Group::None);
QString getScriptsFilepath() const;
void openScript(const QString &label);
void invalidateScripts();
static QString getJsonFilepath(const QString &mapName);
QString getJsonFilepath() const { return getJsonFilepath(m_name); }
@@ -144,8 +145,6 @@ private:
QPointer<QUndoStack> m_editHistory;
QPointer<QFileSystemWatcher> m_scriptFileWatcher;
void invalidateScripts();
signals:
void modified();
void scriptsModified();

View File

@@ -143,6 +143,7 @@ void Map::setSharedScriptsMap(const QString &sharedScriptsMap) {
void Map::invalidateScripts() {
m_scriptsLoaded = false;
m_scriptFileWatcher->removePaths(m_scriptFileWatcher->files());
emit scriptsModified();
}
@@ -151,7 +152,6 @@ QStringList Map::getScriptLabels(Event::Group group) {
const QString scriptsFilepath = getScriptsFilepath();
QString error;
m_scriptLabels = ParseUtil::getGlobalScriptLabels(scriptsFilepath, &error);
m_scriptsLoaded = true;
if (!error.isEmpty() && !m_loggedScriptsFileError) {
logWarn(QString("Failed to read scripts file '%1' for %2: %3")
@@ -161,14 +161,14 @@ QStringList Map::getScriptLabels(Event::Group group) {
m_loggedScriptsFileError = true;
}
// Track the scripts file for changes. Path may have changed, so stop tracking old files.
m_scriptFileWatcher->removePaths(m_scriptFileWatcher->files());
if (!m_scriptFileWatcher->addPath(scriptsFilepath) && !m_loggedScriptsFileError) {
if (!m_scriptFileWatcher->files().contains(scriptsFilepath) && !m_scriptFileWatcher->addPath(scriptsFilepath) && !m_loggedScriptsFileError) {
logWarn(QString("Failed to add scripts file '%1' to file watcher for %2.")
.arg(Util::stripPrefix(scriptsFilepath, projectConfig.projectDir() + "/"))
.arg(m_name));
m_loggedScriptsFileError = true;
}
m_scriptsLoaded = true;
}
QStringList scriptLabels = m_scriptLabels;

View File

@@ -1245,8 +1245,9 @@ void Editor::unsetMap() {
this->map->pruneEditHistory();
this->map->disconnect(this);
// Don't let the file watcher accumulate map.json files.
// Don't let the file watcher accumulate map.json / scripts.inc files.
this->project->stopFileWatch(this->map->getJsonFilepath());
this->map->invalidateScripts();
}
clearMapEvents();
clearMapConnections();