1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "findreceiver.h"
6#include "common/common.h"
7#include "services/project/projectservice.h"
8
9FindReceiver::FindReceiver(QObject *parent)
10 : dpf::EventHandler(parent)
11{
12
13}
14
15dpf::EventHandler::Type FindReceiver::type()
16{
17 return dpf::EventHandler::Type::Sync;
18}
19
20QStringList FindReceiver::topics()
21{
22 return { project.topic, editor.topic };
23}
24
25void FindReceiver::eventProcess(const dpf::Event &event)
26{
27 if (event.data() == project.activedProject.name) {
28 dpfservice::ProjectInfo projectInfo = qvariant_cast<dpfservice::ProjectInfo>(
29 event.property(project.activedProject.pKeys[0]));
30 QString workspace = projectInfo.workspaceFolder();
31 QString language = projectInfo.language();
32 emit FindEventTransmit::instance()->sendProjectPath(workspace, language);
33 } else if(event.data() == project.openProject.name) {
34 dpfservice::ProjectInfo projectInfo = qvariant_cast<dpfservice::ProjectInfo>(
35 event.property(project.openProject.pKeys[0]));
36 QString workspace = projectInfo.workspaceFolder();
37 QString language = projectInfo.language();
38 emit FindEventTransmit::instance()->sendProjectPath(workspace, language);
39 } else if (event.data() == project.deletedProject.name){
40 dpfservice::ProjectInfo projectInfo = qvariant_cast<dpfservice::ProjectInfo>(
41 event.property(project.deletedProject.pKeys[0]));
42 QString workspace = projectInfo.workspaceFolder();
43 emit FindEventTransmit::instance()->sendRemovedProject(workspace);
44 } else if (event.data() == editor.openedFile.name) {
45 QString filePath = event.property(editor.openedFile.pKeys[0]).toString();
46 emit FindEventTransmit::instance()->sendCurrentEditFile(filePath, true);
47 } else if (event.data() == editor.closedFile.name) {
48 QString filePath = event.property(editor.switchedFile.pKeys[0]).toString();
49 emit FindEventTransmit::instance()->sendCurrentEditFile(filePath, false);
50 } else if (event.data() == editor.switchedFile.name) {
51 QString filePath = event.property(editor.switchedFile.pKeys[0]).toString();
52 emit FindEventTransmit::instance()->sendCurrentEditFile(filePath, true);
53 }
54}
55
56FindEventTransmit::FindEventTransmit(QObject *parent)
57 : QObject(parent)
58{
59}
60
61FindEventTransmit::~FindEventTransmit()
62{
63
64}
65
66FindEventTransmit* FindEventTransmit::instance()
67{
68 static FindEventTransmit instance;
69 return &instance;
70}
71