forked from fpoussin/qtcreator-doxygen
-
Notifications
You must be signed in to change notification settings - Fork 10
/
doxygenplugin.cpp
361 lines (310 loc) · 13.1 KB
/
doxygenplugin.cpp
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/**************************************************************************
**
** This file is part of Doxygen plugin for Qt Creator
**
** Copyright (c) 2009 Kevin Tanguy ([email protected]).
** Copyright (c) 2015 Fabien Poussin ([email protected]).
**
** This plugin is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as
** published by the Free Software Foundation, either version 2.1
** of the License, or (at your option) any later version.
**
** This plugin 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 Lesser General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Doxygen Plugin. If not, see <http://www.gnu.org/licenses/>.
**/
#include "doxygenplugin.h"
#include "doxygen.h"
#include "doxygenconstants.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <cppeditor/cppeditorconstants.h>
#include <cpptools/cpptoolsconstants.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/session.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/parameteraction.h>
#include <utils/qtcassert.h>
#include <utils/synchronousprocess.h>
#include <QAction>
#include <QFileInfo>
#include <QKeySequence>
#include <QMainWindow>
#include <QMenu>
#include <QMessageBox>
#include <QProcess>
#include <QString>
#include <QStringList>
#include <QtPlugin>
using namespace ExtensionSystem;
using namespace DoxyPlugin;
using namespace DoxyPlugin::Internal;
// Timeout for building documentation
enum { doxygenTimeOut = 120 };
static const char CMD_ID_DOXYGEN_MAINVIEW[] = "Doxygen.MainView";
static const char CMD_ID_DOXYGEN_MENU[] = "Doxygen.Menu";
static const char CMD_ID_CREATEDOCUMENTATION[] = "Doxygen.CreateDocumentation";
static const char CMD_ID_DOCUMENTFILE[] = "Doxygen.DocumentFile";
static const char CMD_ID_DOCUMENTOPENEDPROJECT[] = "Doxygen.DocumentOpenedProject";
static const char CMD_ID_DOCUMENTACTIVEPROJECT[] = "Doxygen.DocumentActiveProject";
static const char CMD_ID_BUILDDOCUMENTATION[] = "Doxygen.BuildDocumentation";
static const char CMD_ID_DOXYFILEWIZARD[] = "Doxygen.RunWizard";
DoxygenPlugin* DoxygenPlugin::m_instance = nullptr;
DoxygenPlugin::DoxygenPlugin()
{
m_instance = this;
}
DoxygenPlugin::~DoxygenPlugin()
{
// Unregister objects from the plugin manager's object pool
// Delete members
m_instance = nullptr;
m_settings->deleteLater();
}
bool DoxygenPlugin::initialize(const QStringList& arguments, QString* errorString)
{
// Register objects in the plugin manager's object pool
// Load settings
// Add actions to menus
// Connect to other plugins' signals
// In the initialize function, a plugin can be sure that the plugins it
// depends on have initialized their members.
using namespace Constants;
using namespace Core::Constants;
using namespace ExtensionSystem;
Q_UNUSED(arguments);
Q_UNUSED(errorString);
// settings dialog :)
m_settings = new DoxygenSettings;
//addAutoReleasedObject(m_settings);
Core::ActionManager* am = Core::ActionManager::instance();
Core::Context globalcontext(C_GLOBAL);
//Core::Context context(CMD_ID_DOXYGEN_MAINVIEW);
Core::ActionContainer* toolsContainer = am->actionContainer(Core::Constants::M_TOOLS);
Core::ActionContainer* doxygenMenu = am->createMenu(Core::Id(CMD_ID_DOXYGEN_MENU));
doxygenMenu->menu()->setTitle(tr("&Doxygen"));
toolsContainer->addMenu(doxygenMenu);
// put action in our own menu in "Tools"
// create documentation for symbol under cursor
Core::Command* command;
m_doxygenCreateDocumentationAction = new QAction(tr("Document current entity"), this);
command = am->registerAction(m_doxygenCreateDocumentationAction, CMD_ID_CREATEDOCUMENTATION, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F9")));
connect(m_doxygenCreateDocumentationAction, SIGNAL(triggered(bool)), this, SLOT(documentEntity()));
doxygenMenu->addAction(command);
// Don't forget the contextual menu
Core::ActionContainer* contextMenu = am->createMenu(CppEditor::Constants::M_CONTEXT);
contextMenu->addAction(command);
// create documentation for a whole file
m_doxygenDocumentFileAction = new QAction(tr("Document current file"), this);
command = am->registerAction(m_doxygenDocumentFileAction, CMD_ID_DOCUMENTFILE, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F5")));
connect(m_doxygenDocumentFileAction, SIGNAL(triggered(bool)), this, SLOT(documentFile()));
doxygenMenu->addAction(command);
/*
// create documentation for a whole project of the currently opened file
m_doxygenDocumentOpenedProjectAction = new QAction(tr("Document whole project of opened file"), this);
command = am->registerAction(m_doxygenDocumentOpenedProjectAction,
CMD_ID_DOCUMENTOPENEDPROJECT, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F7")));
connect(m_doxygenDocumentOpenedProjectAction, SIGNAL(triggered(bool)),
this, SLOT(documentOpenedProject()));
doxygenMenu->addAction(command);
*/
// create documentation for a whole project
m_doxygenDocumentActiveProjectAction = new QAction(tr("Document current project"), this);
command = am->registerAction(m_doxygenDocumentActiveProjectAction,
CMD_ID_DOCUMENTACTIVEPROJECT, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F8")));
connect(m_doxygenDocumentActiveProjectAction, SIGNAL(triggered(bool)),
this, SLOT(documentCurrentProject()));
doxygenMenu->addAction(command);
// "compile" documentation action
m_doxygenBuildDocumentationAction = new QAction(tr("Build Doxygen Documentation"), this);
command = am->registerAction(m_doxygenBuildDocumentationAction, CMD_ID_BUILDDOCUMENTATION, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F4")));
connect(m_doxygenBuildDocumentationAction, SIGNAL(triggered(bool)), this, SLOT(buildDocumentation()));
doxygenMenu->addAction(command);
// edit Doxyfile action
m_doxygenDoxyfileWizardAction = new QAction(tr("Edit Doxyfile"), this);
command = am->registerAction(m_doxygenDoxyfileWizardAction, CMD_ID_DOXYFILEWIZARD, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F6")));
connect(m_doxygenDoxyfileWizardAction, SIGNAL(triggered(bool)), this, SLOT(doxyfileWizard()));
doxygenMenu->addAction(command);
// Internal connections
Doxygen* dox = Doxygen::instance();
connect(dox, SIGNAL(message(QString)), this, SLOT(externalString(QString)));
connect(this, SIGNAL(doxyDocumentEntity(DoxygenSettingsStruct, Core::IEditor*)),
dox, SLOT(documentEntity(DoxygenSettingsStruct, Core::IEditor*)));
connect(this, SIGNAL(doxyDocumentFile(DoxygenSettingsStruct, Core::IEditor*)),
dox, SLOT(documentFile(DoxygenSettingsStruct, Core::IEditor*)));
connect(this, SIGNAL(doxyDocumentCurrentProject(DoxygenSettingsStruct)),
dox, SLOT(documentCurrentProject(DoxygenSettingsStruct)));
// Process connection for Doxygen
m_process = new QProcess();
connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(processExited(int, QProcess::ExitStatus)));
connect(m_process, SIGNAL(readyRead()),
this, SLOT(readProcessOutput()));
return true;
}
void DoxygenPlugin::extensionsInitialized()
{
// Retrieve objects from the plugin manager's object pool
// In the extensionsInitialized function, a plugin can be sure that all
// plugins that depend on it are completely initialized.
}
ExtensionSystem::IPlugin::ShutdownFlag DoxygenPlugin::aboutToShutdown()
{
// Save settings
// Disconnect from signals that are not needed during shutdown
// Hide UI (if you add UI that is not in the main window directly)
return SynchronousShutdown;
}
void DoxygenPlugin::documentEntity()
{
Core::IEditor* editor = Core::EditorManager::instance()->currentEditor();
emit doxyDocumentEntity(settings(), editor);
}
void DoxygenPlugin::documentFile()
{
if (QMessageBox::question((QWidget*)this->parent(),
"Doxygen", "Document current File?",
QMessageBox::Yes, QMessageBox::No)
== QMessageBox::Yes) {
Core::IEditor* editor = Core::EditorManager::instance()->currentEditor();
emit doxyDocumentFile(settings(), editor);
}
}
void DoxygenPlugin::documentSpecificProject()
{
Doxygen::instance()->documentSpecificProject(settings());
}
void DoxygenPlugin::documentCurrentProject()
{
emit doxyDocumentCurrentProject(settings());
}
bool DoxygenPlugin::buildDocumentation() // TODO: refactor
{
// TODO, allow configuration of the command
// the default here will just run doxygen at the project root
ProjectExplorer::Project* p = ProjectExplorer::ProjectTree::currentProject();
if (!p) {
QMessageBox::warning((QWidget*)parent(),
tr("Doxygen"),
tr("You don't have any current project."),
QMessageBox::Close, QMessageBox::NoButton);
return false;
}
QString projectRoot = Doxygen::getProjectRoot();
if (!projectRoot.size())
return false;
QString doxyFile = projectRoot;
doxyFile += settings().doxyfileFileName;
QStringList args;
// create default Doxyfile if it doesn't exist
QFileInfo doxyFileInfo(doxyFile);
if (!doxyFileInfo.exists()) {
args << "-g" << doxyFile;
runDoxygen(args, projectRoot);
return true;
}
args << doxyFile;
runDoxygen(args, projectRoot);
return false;
}
void DoxygenPlugin::doxyfileWizard() // TODO: refactor
{
// prevent a crash if user launches this command with no project opened
// You don't need to have an editor open for that.
ProjectExplorer::Project* p = ProjectExplorer::ProjectTree::currentProject();
if (!p) {
QMessageBox::warning((QWidget*)parent(),
tr("Doxygen"),
tr("You don't have any current project."),
QMessageBox::Close, QMessageBox::NoButton);
return;
}
QString projectRoot = p->projectDirectory().toString();
QString executable = settings().doxywizardCommand;
QStringList arglist(settings().doxyfileFileName);
bool ret = QProcess::startDetached(settings().doxywizardCommand, arglist, projectRoot);
if (!ret) {
const QString outputText = tr("Failed to launch %1\n").arg(executable);
externalString(outputText);
}
}
void DoxygenPlugin::runDoxygen(const QStringList& arguments, QString workingDirectory)
{
const QString executable = settings().doxygenCommand;
if (executable.isEmpty()) {
externalString(tr("No doxygen executable specified"));
return;
}
const QStringList allArgs = settings().addOptions(arguments);
const QString outputText = tr("Executing: %1 %2\n").arg(executable).arg(DoxygenSettingsStruct::formatArguments(allArgs));
externalString(outputText);
m_process->close();
m_process->waitForFinished();
m_process->setWorkingDirectory(workingDirectory);
m_process->start(executable, allArgs);
if (!m_process->waitForStarted(5000))
qDebug("Could not start %s within 5 seconds", executable.toStdString().c_str());
return;
}
void DoxygenPlugin::externalString(const QString& text)
{
Core::MessageManager::write(text);
Core::MessageManager::showOutputPane();
}
void DoxygenPlugin::processExited(int returnCode, QProcess::ExitStatus exitStatus)
{
DoxygenResponse response;
response.error = true;
response.stdErr = QLatin1String(m_process->readAllStandardError());
response.stdOut = QLatin1String(m_process->readAllStandardOutput());
switch (exitStatus) {
case QProcess::NormalExit:
response.error = false;
break;
case QProcess::CrashExit:
response.message = tr("The process terminated with exit code %1.").arg(returnCode);
break;
}
if (response.error)
externalString(response.message);
else
externalString(tr("Doxygen ran successfully"));
}
void DoxygenPlugin::readProcessOutput()
{
externalString(QLatin1String(m_process->readAll()));
}
DoxygenSettingsStruct DoxygenPlugin::settings() const
{
return m_settings->settings();
}
DoxygenPlugin* DoxygenPlugin::instance()
{
return m_instance;
}