-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsourceinfoplugin.cpp
More file actions
182 lines (146 loc) · 5.15 KB
/
sourceinfoplugin.cpp
File metadata and controls
182 lines (146 loc) · 5.15 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* Copyright 2018 Michal Srb <michalsrb@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "sourceinfoplugin.h"
#include "sourceinfoinlinenoteprovider.h"
#include "sourceinfotoolview.h"
#include <QUrl>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KPluginFactory>
#include <interfaces/icore.h>
#include <interfaces/idocument.h>
#include <interfaces/idocumentcontroller.h>
#include <interfaces/iuicontroller.h>
#include <debug.h>
using namespace KDevelop;
class SourceInfoToolViewFactory: public KDevelop::IToolViewFactory
{
public:
explicit SourceInfoToolViewFactory(QSharedPointer<SourceInfoConfig> config): m_config(config) {}
QWidget* create(QWidget *parent = nullptr) override
{
SourceInfoToolView *view = new SourceInfoToolView(m_config, parent);
return view;
}
Qt::DockWidgetArea defaultPosition() override
{
return Qt::RightDockWidgetArea;
}
QString id() const override
{
return QStringLiteral("org.kdevelop.SourceInfo");
}
private:
QSharedPointer<SourceInfoConfig> m_config;
};
//KPluginFactory stuff to load the plugin dynamically at runtime
K_PLUGIN_FACTORY_WITH_JSON(KDevExecuteFactory, "kdevsourceinfo.json", registerPlugin<SourceInfoPlugin>();)
SourceInfoPlugin::SourceInfoPlugin(QObject *parent, const QVariantList&)
: KDevelop::IPlugin("kdevsourceinfo", parent)
, m_config(QSharedPointer<SourceInfoConfig>::create())
, m_viewFactory(new SourceInfoToolViewFactory(m_config))
{
core()->uiController()->addToolView(i18n("Source Info"), m_viewFactory);
auto docController = ICore::self()->documentController();
for (auto *document : docController->openDocuments()) {
documentOpened(document);
}
connect(docController, &IDocumentController::textDocumentCreated, this, &SourceInfoPlugin::documentOpened);
connect(docController, &IDocumentController::documentClosed, this, &SourceInfoPlugin::documentClosed);
}
SourceInfoPlugin::~SourceInfoPlugin()
{
}
void SourceInfoPlugin::unload()
{
core()->uiController()->removeToolView(m_viewFactory);
auto docController = ICore::self()->documentController();
for (auto *document : docController->openDocuments()) {
documentClosed(document);
}
}
void SourceInfoPlugin::documentOpened(KDevelop::IDocument* document)
{
if (document->isTextDocument()) {
auto textDocument = document->textDocument();
auto *provider = new SourceInfoInlineNoteProvider(m_config, textDocument);
m_documentToProviderMap.insert(textDocument, provider);
}
}
void SourceInfoPlugin::documentClosed(KDevelop::IDocument* document)
{
if (document->isTextDocument()) {
auto textDocument = document->textDocument();
auto provider = m_documentToProviderMap.find(textDocument);
if (provider != m_documentToProviderMap.end()) {
delete *provider;
m_documentToProviderMap.erase(provider);
}
}
}
#if 0
QUrl SourceInfoPlugin::url( KDevelop::ILaunchConfiguration* cfg, QString& err_ ) const
{
QUrl url;
if( !cfg )
{
return url;
}
KConfigGroup grp = cfg->config();
QString host = grp.readEntry( SourceInfoPlugin::serverEntry, "" );
if( host.isEmpty() )
{
err_ = i18n("Empty server in launch configuration");
qCWarning(KDEV_SOURCEINFO) << "Launch Configuration:" << cfg->name() << err_;
return url;
}
QString path(grp.readEntry( SourceInfoPlugin::pathEntry, "" ));
if( !host.endsWith("/") && !path.isEmpty() && !path.startsWith("/") ) {
path.prepend("/");
}
if( !host.contains(QStringLiteral("://")) )
{
host.prepend(QStringLiteral("http://"));
}
url.setUrl(host + path);
url.setPort(grp.readEntry( SourceInfoPlugin::portEntry, 80 ));
{
QString q = grp.readEntry( SourceInfoPlugin::argumentsEntry, "" );
if (!q.isEmpty()) {
url.setQuery(q);
}
}
if( url.toString().isEmpty() ) {
err_ = i18n("Invalid launch configuration");
qCWarning(KDEV_SOURCEINFO) << "Launch Configuration:" << cfg->name() << err_;
return url;
}
qCDebug(KDEV_SOURCEINFO) << "Url:" << url.toString();
return url;
}
QString SourceInfoPlugin::browser( ILaunchConfiguration* cfg ) const
{
return cfg->config().readEntry( SourceInfoPlugin::browserEntry, "" );
}
QString SourceInfoPlugin::browserAppConfigTypeId() const
{
return _browserAppConfigTypeId;
}
#endif
#include "sourceinfoplugin.moc"