// SPDX-FileCopyrightText: 2024 - 2025 UnionTech Software Technology Co., Ltd.//// SPDX-License-Identifier: GPL-3.0-or-later#include "gitreceiver.h"#include "client/gitclient.h"#include "utils/gitmenumanager.h"#include "common/util/eventdefinitions.h"#include <QFileInfo>#include <QMenu>GitReceiver::GitReceiver(QObject *parent): dpf::EventHandler(parent){using namespace std::placeholders;eventHandleMap.insert(editor.switchedFile.name, std::bind(&GitReceiver::handleSwitchedFileEvent, this, _1));eventHandleMap.insert(editor.contextMenu.name, std::bind(&GitReceiver::handleContextMenuEvent, this, _1));eventHandleMap.insert(project.activatedProject.name, std::bind(&GitReceiver::handleProjectChangedEvent, this, _1));eventHandleMap.insert(project.deletedProject.name, std::bind(&GitReceiver::handleProjectChangedEvent, this, _1));}dpf::EventHandler::Type GitReceiver::type(){return dpf::EventHandler::Type::Sync;}QStringList GitReceiver::topics(){return { editor.topic, project.topic };}void GitReceiver::eventProcess(const dpf::Event &event){const auto &eventName = event.data().toString();if (!eventHandleMap.contains(eventName))return;eventHandleMap[eventName](event);}void GitReceiver::handleCursorPositionChangedEvent(const dpf::Event &event){const auto &fileName = event.property("fileName").toString();int line = event.property("line").toInt() + 1;QFileInfo info(fileName);GitClient::instance()->instantBlame(info.absolutePath(), fileName, line);}void GitReceiver::handleContextMenuEvent(const dpf::Event &event){auto editorMenu = event.property("menu").value<QMenu *>();if (editorMenu)editorMenu->addAction(GitMenuManager::instance()->gitAction());}void GitReceiver::handleSwitchedFileEvent(const dpf::Event &event){const auto &fileName = event.property("fileName").toString();GitMenuManager::instance()->setupFileMenu(fileName);bool ret = GitClient::instance()->setupInstantBlame(fileName);if (ret) {if (!eventHandleMap.contains(editor.cursorPositionChanged.name))eventHandleMap.insert(editor.cursorPositionChanged.name, std::bind(&GitReceiver::handleCursorPositionChangedEvent, this, std::placeholders::_1));} else if (eventHandleMap.contains(editor.cursorPositionChanged.name)) {eventHandleMap.remove(editor.cursorPositionChanged.name);GitClient::instance()->clearInstantBlame();}}void GitReceiver::handleProjectChangedEvent(const dpf::Event &event){GitMenuManager::instance()->setupProjectMenu();}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。