1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "projectcorereceiver.h" |
6 | #include "common/common.h" |
7 | #include "mainframe/projecttree.h" |
8 | #include "mainframe/projectkeeper.h" |
9 | #include "services/project/projectservice.h" |
10 | #include "services/window/windowelement.h" |
11 | |
12 | ProjectCoreReceiver::ProjectCoreReceiver(QObject *parent) |
13 | : dpf::EventHandler (parent) |
14 | , dpf::AutoEventHandlerRegister<ProjectCoreReceiver> () |
15 | { |
16 | |
17 | } |
18 | |
19 | dpf::EventHandler::Type ProjectCoreReceiver::type() |
20 | { |
21 | return dpf::EventHandler::Type::Sync; |
22 | } |
23 | |
24 | QStringList ProjectCoreReceiver::topics() |
25 | { |
26 | return {project.topic}; //绑定menu 事件 |
27 | } |
28 | |
29 | void ProjectCoreReceiver::eventProcess(const dpf::Event &event) |
30 | { |
31 | using namespace dpfservice; |
32 | if (event.data() == project.activeProject.name) { |
33 | auto infos = ProjectKeeper::instance()->treeView()->getAllProjectInfo(); |
34 | QString kitName = event.property(project.openProject.pKeys[0]).toString(); |
35 | QString language = event.property(project.openProject.pKeys[1]).toString(); |
36 | QString workspace = event.property(project.openProject.pKeys[2]).toString(); |
37 | ProjectKeeper::instance()->treeView()->activeProjectInfo(kitName, language, workspace); |
38 | } else if (event.data() == project.openProject.name) { |
39 | navigation.doSwitch(dpfservice::MWNA_EDIT); |
40 | auto &ctx = dpfInstance.serviceContext(); |
41 | ProjectService *projectService = ctx.service<ProjectService>(ProjectService::name()); |
42 | if (projectService) { |
43 | // "kitName", "language", "workspace" |
44 | QString kitName = event.property(project.openProject.pKeys[0]).toString(); |
45 | QString language = event.property(project.openProject.pKeys[1]).toString(); |
46 | QString workspace = event.property(project.openProject.pKeys[2]).toString(); |
47 | auto generator = projectService->createGenerator<ProjectGenerator>(kitName); |
48 | if (!generator) |
49 | return; |
50 | QStringList supportLangs = generator->supportLanguages(); |
51 | if (supportLangs.contains(language)) { |
52 | if (generator->canOpenProject(kitName, language, workspace)) { |
53 | generator->doProjectOpen(language, kitName, workspace); |
54 | } else if (generator->isOpenedProject(kitName, language, workspace)) { |
55 | project.activeProject(kitName, language, workspace); |
56 | } |
57 | } |
58 | } |
59 | } |
60 | } |
61 | |
62 | |
63 | |