From 3a8564c1f5d034a3b205d21bb602225ee97a8419 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 13 Nov 2014 14:38:58 +0100 Subject: [PATCH] Fix reloading documents when they are changed fast, multiple times. This can for example happen when doing interactive git rebases. * When a file was changed after we reloaded it, but before we removed +readded the watcher, we wouldn't get a notification for these changes. * When we got a file changed notification while we were in checkForReload (because of event processing of the dialog, or file loading), the notification was dropped and only processes when a check was triggered again (e.g. at window activation, or when some (other) file changed) Change-Id: Iab1861a8f05c739a3405bc1afe90ae6f2145057b Task-number: QTCREATORBUG-9745 Reviewed-by: Daniel Teske Reviewed-by: Orgad Shaneh --- src/plugins/coreplugin/documentmanager.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index 9ae7a491857..dbf647afdcd 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -908,14 +908,16 @@ void DocumentManager::checkForReload() if (!QApplication::activeWindow()) return; - if (QApplication::activeModalWidget()) { // a modal dialog, recheck later + if (QApplication::activeModalWidget() || d->m_blockActivated) { + // We do not want to prompt for modified file if we currently have some modal dialog open. + // If d->m_blockActivated is true, then it means that the event processing of either the + // file modified dialog, or of loading large files, has delivered a file change event from + // a watcher *and* the timer triggered. We may never end up here in a nested way, so + // recheck later. QTimer::singleShot(200, this, SLOT(checkForReload())); return; } - if (d->m_blockActivated) - return; - d->m_blockActivated = true; IDocument::ReloadSetting defaultBehavior = EditorManagerPrivate::reloadSetting(); @@ -1009,6 +1011,14 @@ void DocumentManager::checkForReload() // handle it! d->m_blockedIDocument = document; + // Update file info, also handling if e.g. link target has changed. + // We need to do that before the file is reloaded, because removing the watcher will + // loose any pending change events. Loosing change events *before* the file is reloaded + // doesn't matter, because in that case we then reload the new version of the file already + // anyhow. + removeFileInfo(document); + addFileInfo(document); + bool success = true; QString errorString; // we've got some modification @@ -1110,9 +1120,6 @@ void DocumentManager::checkForReload() errorStrings << errorString; } - // update file info, also handling if e.g. link target has changed - removeFileInfo(document); - addFileInfo(document); d->m_blockedIDocument = 0; } if (!errorStrings.isEmpty())