diff --git a/src/source/common/openFileWatcher.cpp b/src/source/common/openFileWatcher.cpp index 83fd91c6f..c83e106d9 100644 --- a/src/source/common/openFileWatcher.cpp +++ b/src/source/common/openFileWatcher.cpp @@ -44,8 +44,8 @@ void OpenFileWatcher::addWatchFile(const QString &strFile) m_pOpenFileWatcher->addPath(strFile); // 第一次默认文件未修改 - if (m_mapFileHasModified.find(strFile) != m_mapFileHasModified.end()) { - m_mapFileHasModified[m_strOpenFile] = false; + if (m_mapFileHasModified.find(strFile) == m_mapFileHasModified.end()) { + m_mapFileHasModified[strFile] = false; } } diff --git a/src/source/mainwindow.cpp b/src/source/mainwindow.cpp index 49fc09cfa..f1e7b253c 100644 --- a/src/source/mainwindow.cpp +++ b/src/source/mainwindow.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #ifdef DTKCORE_CLASS_DConfigFile #include @@ -2949,10 +2950,17 @@ void MainWindow::slotOpenFileChanged(const QString &strPath) SimpleQueryDialog dialog(this); int iResult = dialog.showDialog(strDesText, tr("Cancel", "button"), DDialog::ButtonNormal, tr("Update", "button"), DDialog::ButtonRecommend); if (1 == iResult) { - // 对重命名或删除导致的文件不存在的情况,不给出任何提示,且从文件监控中去掉此文件 + // 文件不存在可能是编辑器"先删除再创建"的保存方式,延迟重检而非直接移除监控 if (!QFile::exists(strPath)) { - mapStatus.remove(strPath); - mapPassword.remove(strPath); + mapStatus[strPath] = false; + QTimer::singleShot(2000, this, [this, strPath]() { + if (QFile::exists(strPath)) { + m_pOpenFileWatcher->addWatchFile(strPath); + } else { + QMap &status = m_pOpenFileWatcher->getFileHasModified(); + status.remove(strPath); + } + }); return; }