| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | 
|---|
| 2 | // | 
|---|
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later | 
|---|
| 4 |  | 
|---|
| 5 | #include "menumanager.h" | 
|---|
| 6 | #include "debugmanager.h" | 
|---|
| 7 | #include "debuggersignals.h" | 
|---|
| 8 | #include "debuggerglobals.h" | 
|---|
| 9 | #include "base/abstractmenu.h" | 
|---|
| 10 | #include "common/common.h" | 
|---|
| 11 | #include "services/window/windowservice.h" | 
|---|
| 12 |  | 
|---|
| 13 | #include <QMenu> | 
|---|
| 14 |  | 
|---|
| 15 | using namespace dpfservice; | 
|---|
| 16 | MenuManager::(QObject *parent) : QObject(parent) | 
|---|
| 17 | { | 
|---|
| 18 | } | 
|---|
| 19 |  | 
|---|
| 20 | void MenuManager::(WindowService *windowService) | 
|---|
| 21 | { | 
|---|
| 22 | if (!windowService) | 
|---|
| 23 | return; | 
|---|
| 24 |  | 
|---|
| 25 | startDebugging.reset(new QAction(MWMDA_START_DEBUG)); | 
|---|
| 26 | ActionManager::getInstance()->registerAction(startDebugging.get(), "Debug.Start.Debugging", | 
|---|
| 27 | MWMDA_START_DEBUG, QKeySequence(Qt::Key::Key_F5), | 
|---|
| 28 | ":/resource/images/debugger_start.png"); | 
|---|
| 29 | connect(startDebugging.get(), &QAction::triggered, debugManager, &DebugManager::run); | 
|---|
| 30 | AbstractAction *actionImpl = new AbstractAction(startDebugging.get()); | 
|---|
| 31 | windowService->addAction(MWM_DEBUG, actionImpl); | 
|---|
| 32 | windowService->addToolBarActionItem( "Start Debugging", startDebugging.get(), "Debug"); | 
|---|
| 33 | windowService->addToolBarActionItem( "Debugger.Start", startDebugging.get(), "Debug"); | 
|---|
| 34 |  | 
|---|
| 35 | #if 0 // not used yet. | 
|---|
| 36 | detachDebugger.reset(new QAction( "Detach Debugger")); | 
|---|
| 37 | connect(detachDebugger.get(), &QAction::triggered, debugManager, &DebugManager::detachDebug); | 
|---|
| 38 | actionImpl = new AbstractAction(detachDebugger.get()); | 
|---|
| 39 | windowService->addAction(QString::fromStdString(MENU_DEBUG), actionImpl); | 
|---|
| 40 | #endif | 
|---|
| 41 |  | 
|---|
| 42 | interrupt.reset(new QAction(MWMDA_INTERRUPT)); | 
|---|
| 43 | ActionManager::getInstance()->registerAction(interrupt.get(), "Debug.Interrupt", | 
|---|
| 44 | MWMDA_INTERRUPT, QKeySequence(Qt::Key::Key_F5), | 
|---|
| 45 | ":/resource/images/debugger_interrupt.png"); | 
|---|
| 46 | interrupt->setEnabled(false); | 
|---|
| 47 | connect(interrupt.get(), &QAction::triggered, debugManager, &DebugManager::interruptDebug); | 
|---|
| 48 | actionImpl = new AbstractAction(interrupt.get()); | 
|---|
| 49 | interrupt->setEnabled(false); | 
|---|
| 50 | windowService->addAction(MWM_DEBUG, actionImpl); | 
|---|
| 51 |  | 
|---|
| 52 | continueDebugging.reset(new QAction(MWMDA_CONTINUE)); | 
|---|
| 53 | ActionManager::getInstance()->registerAction(continueDebugging.get(), "Debug.Continue", | 
|---|
| 54 | MWMDA_CONTINUE, QKeySequence(Qt::Key::Key_F5), | 
|---|
| 55 | ":/resource/images/debugger_continue.png"); | 
|---|
| 56 | continueDebugging->setEnabled(false); | 
|---|
| 57 | connect(continueDebugging.get(), &QAction::triggered, debugManager, &DebugManager::continueDebug); | 
|---|
| 58 | actionImpl = new AbstractAction(continueDebugging.get()); | 
|---|
| 59 | windowService->addAction(MWM_DEBUG, actionImpl); | 
|---|
| 60 | windowService->addToolBarActionItem( "Debugger.Continue", continueDebugging.get(), "Debug"); | 
|---|
| 61 |  | 
|---|
| 62 | abortDebugging.reset(new QAction(MWMDA_ABORT_DEBUGGING)); | 
|---|
| 63 | ActionManager::getInstance()->registerAction(abortDebugging.get(), "Debug.Abort.Debugging", | 
|---|
| 64 | MWMDA_ABORT_DEBUGGING, QKeySequence(Qt::Modifier::ALT | Qt::Key::Key_Backspace), | 
|---|
| 65 | ":/resource/images/debugger_stop.png"); | 
|---|
| 66 | abortDebugging->setEnabled(false); | 
|---|
| 67 | connect(abortDebugging.get(), &QAction::triggered, debugManager, &DebugManager::abortDebug); | 
|---|
| 68 | actionImpl = new AbstractAction(abortDebugging.get()); | 
|---|
| 69 | windowService->addAction(MWM_DEBUG, actionImpl); | 
|---|
| 70 | windowService->addToolBarActionItem( "abort_debug", abortDebugging.get(), "Debug"); | 
|---|
| 71 | windowService->addToolBarActionItem( "Debugger.Stop", abortDebugging.get(), "Debug"); | 
|---|
| 72 |  | 
|---|
| 73 | restartDebugging.reset(new QAction(MWMDA_RESTART_DEBUGGING)); | 
|---|
| 74 | ActionManager::getInstance()->registerAction(restartDebugging.get(), "Debug.Restart.Debugging", | 
|---|
| 75 | MWMDA_RESTART_DEBUGGING, QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_B), | 
|---|
| 76 | ":/resource/images/restart_debug.png"); | 
|---|
| 77 | restartDebugging->setEnabled(false); | 
|---|
| 78 | connect(restartDebugging.get(), &QAction::triggered, debugManager, &DebugManager::restartDebug); | 
|---|
| 79 | actionImpl = new AbstractAction(restartDebugging.get()); | 
|---|
| 80 | windowService->addAction(MWM_DEBUG, actionImpl); | 
|---|
| 81 |  | 
|---|
| 82 | stepOver.reset(new QAction(MWMDA_STEP_OVER)); | 
|---|
| 83 | ActionManager::getInstance()->registerAction(stepOver.get(), "Debug.Step.Over", | 
|---|
| 84 | MWMDA_STEP_OVER, QKeySequence(Qt::Key::Key_F10), | 
|---|
| 85 | ":/resource/images/debugger_stepover.png"); | 
|---|
| 86 | stepOver->setEnabled(false); | 
|---|
| 87 | connect(stepOver.get(), &QAction::triggered, debugManager, &DebugManager::stepOver); | 
|---|
| 88 | actionImpl = new AbstractAction(stepOver.get()); | 
|---|
| 89 | windowService->addAction(MWM_DEBUG, actionImpl); | 
|---|
| 90 | windowService->addToolBarActionItem( "Step.Over", stepOver.get(), "Debug"); | 
|---|
| 91 |  | 
|---|
| 92 | stepIn.reset(new QAction(MWMDA_STEP_IN)); | 
|---|
| 93 | ActionManager::getInstance()->registerAction(stepIn.get(), "Debug.Step.In", | 
|---|
| 94 | MWMDA_STEP_IN, QKeySequence(Qt::Key::Key_F11), | 
|---|
| 95 | ":/resource/images/debugger_stepinto.png"); | 
|---|
| 96 | stepIn->setEnabled(false); | 
|---|
| 97 | connect(stepIn.get(), &QAction::triggered, debugManager, &DebugManager::stepIn); | 
|---|
| 98 | actionImpl = new AbstractAction(stepIn.get()); | 
|---|
| 99 | windowService->addAction(MWM_DEBUG, actionImpl); | 
|---|
| 100 | windowService->addToolBarActionItem( "Step.In", stepIn.get(), "Debug"); | 
|---|
| 101 |  | 
|---|
| 102 | stepOut.reset(new QAction(MWMDA_STEP_OUT)); | 
|---|
| 103 | ActionManager::getInstance()->registerAction(stepOut.get(), "Debug.Step.Out", | 
|---|
| 104 | MWMDA_STEP_OUT, QKeySequence(Qt::Modifier::SHIFT | Qt::Key::Key_F11), | 
|---|
| 105 | ":/resource/images/debugger_stepout.png"); | 
|---|
| 106 | stepOut->setEnabled(false); | 
|---|
| 107 | connect(stepOut.get(), &QAction::triggered, debugManager, &DebugManager::stepOut); | 
|---|
| 108 | actionImpl = new AbstractAction(stepOut.get()); | 
|---|
| 109 | windowService->addAction(MWM_DEBUG, actionImpl); | 
|---|
| 110 | windowService->addToolBarActionItem( "Step.Out", stepOut.get(), "Debug.End"); | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 | void MenuManager::handleRunStateChanged(AbstractDebugger::RunState state) | 
|---|
| 114 | { | 
|---|
| 115 | switch (state) { | 
|---|
| 116 | case AbstractDebugger::kNoRun: | 
|---|
| 117 | case AbstractDebugger::kPreparing: | 
|---|
| 118 | case AbstractDebugger::kStart: | 
|---|
| 119 | startDebugging->setEnabled(true); | 
|---|
| 120 | #if 0 // not used yet. | 
|---|
| 121 | detachDebugger->setEnabled(true); | 
|---|
| 122 | #endif | 
|---|
| 123 | interrupt->setEnabled(false); | 
|---|
| 124 | continueDebugging->setEnabled(false); | 
|---|
| 125 | abortDebugging->setEnabled(false); | 
|---|
| 126 | restartDebugging->setEnabled(false); | 
|---|
| 127 | stepOver->setEnabled(false); | 
|---|
| 128 | stepIn->setEnabled(false); | 
|---|
| 129 | stepOut->setEnabled(false); | 
|---|
| 130 | break; | 
|---|
| 131 |  | 
|---|
| 132 | case AbstractDebugger::kRunning: | 
|---|
| 133 | startDebugging->setEnabled(false); | 
|---|
| 134 | #if 0 // not used yet. | 
|---|
| 135 | detachDebugger->setEnabled(false); | 
|---|
| 136 | #endif | 
|---|
| 137 | interrupt->setEnabled(true); | 
|---|
| 138 | continueDebugging->setEnabled(false); | 
|---|
| 139 | abortDebugging->setEnabled(true); | 
|---|
| 140 | restartDebugging->setEnabled(true); | 
|---|
| 141 | stepOver->setEnabled(false); | 
|---|
| 142 | stepIn->setEnabled(false); | 
|---|
| 143 | stepOut->setEnabled(false); | 
|---|
| 144 | break; | 
|---|
| 145 | case AbstractDebugger::kStopped: | 
|---|
| 146 | startDebugging->setEnabled(false); | 
|---|
| 147 | #if 0 // not used yet. | 
|---|
| 148 | detachDebugger->setEnabled(false); | 
|---|
| 149 | #endif | 
|---|
| 150 | interrupt->setEnabled(false); | 
|---|
| 151 | continueDebugging->setEnabled(true); | 
|---|
| 152 | abortDebugging->setEnabled(true); | 
|---|
| 153 | restartDebugging->setEnabled(true); | 
|---|
| 154 | stepOver->setEnabled(true); | 
|---|
| 155 | stepIn->setEnabled(true); | 
|---|
| 156 | stepOut->setEnabled(true); | 
|---|
| 157 | break; | 
|---|
| 158 | case AbstractDebugger::kCustomRunning: | 
|---|
| 159 | startDebugging->setEnabled(false); | 
|---|
| 160 | interrupt->setEnabled(false); | 
|---|
| 161 | continueDebugging->setEnabled(false); | 
|---|
| 162 | abortDebugging->setEnabled(true); | 
|---|
| 163 | restartDebugging->setEnabled(false); | 
|---|
| 164 | stepOver->setEnabled(false); | 
|---|
| 165 | stepIn->setEnabled(false); | 
|---|
| 166 | stepOut->setEnabled(false); | 
|---|
| 167 | break; | 
|---|
| 168 |  | 
|---|
| 169 | default: | 
|---|
| 170 | // do nothing. | 
|---|
| 171 | break; | 
|---|
| 172 | } | 
|---|
| 173 | } | 
|---|
| 174 |  | 
|---|