From 4d5da2938a1f9be9469f31cabadf8f684c8bbe95 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 14 Mar 2019 12:21:47 +0100 Subject: [PATCH] Debugger: Move perspective saving to a time where mode is active It should not make and I do not observe a difference, but it seems the better thing to do. Change-Id: I1f1f9fba72c2b20f24ebde04cf4ec3711d77d476 Reviewed-by: Eike Ziller --- src/plugins/debugger/debuggermainwindow.cpp | 53 +++++++++++---------- src/plugins/debugger/debuggermainwindow.h | 3 +- src/plugins/debugger/debuggerplugin.cpp | 29 +++++------ 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/plugins/debugger/debuggermainwindow.cpp b/src/plugins/debugger/debuggermainwindow.cpp index 641b6a7f058..7d4175fc956 100644 --- a/src/plugins/debugger/debuggermainwindow.cpp +++ b/src/plugins/debugger/debuggermainwindow.cpp @@ -306,35 +306,36 @@ void DebuggerMainWindow::showStatusMessage(const QString &message, int timeoutMS theMainWindow->d->m_statusLabel->showStatusMessage(message, timeoutMS); } -void DebuggerMainWindow::onModeChanged(Core::Id mode) +void DebuggerMainWindow::enterDebugMode() { - if (mode == Debugger::Constants::MODE_DEBUG) { - theMainWindow->setDockActionsVisible(true); - Perspective *perspective = theMainWindow->d->m_currentPerspective; - if (!perspective) { - const QSettings *settings = ICore::settings(); - const QString lastPerspectiveId = settings->value(LAST_PERSPECTIVE_KEY).toString(); - perspective = Perspective::findPerspective(lastPerspectiveId); - // If we don't find a perspective with the stored name, pick any. - // This can happen e.g. when a plugin was disabled that provided - // the stored perspective, or when the save file was modified externally. - if (!perspective && !theMainWindow->d->m_perspectives.isEmpty()) - perspective = theMainWindow->d->m_perspectives.first(); - } - // There's at least the debugger preset perspective that should be found above. - QTC_ASSERT(perspective, return); - perspective->select(); - } else { - if (Perspective *perspective = theMainWindow->d->m_currentPerspective) - perspective->d->saveLayout(); + theMainWindow->setDockActionsVisible(true); + Perspective *perspective = theMainWindow->d->m_currentPerspective; + if (!perspective) { + const QSettings *settings = ICore::settings(); + const QString lastPerspectiveId = settings->value(LAST_PERSPECTIVE_KEY).toString(); + perspective = Perspective::findPerspective(lastPerspectiveId); + // If we don't find a perspective with the stored name, pick any. + // This can happen e.g. when a plugin was disabled that provided + // the stored perspective, or when the save file was modified externally. + if (!perspective && !theMainWindow->d->m_perspectives.isEmpty()) + perspective = theMainWindow->d->m_perspectives.first(); + } + // There's at least the debugger preset perspective that should be found above. + QTC_ASSERT(perspective, return); + perspective->select(); +} - theMainWindow->setDockActionsVisible(false); +void DebuggerMainWindow::leaveDebugMode() +{ + if (Perspective *perspective = theMainWindow->d->m_currentPerspective) + perspective->d->saveLayout(); - // Hide dock widgets manually in case they are floating. - for (QDockWidget *dockWidget : theMainWindow->dockWidgets()) { - if (dockWidget->isFloating()) - dockWidget->hide(); - } + theMainWindow->setDockActionsVisible(false); + + // Hide dock widgets manually in case they are floating. + for (QDockWidget *dockWidget : theMainWindow->dockWidgets()) { + if (dockWidget->isFloating()) + dockWidget->hide(); } } diff --git a/src/plugins/debugger/debuggermainwindow.h b/src/plugins/debugger/debuggermainwindow.h index 2b99e201a8e..98ff0a37d1d 100644 --- a/src/plugins/debugger/debuggermainwindow.h +++ b/src/plugins/debugger/debuggermainwindow.h @@ -126,7 +126,8 @@ public: static void doShutdown(); static void showStatusMessage(const QString &message, int timeoutMS); - static void onModeChanged(Core::Id mode); + static void enterDebugMode(); + static void leaveDebugMode(); static QWidget *centralWidgetStack(); void addSubPerspectiveSwitcher(QWidget *widget); diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 8c9f0e96ffd..44ce9a03d82 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -696,7 +696,6 @@ public: int lineNumber, QMenu *menu); void toggleBreakpointHelper(); - void onModeChanged(Id mode); void updateDebugWithoutDeployMenu(); void startRemoteCdbSession(); @@ -1352,8 +1351,19 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, addCdbOptionPages(&m_optionPages); m_optionPages.append(new LocalsAndExpressionsOptionsPage); - connect(ModeManager::instance(), &ModeManager::currentModeChanged, - this, &DebuggerPluginPrivate::onModeChanged); + connect(ModeManager::instance(), &ModeManager::currentModeAboutToChange, this, [] { + if (ModeManager::currentModeId() == MODE_DEBUG) + DebuggerMainWindow::leaveDebugMode(); + }); + + connect(ModeManager::instance(), &ModeManager::currentModeChanged, this, [](Id mode) { + if (mode == MODE_DEBUG) { + DebuggerMainWindow::enterDebugMode(); + if (IEditor *editor = EditorManager::currentEditor()) + editor->widget()->setFocus(); + } + }); + connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::settingsChanged, this, &DebuggerPluginPrivate::updateDebugWithoutDeployMenu); @@ -2283,19 +2293,6 @@ void DebuggerPlugin::extensionsInitialized() dd->extensionsInitialized(); } -void DebuggerPluginPrivate::onModeChanged(Id mode) -{ - DebuggerMainWindow::onModeChanged(mode); - // FIXME: This one gets always called, even if switching between modes - // different then the debugger mode. E.g. Welcome and Help mode and - // also on shutdown. - - if (mode == MODE_DEBUG) { - if (IEditor *editor = EditorManager::currentEditor()) - editor->widget()->setFocus(); - } -} - } // namespace Internal static bool buildTypeAccepted(QFlags toolMode, BuildConfiguration::BuildType buildType)