Skip to content

Commit 8aa2716

Browse files
committed
Refactoring and fixes.
1 parent 3139ffd commit 8aa2716

File tree

4 files changed

+93
-53
lines changed

4 files changed

+93
-53
lines changed

doxygen.cpp

+55-34
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <QFileInfo>
4949
#include <QRegExp>
5050
#include <QProgressDialog>
51+
#include <QMessageBox>
5152

5253
using namespace CPlusPlus;
5354
using namespace ProjectExplorer;
@@ -120,11 +121,11 @@ Symbol* currentSymbol(Core::IEditor *editor)
120121

121122
// TODO: Recode it entirely.
122123
// TODO: Duplicate detection.
123-
void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
124+
bool Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
124125
{
125126
// before continuing, test if the editor is actually showing a file.
126127
if(!editor)
127-
return;
128+
return false;
128129

129130
// get the widget for later.
130131
TextEditor::TextEditorWidget *editorWidget = qobject_cast<TextEditor::TextEditorWidget*>(
@@ -144,38 +145,36 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
144145
editorWidget->gotoNextWord();
145146
// infinite loop prevention
146147
if(lastLine == editor->currentLine() && lastColumn == editor->currentColumn())
147-
return;
148+
return false;
148149
lastLine = editor->currentLine();
149150
lastColumn = editor->currentColumn();
150151
lastSymbol = currentSymbol(editor);
151152
}
152153
//qDebug() << lastLine << " " << lastColumn;
153154
if (!lastSymbol)
154155
{
155-
return;
156+
return false;
156157
}
157158

158159
// We don't want to document multiple times.
159160
//QRegExp duplicate("\\brief\s*([^\n\r])+");
160-
// Todo: fix when doc is not saved
161-
QRegExp duplicate("^(\\s|\t)?\\*/");
161+
QRegExp commentClosing("\\*/");
162162
QString text(editorWidget->document()->toPlainText());
163163
QStringList lines(text.split(QRegExp("\n|\r\n|\r")));
164164

165-
for (int i= 1; i <= 10; i++)
165+
for (int i= 1; i <= 5; i++)
166166
{
167167
int prevLine = lastLine - i;
168168
if (prevLine < 0) break;
169169
QString checkText(lines.at(prevLine));
170-
if (checkText.contains(duplicate))
170+
if (checkText.contains(commentClosing))
171171
{
172-
qDebug() << "Duplicate found in" << editor->document()->filePath().toString() << prevLine;
173-
qDebug() << checkText;
174-
return;
172+
//qDebug() << "Duplicate found in" << editor->document()->filePath().toString() << prevLine;
173+
//qDebug() << checkText;
174+
return false;
175175
}
176176
}
177177

178-
179178
QStringList scopes = scopesForSymbol(lastSymbol);
180179
Overview overview;
181180
overview.showArgumentNames = true;
@@ -204,7 +203,7 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
204203
// quickfix when calling the method on "};" (end class) or "}" (end namespace)
205204
if(indent.contains(QRegExp("^\\};?")))
206205
{
207-
return;
206+
return false;
208207
}
209208

210209
if(indent.endsWith('~'))
@@ -273,7 +272,7 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
273272
if(DoxySettings.shortVarDoc)
274273
{
275274
printAtEnd = true;
276-
docToWrite = DoxySettings.DoxyComment.doxShortVarDoc + "TODO" + DoxySettings.DoxyComment.doxShortVarDocEnd;
275+
docToWrite = DoxySettings.DoxyComment.doxShortVarDoc + "TODO: describe" + DoxySettings.DoxyComment.doxShortVarDocEnd;
277276
}
278277
else
279278
{
@@ -288,7 +287,7 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
288287
// Never noticed it before, a useless comment block because of the Q_OBJECT macro
289288
// so let's just ignore that will we?
290289
if(overview.prettyName(name) == "qt_metacall")
291-
return;
290+
return false;
292291

293292
if(DoxySettings.verbosePrinting)
294293
docToWrite += indent + DoxySettings.DoxyComment.doxNewLine + "fn " + overview.prettyName(name) + "\n";
@@ -353,22 +352,27 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
353352
editorWidget->moveCursor(QTextCursor::EndOfLine);
354353
else
355354
editorWidget->moveCursor(QTextCursor::StartOfBlock);
355+
356356
editorWidget->insertPlainText(docToWrite);
357+
return true;
357358
}
359+
return false;
358360
}
359361

360-
void Doxygen::addFileComment(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
362+
bool Doxygen::addFileComment(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
361363
{
362364
// before continuing, test if the editor is actually showing a file.
363365
if(!editor)
364-
return;
366+
return false;
365367

366368
// get the widget for later.
367369
TextEditor::TextEditorWidget *editorWidget = qobject_cast<TextEditor::TextEditorWidget*>(
368370
editor->widget());
369371
// get our symbol
370372
editorWidget->gotoLine(1, 0);
371373
editorWidget->insertPlainText(DoxySettings.fileComment + "\n");
374+
375+
return true;
372376
}
373377

374378
void Doxygen::addSymbol(const CPlusPlus::Symbol* symbol, QList<const Symbol*> &symmap)
@@ -400,29 +404,29 @@ void Doxygen::addSymbol(const CPlusPlus::Symbol* symbol, QList<const Symbol*> &s
400404
}
401405
}
402406

403-
void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
407+
uint Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
404408
{
405409
// before continuing, test if the editor is actually showing a file.
406410
if(!editor)
407411
{
408412
//qDebug() << "No editor";
409-
return;
413+
return 0;
410414
}
411415

412416
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
413417
//ExtensionSystem::PluginManager::instance()->getObject<CPlusPlus::CppModelManagerInterface>();
414418
if(!modelManager)
415419
{
416420
//qDebug() << "No modelManager";
417-
return;
421+
return 0;
418422
}
419423

420424
const Snapshot snapshot = modelManager->snapshot();
421425
Document::Ptr doc = snapshot.document(editor->document()->filePath());
422426
if(!doc)
423427
{
424428
//qDebug() << "No document";
425-
return;
429+
return 0;
426430
}
427431

428432
// TODO : check
@@ -434,10 +438,9 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi
434438
addFileComment(DoxySettings, editor);
435439
}
436440
//qDebug() << "No global symbols";
437-
return;
441+
return 0;
438442
}
439443

440-
441444
// check that as well...
442445
Scope* scope = doc->scopeAt(0,0);
443446
if(!scope)
@@ -447,7 +450,7 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi
447450
addFileComment(DoxySettings, editor);
448451
}
449452
//qDebug() << "No scope";
450-
return;
453+
return 0;
451454
}
452455

453456
unsigned symbolcount = scope->memberCount();
@@ -467,36 +470,53 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi
467470

468471
TextEditor::TextEditorWidget *editorWidget = qobject_cast<TextEditor::TextEditorWidget*>(editor->widget());
469472

473+
uint count = 0;
470474
if (editorWidget)
471475
{
472476
QList<const Symbol*>::iterator it = symmap.end();
473477
for(; it != symmap.begin(); --it)
474478
{
475479
const Symbol* sym = *(it-1);
476480
editorWidget->gotoLine(sym->line());
477-
createDocumentation(DoxySettings, editor);
481+
if (createDocumentation(DoxySettings, editor))
482+
count++;
478483
}
479484

480485
if(DoxySettings.fileCommentsEnabled)
481486
{
482-
addFileComment(DoxySettings, editor);
487+
if (addFileComment(DoxySettings, editor))
488+
count++;
483489
}
484490
}
491+
//qDebug() << "Count" << count;
492+
493+
return count;
485494
}
486495

487-
// TODO fix this!!!
488-
void Doxygen::documentActiveProject(const DoxygenSettingsStruct &DoxySettings)
496+
// TODO: fix this! Unused at the moment.
497+
uint Doxygen::documentSpecificProject(const DoxygenSettingsStruct &DoxySettings)
489498
{
490-
documentProject(ProjectExplorer::SessionManager::startupProject(), DoxySettings);
499+
return documentProject(ProjectExplorer::SessionManager::startupProject(), DoxySettings);
491500
}
492501

493-
void Doxygen::documentOpenedProject(const DoxygenSettingsStruct &DoxySettings)
502+
uint Doxygen::documentCurrentProject(const DoxygenSettingsStruct &DoxySettings)
494503
{
495-
documentProject(ProjectExplorer::ProjectTree::currentProject(), DoxySettings);
504+
return documentProject(ProjectExplorer::ProjectTree::currentProject(), DoxySettings);
496505
}
497506

498-
void Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings)
507+
uint Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings)
499508
{
509+
// prevent a crash if user launches this command with no project opened
510+
// You don't need to have an editor open for that.
511+
if (!p) {
512+
QMessageBox::warning((QWidget*)parent(),
513+
tr("Doxygen"),
514+
tr("You don't have any current project."),
515+
QMessageBox::Close, QMessageBox::NoButton);
516+
return 0;
517+
}
518+
519+
uint count = 0;
500520
Core::EditorManager *editorManager = Core::EditorManager::instance();
501521
QStringList files = p->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
502522
QProgressDialog progress("Processing files...", "Cancel", 0, files.size());
@@ -533,7 +553,7 @@ void Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettings
533553
if(editor)
534554
{
535555
documented = true;
536-
documentFile(DoxySettings, editor);
556+
count += documentFile(DoxySettings, editor);
537557
}
538558
}
539559

@@ -555,11 +575,12 @@ void Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettings
555575
{
556576
Core::IEditor *editor = editorManager->openEditor(files[i]);
557577
if(editor)
558-
addFileComment(DoxySettings, editor);
578+
count += addFileComment(DoxySettings, editor);
559579
}
560580
}
561581
}
562582
progress.setValue(files.size());
583+
return count;
563584
}
564585

565586
QString Doxygen::getProjectRoot()

doxygen.h

+10-7
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,21 @@
3030
namespace DoxyPlugin {
3131
namespace Internal {
3232

33-
class Doxygen
33+
class Doxygen : public QObject
3434
{
3535
public:
3636
static Doxygen* instance();
3737
static QString getProjectRoot();
3838
void addSymbol(const CPlusPlus::Symbol* symbol, QList<const CPlusPlus::Symbol*> &symmap);
39-
void createDocumentation(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor);
40-
void addFileComment(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor);
41-
void documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor);
42-
void documentProject(ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings);
43-
void documentActiveProject(const DoxygenSettingsStruct &DoxySettings);
44-
void documentOpenedProject(const DoxygenSettingsStruct &DoxySettings);
39+
bool createDocumentation(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor);
40+
bool addFileComment(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor);
41+
uint documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor);
42+
uint documentProject(ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings);
43+
uint documentSpecificProject(const DoxygenSettingsStruct &DoxySettings);
44+
uint documentCurrentProject(const DoxygenSettingsStruct &DoxySettings);
45+
46+
signals:
47+
void message(QString);
4548

4649
private:
4750
Doxygen();

doxygenplugin.cpp

+25-9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include <QKeySequence>
5454
#include <QStringList>
5555
#include <QFileInfo>
56+
#include <QString>
5657

5758
#include <QtPlugin>
5859

@@ -152,7 +153,7 @@ bool DoxygenPlugin::initialize(const QStringList &arguments, QString *errorStrin
152153
command->setAttribute(Core::Command::CA_UpdateText);
153154
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F8")));
154155
connect(m_doxygenDocumentActiveProjectAction, SIGNAL(triggered(bool)),
155-
this, SLOT(documentActiveProject()));
156+
this, SLOT(documentCurrentProject()));
156157
doxygenMenu->addAction(command);
157158

158159
// "compile" documentation action
@@ -203,18 +204,32 @@ void DoxygenPlugin::createDocumentation()
203204

204205
void DoxygenPlugin::documentFile()
205206
{
206-
Core::IEditor *editor = Core::EditorManager::instance()->currentEditor();
207-
Doxygen::instance()->documentFile(settings(), editor);
207+
if (QMessageBox::question((QWidget*)this->parent(),
208+
"Doxygen", "Document current File?",
209+
QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
210+
{
211+
Core::IEditor *editor = Core::EditorManager::instance()->currentEditor();
212+
uint count = Doxygen::instance()->documentFile(settings(), editor);
213+
QString msg;
214+
this->externalString(msg.sprintf("Doxygen blocs generated: %u", count));
215+
}
208216
}
209217

210-
void DoxygenPlugin::documentOpenedProject()
218+
void DoxygenPlugin::documentSpecificProject()
211219
{
212-
Doxygen::instance()->documentOpenedProject(settings());
220+
Doxygen::instance()->documentSpecificProject(settings());
213221
}
214222

215-
void DoxygenPlugin::documentActiveProject()
223+
void DoxygenPlugin::documentCurrentProject()
216224
{
217-
Doxygen::instance()->documentActiveProject(settings());
225+
if (QMessageBox::question((QWidget*)this->parent(),
226+
"Doxygen", "Document current project?",
227+
QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
228+
{
229+
uint count = Doxygen::instance()->documentCurrentProject(settings());
230+
QString msg;
231+
this->externalString(msg.sprintf("Doxygen blocs generated: %u", count));
232+
}
218233
}
219234

220235
bool DoxygenPlugin::buildDocumentation() // TODO: refactor
@@ -262,7 +277,7 @@ void DoxygenPlugin::doxyfileWizard() // TODO: refactor
262277
ProjectExplorer::Project *p = ProjectExplorer::ProjectTree::currentProject();
263278
if (!p) {
264279
QMessageBox::warning((QWidget*)parent(),
265-
tr("No Current Project"),
280+
tr("Doxygen"),
266281
tr("You don't have any current project."),
267282
QMessageBox::Close, QMessageBox::NoButton);
268283
return;
@@ -348,9 +363,10 @@ DoxygenResponse DoxygenPlugin::runDoxygen(const QStringList &arguments, int time
348363
return response;
349364
}
350365

351-
void DoxygenPlugin::externalString(const QString& text, bool)
366+
void DoxygenPlugin::externalString(const QString& text)
352367
{
353368
Core::MessageManager::write(text);
369+
Core::MessageManager::showOutputPane();
354370
}
355371

356372
DoxygenSettingsStruct DoxygenPlugin::settings() const

doxygenplugin.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ class DoxygenPlugin : public ExtensionSystem::IPlugin
7272
private slots:
7373
void createDocumentation();
7474
void documentFile();
75-
void documentOpenedProject();
76-
void documentActiveProject();
75+
void documentSpecificProject();
76+
void documentCurrentProject();
7777
bool buildDocumentation();
7878
void doxyfileWizard();
79-
void externalString(const QString&, bool);
79+
void externalString(const QString&);
8080
};
8181

8282
} // namespace Internal

0 commit comments

Comments
 (0)