1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "codeeditor.h"
6#include "codelens/codelens.h"
7#include "textedittabwidget/textedittabwidget.h"
8#include "textedittabwidget/language/cpp/texteditcpp.h"
9#include "textedittabwidget/language/cmake/texteditcmake.h"
10#include "textedittabwidget/language/java/texteditjava.h"
11#include "textedittabwidget/language/python/texteditpython.h"
12#include "textedittabwidget/language/js/texteditjs.h"
13#include "textedittabwidget/texteditsplitter.h"
14#include "mainframe/naveditmainwindow.h"
15#include "mainframe/texteditkeeper.h"
16#include "transceiver/codeeditorreceiver.h"
17
18#include "base/abstractmenu.h"
19#include "base/abstractaction.h"
20#include "base/abstractcentral.h"
21#include "base/abstractwidget.h"
22
23#include "services/window/windowservice.h"
24#include "services/language/languageservice.h"
25#include "common/widget/outputpane.h"
26
27#include <QAction>
28#include <QSplitter>
29
30using namespace dpfservice;
31
32const QString SAVE_ALL_DOCUMENTS = CodeEditor::tr("Save All Documents");
33const QString CLOSE_ALL_DOCUMENTS = CodeEditor::tr("Close All Documents");
34const QString PRINT = CodeEditor::tr("Print");
35
36void CodeEditor::initialize()
37{
38 qInfo() << __FUNCTION__;
39 TextEditKeeper::impl<TextEdit>("");
40 TextEditKeeper::impl<TextEditPython>();
41 TextEditKeeper::impl<TextEditCpp>();
42 TextEditKeeper::impl<TextEditCmake>();
43 TextEditKeeper::impl<TextEditJava>();
44 TextEditKeeper::impl<TextEditJS>();
45
46 QString errStr;
47 auto &ctx = dpfInstance.serviceContext();
48 if (!ctx.load(dpfservice::LanguageService::name(), &errStr)) {
49 qCritical() << errStr;
50 abort();
51 }
52}
53
54bool CodeEditor::start()
55{
56 qInfo() << __FUNCTION__;
57 auto &ctx = dpfInstance.serviceContext();
58 WindowService *windowService = ctx.service<WindowService>(WindowService::name());
59
60 if (windowService) {
61 NavEditMainWindow *navEditWindow = NavEditMainWindow::instance();
62 TextEditSplitter *editManager = TextEditSplitter::instance();
63 navEditWindow->setWidgetEdit(new AbstractCentral(editManager));
64 windowService->addCentralNavigation(MWNA_EDIT, new AbstractCentral(navEditWindow));
65
66 using namespace std::placeholders;
67 if (!windowService->addWidgetWorkspace) {
68 windowService->addWidgetWorkspace = std::bind(&NavEditMainWindow::addWidgetWorkspace, navEditWindow, _1, _2);
69 }
70
71 if (!windowService->addContextWidget) {
72 windowService->addContextWidget = std::bind(&NavEditMainWindow::addContextWidget, navEditWindow, _1, _2, _3);
73 }
74
75 if (!windowService->removeContextWidget) {
76 windowService->removeContextWidget = std::bind(&NavEditMainWindow::removeContextWidget, navEditWindow, _1);
77 }
78
79 if (!windowService->setWidgetEdit) {
80 windowService->setWidgetEdit = std::bind(&NavEditMainWindow::setWidgetEdit, navEditWindow, _1);
81 }
82
83 windowService->addContextWidget(QTabWidget::tr("Code &Lens"), new AbstractWidget(CodeLens::instance()), "Lens");
84
85 if (!windowService->setWidgetWatch) {
86 windowService->setWidgetWatch = std::bind(&NavEditMainWindow::setWidgetWatch, navEditWindow, _1);
87 }
88
89 if (!windowService->addFindToolBar) {
90 windowService->addFindToolBar = std::bind(&NavEditMainWindow::addFindToolBar, navEditWindow, _1);
91 }
92
93 if (!windowService->showFindToolBar) {
94 windowService->showFindToolBar = std::bind(&NavEditMainWindow::showFindToolBar, navEditWindow);
95 }
96
97 auto sep = new QAction();
98 sep->setSeparator(true);
99 windowService->addAction(MWM_FILE, new AbstractAction(sep));
100
101 windowService->addContextWidget(tr("&Application Output"), new AbstractWidget(OutputPane::instance()), "Application");
102 }
103
104 return true;
105}
106
107dpf::Plugin::ShutdownFlag CodeEditor::stop()
108{
109 qInfo() << __FUNCTION__;
110 return Sync;
111}
112
113