1 Star 0 Fork 0

Codeya-IDE/Codeya-IDE

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
gitreceiver.cpp 2.57 KB
Copy Edit Raw Blame History
Lu Zhen authored 2026-02-02 14:11 +08:00 . feat: init
// 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();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Codeya-IDE/codeya-ide.git
git@gitee.com:Codeya-IDE/codeya-ide.git
Codeya-IDE
codeya-ide
Codeya-IDE
master

Search