1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "reversedebugplugin.h"
6#include "base/abstractmenu.h"
7#include "base/abstractwidget.h"
8#include "services/window/windowservice.h"
9#include "common/actionmanager/actionmanager.h"
10#include "reversedebuggermgr.h"
11
12#include <QMenu>
13
14using namespace dpfservice;
15using namespace ReverseDebugger::Internal;
16
17void ReverseDebugPlugin::initialize()
18{
19}
20
21bool ReverseDebugPlugin::start()
22{
23 auto &ctx = dpfInstance.serviceContext();
24 windowService = ctx.service<WindowService>(WindowService::name());
25 if (!windowService) {
26 qCritical() << "Failed, can't found window service";
27 abort();
28 }
29
30 auto actionInit = [&](QAction *action, QString actionID, QKeySequence key, QString iconFileName){
31 ActionManager::getInstance()->registerAction(action, actionID, action->text(), key, iconFileName);
32 AbstractAction *actionImpl = new AbstractAction(action);
33 windowService->addAction(dpfservice::MWM_TOOLS, actionImpl);
34 };
35
36 auto reverseDbgAction = new QAction(tr("Reverse debug"));
37 QMenu *menu = new QMenu();
38 reverseDbgAction->setMenu(menu);
39 actionInit(reverseDbgAction, "Tool.Reverse", {}, "");
40
41 auto recoredAction = new QAction(tr("Record"));
42 auto replayAction = new QAction(tr("Replay"));
43
44 menu->addAction(recoredAction);
45 menu->addAction(replayAction);
46
47 reverseDebug = new ReverseDebuggerMgr(this);
48 connect(recoredAction, &QAction::triggered, reverseDebug, &ReverseDebuggerMgr::recored);
49 connect(replayAction, &QAction::triggered, reverseDebug, &ReverseDebuggerMgr::replay);
50
51 windowService->addContextWidget(tr("R&everse Debug"), new AbstractWidget(reverseDebug->getWidget()), "Reverse");
52
53 return true;
54}
55
56dpf::Plugin::ShutdownFlag ReverseDebugPlugin::stop()
57{
58 return Sync;
59}
60