From d0dc68058e4542c00f35a43be9f9f0fb8ec9b264 Mon Sep 17 00:00:00 2001
From: Daniel Teske <daniel.teske@digia.com>
Date: Tue, 23 Apr 2013 13:48:52 +0200
Subject: [PATCH] ProjectModels: Fix crash on changing the tree in particular
 ways

The crash is due to the project model figuring out a safe node to be the
current node, setting that. But then the DocumentManager synchronizes
the current node with the editor, thus setting the current node back.

Task-number: QTCREATORBUG-9176
Change-Id: Ia516a770dbbfd16d224fa030a8c3d1b3a40f83cd
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
---
 src/plugins/projectexplorer/projectexplorer.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index 2f30369457c..a5e269c914d 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -237,6 +237,7 @@ struct ProjectExplorerPluginPrivate {
     KitManager *m_kitManager;
     ToolChainManager *m_toolChainManager;
     bool m_shuttingDown;
+    bool m_ignoreDocumentManagerChangedFile;
     QStringList m_arguments;
 };
 
@@ -248,7 +249,8 @@ ProjectExplorerPluginPrivate::ProjectExplorerPluginPrivate() :
     m_projectsMode(0),
     m_kitManager(0),
     m_toolChainManager(0),
-    m_shuttingDown(false)
+    m_shuttingDown(false),
+    m_ignoreDocumentManagerChangedFile(false)
 {
 }
 
@@ -1413,6 +1415,8 @@ void ProjectExplorerPlugin::setCurrentFile(Project *project, const QString &file
 
 void ProjectExplorerPlugin::setCurrentFile(const QString &filePath)
 {
+    if (d->m_ignoreDocumentManagerChangedFile)
+        return;
     Project *project = d->m_session->projectForFile(filePath);
     // If the file is not in any project, stay with the current project
     // e.g. on opening a git diff buffer, git log buffer, we don't change the project
@@ -1826,8 +1830,10 @@ void ProjectExplorerPlugin::setCurrent(Project *project, QString filePath, Node
         updateActions();
     }
 
+    d->m_ignoreDocumentManagerChangedFile = true;
     Core::DocumentManager::setCurrentFile(filePath);
     updateContext();
+    d->m_ignoreDocumentManagerChangedFile = false;
 }
 
 void ProjectExplorerPlugin::updateActions()
-- 
GitLab