From 5b65a60e788df17abc2e9c2af53f55128a33acc6 Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Tue, 6 Apr 2010 15:10:20 +0200
Subject: [PATCH] QmlDesigner: Switch back to edit mode if last .qml file
 closes

Fixes multiple ways to crash QmlDesigner after last .qml file is closed
by enforcing a switch to Edit mode then.

Patch originally done by con.
---
 src/plugins/coreplugin/designmode.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/plugins/coreplugin/designmode.cpp b/src/plugins/coreplugin/designmode.cpp
index c8e83bc9195..419c255882b 100644
--- a/src/plugins/coreplugin/designmode.cpp
+++ b/src/plugins/coreplugin/designmode.cpp
@@ -207,7 +207,7 @@ void DesignMode::unregisterDesignWidget(QWidget *widget)
 // if editor changes, check if we have valid mimetype registered.
 void DesignMode::currentEditorChanged(Core::IEditor *editor)
 {
-    if (d->m_currentEditor.data() == editor)
+    if (editor && (d->m_currentEditor.data() == editor))
         return;
 
     bool mimeEditorAvailable = false;
@@ -239,6 +239,8 @@ void DesignMode::currentEditorChanged(Core::IEditor *editor)
 
     if (!mimeEditorAvailable) {
         setActiveContext(QList<int>());
+        if (core->modeManager()->currentMode() == this)
+            core->modeManager()->activateMode(Core::Constants::MODE_EDIT);
         setEnabled(false);
         d->m_currentEditor = QWeakPointer<Core::IEditor>();
         emit actionsUpdated(d->m_currentEditor.data());
-- 
GitLab