1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "findplugin.h"
6
7#include "services/window/windowservice.h"
8#include "findtoolbar.h"
9#include "findtoolwindow.h"
10#include "searchresultwindow.h"
11#include "common/common.h"
12#include "base/abstractmenu.h"
13#include "base/abstractwidget.h"
14
15#include <QMenu>
16#include <QAction>
17
18using namespace dpfservice;
19
20void FindPlugin::initialize()
21{
22 qInfo() << __FUNCTION__;
23
24}
25
26bool FindPlugin::start()
27{
28 qInfo() << __FUNCTION__;
29
30 auto &ctx = dpfInstance.serviceContext();
31 windowService = ctx.service<WindowService>(WindowService::name());
32 if (!windowService) {
33 qCritical() << "Failed, can't found window service";
34 abort();
35 }
36
37 QMenu* editMenu = new QMenu(QMenu::tr("&Edit"));
38 QAction* findAction = new QAction();
39 QAction* advancedFindAction = new QAction();
40
41
42 ActionManager::getInstance()->registerAction(findAction, "Edit.Find",
43 tr("Find/Replace"), QKeySequence(Qt::Modifier::CTRL | Qt::Key_F),
44 ":/find/images/find.png");
45 ActionManager::getInstance()->registerAction(advancedFindAction, "Edit.Advanced.Find",
46 tr("Advanced Find"), QKeySequence(Qt::Modifier::CTRL | Qt::Modifier::SHIFT | Qt::Key_F),
47 ":/find/images/edit-find.png");
48
49 editMenu->addAction(findAction);
50 editMenu->addAction(advancedFindAction);
51 windowService->addToolBarActionItem("Find/Replace", findAction, "Search.End");
52
53 connect(findAction, &QAction::triggered, [=] {
54 windowService->showFindToolBar();
55 });
56
57 connect(advancedFindAction, &QAction::triggered, [=] {
58 editor.switchContext(tr("Advanced &Search"));
59 });
60
61 AbstractMenu * menuImpl = new AbstractMenu(editMenu);
62 windowService->addMenu(menuImpl);
63
64 AbstractWidget *widgetImpl = new AbstractWidget(new FindToolWindow());
65 windowService->addContextWidget(tr("Advanced &Search"), widgetImpl, "Advsearch");
66
67 FindToolBar * findToolBar = new FindToolBar();
68 AbstractWidget *abstractFindToolBar = new AbstractWidget(findToolBar);
69 windowService->addFindToolBar(abstractFindToolBar);
70 connect(findToolBar, &FindToolBar::advanced, this, &FindPlugin::sendSwitchSearchResult);
71
72 return true;
73}
74
75void FindPlugin::sendSwitchSearchResult()
76{
77 editor.switchContext(tr("Advanced &Search"));
78}
79
80dpf::Plugin::ShutdownFlag FindPlugin::stop()
81{
82 qInfo() << __FUNCTION__;
83 return Sync;
84}
85
86
87