From 9af8ecd935b8647d49574e1b66a522970025dcb8 Mon Sep 17 00:00:00 2001 From: Artem Sokolovskii Date: Fri, 29 Sep 2023 14:50:58 +0200 Subject: [PATCH] DAP: Fix dap engine selection with the translated strings Change-Id: I051c1f7e9776922a98f7c54676c237c63984050d Reviewed-by: hjk --- src/plugins/debugger/debuggerplugin.cpp | 44 ++++++++++----------- src/plugins/debugger/debuggerruncontrol.cpp | 10 ++--- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 88bcbd081c0..bb90a260cc9 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -1239,17 +1239,29 @@ DebuggerPluginPrivate::DebuggerPluginPrivate(const QStringList &arguments) void DebuggerPluginPrivate::createDapDebuggerPerspective(QWidget *globalLogWindow) { - EngineManager::registerDefaultPerspective(Tr::tr("CMake Preset"), - "DAP", - Constants::DAP_PERSPECTIVE_ID); + struct DapPerspective + { + QString name; + char const *runMode; + }; - EngineManager::registerDefaultPerspective(Tr::tr("GDB Preset"), - "DAP", - Constants::DAP_PERSPECTIVE_ID); + const QList perspectiveList = { + DapPerspective{Tr::tr("CMake Preset"), ProjectExplorer::Constants::DAP_CMAKE_DEBUG_RUN_MODE}, + DapPerspective{Tr::tr("GDB Preset"), ProjectExplorer::Constants::DAP_GDB_DEBUG_RUN_MODE}, + DapPerspective{Tr::tr("Python Preset"), + ProjectExplorer::Constants::DAP_PY_DEBUG_RUN_MODE}, + }; - EngineManager::registerDefaultPerspective(Tr::tr("Python Preset"), - "DAP", - Constants::DAP_PERSPECTIVE_ID); + for (const DapPerspective &dp : perspectiveList) + EngineManager::registerDefaultPerspective(dp.name, "DAP", Constants::DAP_PERSPECTIVE_ID); + + connect(&m_startDapAction, &QAction::triggered, this, [perspectiveList] { + QComboBox *combo = qobject_cast(EngineManager::dapEngineChooser()); + if (perspectiveList.size() > combo->currentIndex()) + ProjectExplorerPlugin::runStartupProject(perspectiveList.at(combo->currentIndex()) + .runMode, + false); + }); auto breakpointManagerView = createBreakpointManagerView("DAPDebugger.BreakWindow"); auto breakpointManagerWindow @@ -1265,20 +1277,6 @@ void DebuggerPluginPrivate::createDapDebuggerPerspective(QWidget *globalLogWindo Tr::tr("DAP Debugger Perspectives"), "DAPDebugger.Docks.Snapshots"); - connect(&m_startDapAction, &QAction::triggered, this, [] { - QComboBox *combo = qobject_cast(EngineManager::dapEngineChooser()); - if (combo->currentText() == "CMake Preset") { - ProjectExplorerPlugin::runStartupProject( - ProjectExplorer::Constants::DAP_CMAKE_DEBUG_RUN_MODE, false); - } else if (combo->currentText() == "GDB Preset") { - ProjectExplorerPlugin::runStartupProject( - ProjectExplorer::Constants::DAP_GDB_DEBUG_RUN_MODE, false); - } else { - ProjectExplorerPlugin::runStartupProject( - ProjectExplorer::Constants::DAP_PY_DEBUG_RUN_MODE, false); - } - }); - m_perspectiveDap.addToolBarAction(&m_startDapAction); m_startDapAction.setToolTip(Tr::tr("Start DAP Debugging")); m_startDapAction.setText(Tr::tr("Start DAP Debugging")); diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp index 788eacb4bfa..d797586d793 100644 --- a/src/plugins/debugger/debuggerruncontrol.cpp +++ b/src/plugins/debugger/debuggerruncontrol.cpp @@ -481,14 +481,10 @@ void DebuggerRunTool::start() runControl()->setDisplayName(m_runParameters.displayName); + m_engine = createDapEngine(runControl()->runMode()); + if (!m_engine) { - if (runControl()->runMode() == ProjectExplorer::Constants::DAP_CMAKE_DEBUG_RUN_MODE) - m_engine = createDapEngine(runControl()->runMode()); - else if (runControl()->runMode() == ProjectExplorer::Constants::DAP_GDB_DEBUG_RUN_MODE) - m_engine = createDapEngine(runControl()->runMode()); - else if (runControl()->runMode() == ProjectExplorer::Constants::DAP_PY_DEBUG_RUN_MODE) - m_engine = createDapEngine(runControl()->runMode()); - else if (m_runParameters.isCppDebugging()) { + if (m_runParameters.isCppDebugging()) { switch (m_runParameters.cppEngineType) { case GdbEngineType: m_engine = createGdbEngine();