| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "projectcore.h" |
| 6 | #include "transceiver/sendevents.h" |
| 7 | #include "mainframe/projectkeeper.h" |
| 8 | #include "mainframe/projecttree.h" |
| 9 | #include "common/common.h" |
| 10 | #include "base/abstractmenu.h" |
| 11 | #include "base/abstractaction.h" |
| 12 | #include "base/abstractcentral.h" |
| 13 | #include "base/abstractwidget.h" |
| 14 | #include "services/window/windowservice.h" |
| 15 | #include "services/project/projectservice.h" |
| 16 | |
| 17 | #include <QProcess> |
| 18 | #include <QAction> |
| 19 | #include <QLabel> |
| 20 | #include <QTreeView> |
| 21 | |
| 22 | using namespace dpfservice; |
| 23 | void ProjectCore::initialize() |
| 24 | { |
| 25 | qInfo() << __FUNCTION__; |
| 26 | // 发布工程服务 |
| 27 | QString errStr; |
| 28 | auto &ctx = dpfInstance.serviceContext(); |
| 29 | if (!ctx.load(ProjectService::name(), &errStr)) { |
| 30 | qCritical() << errStr; |
| 31 | abort(); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | bool ProjectCore::start() |
| 36 | { |
| 37 | qInfo() << __FUNCTION__; |
| 38 | auto &ctx = dpfInstance.serviceContext(); |
| 39 | WindowService *windowService = ctx.service<WindowService>(WindowService::name()); |
| 40 | if (windowService) { |
| 41 | if (windowService->addWidgetWorkspace) { |
| 42 | auto view = new AbstractWidget(ProjectKeeper::instance()->treeView()); |
| 43 | windowService->addWidgetWorkspace(MWCWT_PROJECTS, view); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | if (windowService && windowService->addCentralNavigation) { |
| 48 | //windowService->addCentralNavigation(MWNA_RUNTIME, new AbstractCentral(RuntimeManager::instance()->getRuntimeWidget())); |
| 49 | } |
| 50 | |
| 51 | QObject::connect(&dpf::Listener::instance(), &dpf::Listener::pluginsStarted, |
| 52 | this, &ProjectCore::pluginsStartedMain); |
| 53 | |
| 54 | |
| 55 | using namespace std::placeholders; |
| 56 | ProjectService *projectService = ctx.service<ProjectService>(ProjectService::name()); |
| 57 | if (projectService) { |
| 58 | ProjectTree *treeView = ProjectKeeper::instance()->treeView(); |
| 59 | if (!projectService->projectView.addRootItem) { |
| 60 | projectService->projectView.addRootItem |
| 61 | = std::bind(&ProjectTree::appendRootItem, treeView, _1); |
| 62 | } |
| 63 | if (!projectService->projectView.removeRootItem) { |
| 64 | projectService->projectView.removeRootItem |
| 65 | = std::bind(&ProjectTree::removeRootItem, treeView, _1); |
| 66 | } |
| 67 | if (!projectService->projectView.expandedDepth) { |
| 68 | projectService->projectView.expandedDepth |
| 69 | = std::bind(&ProjectTree::expandedProjectDepth, treeView, _1, _2); |
| 70 | } |
| 71 | if (!projectService->projectView.expandedAll) { |
| 72 | projectService->projectView.expandedAll |
| 73 | = std::bind(&ProjectTree::expandedProjectAll, treeView, _1); |
| 74 | } |
| 75 | if (!projectService->getAllProjectInfo) { |
| 76 | projectService->getAllProjectInfo |
| 77 | = std::bind(&ProjectTree::getAllProjectInfo, treeView); |
| 78 | } |
| 79 | if (!projectService->getProjectInfo) { |
| 80 | projectService->getProjectInfo |
| 81 | = std::bind(&ProjectTree::getProjectInfo, treeView, _1, _2); |
| 82 | } |
| 83 | if (!projectService->getActiveProjectInfo) { |
| 84 | projectService->getActiveProjectInfo |
| 85 | = std::bind(&ProjectTree::getActiveProjectInfo, treeView); |
| 86 | } |
| 87 | } |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | dpf::Plugin::ShutdownFlag ProjectCore::stop() |
| 92 | { |
| 93 | qInfo() << __FUNCTION__; |
| 94 | return Sync; |
| 95 | } |
| 96 | |
| 97 | void ProjectCore::pluginsStartedMain() |
| 98 | { |
| 99 | auto &ctx = dpfInstance.serviceContext(); |
| 100 | ProjectService *projectService = ctx.service<ProjectService>(ProjectService::name()); |
| 101 | WindowService *windowService = ctx.service<WindowService>(WindowService::name()); |
| 102 | if (projectService && windowService) { |
| 103 | QStringList kitNames = projectService->supportGeneratorName<ProjectGenerator>(); |
| 104 | for (auto kitName : kitNames) { |
| 105 | auto generator = projectService->createGenerator<ProjectGenerator>(kitName); |
| 106 | if (generator) { |
| 107 | for(auto lang : generator->supportLanguages()) { |
| 108 | auto action = generator->openProjectAction(lang, kitName); |
| 109 | if (action) |
| 110 | windowService->addOpenProjectAction(lang, new AbstractAction(action)); |
| 111 | } |
| 112 | QObject::connect(generator, &ProjectGenerator::itemChanged, |
| 113 | ProjectKeeper::instance()->treeView(), |
| 114 | &ProjectTree::itemModified, Qt::UniqueConnection); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |