Repository navigation
Expand file tree
/
Copy pathgitqlientp.cpp
More file actions
140 lines (108 loc) · 3.91 KB
/
Copy pathgitqlientp.cpp
File metadata and controls
140 lines (108 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "gitqlientconstants.h"
#include "gitqlienttr.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/imode.h>
#include <coreplugin/coreicons.h>
#include <coreplugin/modemanager.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/macroexpander.h>
#include <extensionsystem/iplugin.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <cppeditor/cppeditorconstants.h>
#include <QAction>
#include <QMainWindow>
#include <QMenu>
#include <QMessageBox>
#include <QIcon>
#include <GitQlient.h>
using namespace Core;
using namespace Core::Internal;
using namespace ProjectExplorer::Constants;
namespace GitQlientPlugin::Internal
{
class GitQlientMode final : public IMode
{
Q_OBJECT
public:
GitQlientMode();
~GitQlientMode() final = default;
GitQlient *mGitImpl = nullptr;
};
GitQlientMode::GitQlientMode()
{
const Utils::Icon FLAT({ { ":/git.png", Utils::Theme::IconsBaseColor } });
setObjectName(QLatin1String("GitQlient"));
setDisplayName(Tr::tr("GitQlient"));
setIcon(Utils::Icon::combinedIcon({ FLAT, FLAT }));
setPriority(0);
Utils::Id id("GitQlient");
setId(id);
setEnabled(true);
setWidget(mGitImpl = new GitQlient());
mGitImpl->setArgumentsPostInit({ "-noLog" });
mGitImpl->setObjectName("mainWindow");
}
class GitQlientClass final : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "GitQlient.json")
GitQlientMode *mGitQlientMode = nullptr;
QAction *mBlame = nullptr;
public:
GitQlientClass() = default;
~GitQlientClass() = default;
void initialize()
{
mBlame = new QAction(tr("Blame"), this);
connect(mBlame, &QAction::triggered, this, &GitQlientClass::onBlame);
auto am = Core::ActionManager::instance();
Core::Context globalcontext(Core::Constants::C_GLOBAL);
auto command = am->registerAction(mBlame, "Blame", globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
// TODO: Set a shortcut
// command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F5")));
auto menu = am->createMenu("GitQlient");
menu->menu()->setTitle("GitQlient");
menu->addAction(command);
if (auto contextMenu = ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT))
{
contextMenu->addSeparator();
contextMenu->addMenu(menu);
}
auto fileMenu = ActionManager::actionContainer(M_FILECONTEXT);
fileMenu->addMenu(menu, G_FILE_OTHER);
mGitQlientMode = new GitQlientMode();
connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeAboutToChange, this,
&GitQlientClass::aboutToChange);
}
void onBlame()
{
QMessageBox::information(Core::ICore::mainWindow(), tr("Blame"), tr("Hello from GitQlient!"));
}
ShutdownFlag aboutToShutdown() { return SynchronousShutdown; }
void aboutToChange(Utils::Id mode)
{
if (mode == mGitQlientMode->id())
{
bool found;
Utils::globalMacroExpander()->value("CurrentProject:Path", &found);
QStringList currentOpenedProjects;
for (auto project : ProjectExplorer::ProjectManager::projects())
currentOpenedProjects.append(project->projectDirectory().toUrlishString());
mGitQlientMode->mGitImpl->setRepositories(currentOpenedProjects);
Core::ModeManager::instance()->setFocusToCurrentMode();
}
}
};
} // namespace GitQlientPlugin::Internal
#include <gitqlientp.moc>