Debugger: Fix switching to previous mode on exit

This behavior was broken with refactoring done in commit
3b5ecac238. This has two main components:
1. Perspective::select() needs to call EngineManager::activateDebugMode()
   in order to save the previous mode.
2. The contents of the previous function
   DebuggerPluginPrivate::activatePreviousMode() was placed in
   EngineManager::deactivateDebugMode() and is called in
   doFinishDebugger().

Task-number: QTCREATORBUG-21415
Change-Id: Ibca188ba740027769c497e25ea695af8e218ea4e
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Aaron Barany
2018-12-08 00:01:42 -08:00
parent 77ad54a6ef
commit 867befc5ae
4 changed files with 17 additions and 1 deletions

View File

@@ -418,6 +418,8 @@ public:
m_watchHandler.cleanup();
m_engine->showMessage(tr("Debugger finished."), StatusBar);
m_engine->setState(DebuggerFinished); // Also destroys views.
if (boolSetting(SwitchModeOnExit))
EngineManager::deactivateDebugMode();
}
void scheduleResetLocation()

View File

@@ -26,6 +26,7 @@
#include "debuggermainwindow.h"
#include "debuggerconstants.h"
#include "debuggerinternalconstants.h"
#include "enginemanager.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
@@ -696,7 +697,7 @@ void Perspective::addWindow(QWidget *widget,
void Perspective::select()
{
ModeManager::activateMode(Debugger::Constants::MODE_DEBUG);
Debugger::Internal::EngineManager::activateDebugMode();
if (Perspective::currentPerspective() == this)
return;
theMainWindow->d->selectPerspective(this);

View File

@@ -421,6 +421,18 @@ void EngineManager::activateDebugMode()
}
}
void EngineManager::deactivateDebugMode()
{
if (ModeManager::currentModeId() == Constants::MODE_DEBUG && d->m_previousMode.isValid()) {
// If stopping the application also makes Qt Creator active (as the
// "previously active application"), doing the switch synchronously
// leads to funny effects with floating dock widgets
const Core::Id mode = d->m_previousMode;
QTimer::singleShot(0, d, [mode]() { ModeManager::activateMode(mode); });
d->m_previousMode = Id();
}
}
bool EngineManager::isLastOf(const QString &type)
{
int count = 0;

View File

@@ -49,6 +49,7 @@ public:
static void unregisterEngine(DebuggerEngine *engine);
static void activateEngine(DebuggerEngine *engine);
static void activateDebugMode();
static void deactivateDebugMode();
static bool isLastOf(const QString &type);
static QList<QPointer<DebuggerEngine> > engines();