48
48
#include < QFileInfo>
49
49
#include < QRegExp>
50
50
#include < QProgressDialog>
51
+ #include < QMessageBox>
51
52
52
53
using namespace CPlusPlus ;
53
54
using namespace ProjectExplorer ;
@@ -120,11 +121,11 @@ Symbol* currentSymbol(Core::IEditor *editor)
120
121
121
122
// TODO: Recode it entirely.
122
123
// TODO: Duplicate detection.
123
- void Doxygen::createDocumentation (const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
124
+ bool Doxygen::createDocumentation (const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
124
125
{
125
126
// before continuing, test if the editor is actually showing a file.
126
127
if (!editor)
127
- return ;
128
+ return false ;
128
129
129
130
// get the widget for later.
130
131
TextEditor::TextEditorWidget *editorWidget = qobject_cast<TextEditor::TextEditorWidget*>(
@@ -144,38 +145,36 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
144
145
editorWidget->gotoNextWord ();
145
146
// infinite loop prevention
146
147
if (lastLine == editor->currentLine () && lastColumn == editor->currentColumn ())
147
- return ;
148
+ return false ;
148
149
lastLine = editor->currentLine ();
149
150
lastColumn = editor->currentColumn ();
150
151
lastSymbol = currentSymbol (editor);
151
152
}
152
153
// qDebug() << lastLine << " " << lastColumn;
153
154
if (!lastSymbol)
154
155
{
155
- return ;
156
+ return false ;
156
157
}
157
158
158
159
// We don't want to document multiple times.
159
160
// QRegExp duplicate("\\brief\s*([^\n\r])+");
160
- // Todo: fix when doc is not saved
161
- QRegExp duplicate (" ^(\\ s|\t )?\\ */" );
161
+ QRegExp commentClosing (" \\ */" );
162
162
QString text (editorWidget->document ()->toPlainText ());
163
163
QStringList lines (text.split (QRegExp (" \n |\r\n |\r " )));
164
164
165
- for (int i= 1 ; i <= 10 ; i++)
165
+ for (int i= 1 ; i <= 5 ; i++)
166
166
{
167
167
int prevLine = lastLine - i;
168
168
if (prevLine < 0 ) break ;
169
169
QString checkText (lines.at (prevLine));
170
- if (checkText.contains (duplicate ))
170
+ if (checkText.contains (commentClosing ))
171
171
{
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 ;
175
175
}
176
176
}
177
177
178
-
179
178
QStringList scopes = scopesForSymbol (lastSymbol);
180
179
Overview overview;
181
180
overview.showArgumentNames = true ;
@@ -204,7 +203,7 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
204
203
// quickfix when calling the method on "};" (end class) or "}" (end namespace)
205
204
if (indent.contains (QRegExp (" ^\\ };?" )))
206
205
{
207
- return ;
206
+ return false ;
208
207
}
209
208
210
209
if (indent.endsWith (' ~' ))
@@ -273,7 +272,7 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
273
272
if (DoxySettings.shortVarDoc )
274
273
{
275
274
printAtEnd = true ;
276
- docToWrite = DoxySettings.DoxyComment .doxShortVarDoc + " TODO" + DoxySettings.DoxyComment .doxShortVarDocEnd ;
275
+ docToWrite = DoxySettings.DoxyComment .doxShortVarDoc + " TODO: describe " + DoxySettings.DoxyComment .doxShortVarDocEnd ;
277
276
}
278
277
else
279
278
{
@@ -288,7 +287,7 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
288
287
// Never noticed it before, a useless comment block because of the Q_OBJECT macro
289
288
// so let's just ignore that will we?
290
289
if (overview.prettyName (name) == " qt_metacall" )
291
- return ;
290
+ return false ;
292
291
293
292
if (DoxySettings.verbosePrinting )
294
293
docToWrite += indent + DoxySettings.DoxyComment .doxNewLine + " fn " + overview.prettyName (name) + " \n " ;
@@ -353,22 +352,27 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor
353
352
editorWidget->moveCursor (QTextCursor::EndOfLine);
354
353
else
355
354
editorWidget->moveCursor (QTextCursor::StartOfBlock);
355
+
356
356
editorWidget->insertPlainText (docToWrite);
357
+ return true ;
357
358
}
359
+ return false ;
358
360
}
359
361
360
- void Doxygen::addFileComment (const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
362
+ bool Doxygen::addFileComment (const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
361
363
{
362
364
// before continuing, test if the editor is actually showing a file.
363
365
if (!editor)
364
- return ;
366
+ return false ;
365
367
366
368
// get the widget for later.
367
369
TextEditor::TextEditorWidget *editorWidget = qobject_cast<TextEditor::TextEditorWidget*>(
368
370
editor->widget ());
369
371
// get our symbol
370
372
editorWidget->gotoLine (1 , 0 );
371
373
editorWidget->insertPlainText (DoxySettings.fileComment + " \n " );
374
+
375
+ return true ;
372
376
}
373
377
374
378
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
400
404
}
401
405
}
402
406
403
- void Doxygen::documentFile (const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
407
+ uint Doxygen::documentFile (const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor)
404
408
{
405
409
// before continuing, test if the editor is actually showing a file.
406
410
if (!editor)
407
411
{
408
412
// qDebug() << "No editor";
409
- return ;
413
+ return 0 ;
410
414
}
411
415
412
416
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance ();
413
417
// ExtensionSystem::PluginManager::instance()->getObject<CPlusPlus::CppModelManagerInterface>();
414
418
if (!modelManager)
415
419
{
416
420
// qDebug() << "No modelManager";
417
- return ;
421
+ return 0 ;
418
422
}
419
423
420
424
const Snapshot snapshot = modelManager->snapshot ();
421
425
Document::Ptr doc = snapshot.document (editor->document ()->filePath ());
422
426
if (!doc)
423
427
{
424
428
// qDebug() << "No document";
425
- return ;
429
+ return 0 ;
426
430
}
427
431
428
432
// TODO : check
@@ -434,10 +438,9 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi
434
438
addFileComment (DoxySettings, editor);
435
439
}
436
440
// qDebug() << "No global symbols";
437
- return ;
441
+ return 0 ;
438
442
}
439
443
440
-
441
444
// check that as well...
442
445
Scope* scope = doc->scopeAt (0 ,0 );
443
446
if (!scope)
@@ -447,7 +450,7 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi
447
450
addFileComment (DoxySettings, editor);
448
451
}
449
452
// qDebug() << "No scope";
450
- return ;
453
+ return 0 ;
451
454
}
452
455
453
456
unsigned symbolcount = scope->memberCount ();
@@ -467,36 +470,53 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi
467
470
468
471
TextEditor::TextEditorWidget *editorWidget = qobject_cast<TextEditor::TextEditorWidget*>(editor->widget ());
469
472
473
+ uint count = 0 ;
470
474
if (editorWidget)
471
475
{
472
476
QList<const Symbol*>::iterator it = symmap.end ();
473
477
for (; it != symmap.begin (); --it)
474
478
{
475
479
const Symbol* sym = *(it-1 );
476
480
editorWidget->gotoLine (sym->line ());
477
- createDocumentation (DoxySettings, editor);
481
+ if (createDocumentation (DoxySettings, editor))
482
+ count++;
478
483
}
479
484
480
485
if (DoxySettings.fileCommentsEnabled )
481
486
{
482
- addFileComment (DoxySettings, editor);
487
+ if (addFileComment (DoxySettings, editor))
488
+ count++;
483
489
}
484
490
}
491
+ // qDebug() << "Count" << count;
492
+
493
+ return count;
485
494
}
486
495
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)
489
498
{
490
- documentProject (ProjectExplorer::SessionManager::startupProject (), DoxySettings);
499
+ return documentProject (ProjectExplorer::SessionManager::startupProject (), DoxySettings);
491
500
}
492
501
493
- void Doxygen::documentOpenedProject (const DoxygenSettingsStruct &DoxySettings)
502
+ uint Doxygen::documentCurrentProject (const DoxygenSettingsStruct &DoxySettings)
494
503
{
495
- documentProject (ProjectExplorer::ProjectTree::currentProject (), DoxySettings);
504
+ return documentProject (ProjectExplorer::ProjectTree::currentProject (), DoxySettings);
496
505
}
497
506
498
- void Doxygen::documentProject (ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings)
507
+ uint Doxygen::documentProject (ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings)
499
508
{
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 ;
500
520
Core::EditorManager *editorManager = Core::EditorManager::instance ();
501
521
QStringList files = p->files (ProjectExplorer::Project::ExcludeGeneratedFiles);
502
522
QProgressDialog progress (" Processing files..." , " Cancel" , 0 , files.size ());
@@ -533,7 +553,7 @@ void Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettings
533
553
if (editor)
534
554
{
535
555
documented = true ;
536
- documentFile (DoxySettings, editor);
556
+ count += documentFile (DoxySettings, editor);
537
557
}
538
558
}
539
559
@@ -555,11 +575,12 @@ void Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettings
555
575
{
556
576
Core::IEditor *editor = editorManager->openEditor (files[i]);
557
577
if (editor)
558
- addFileComment (DoxySettings, editor);
578
+ count += addFileComment (DoxySettings, editor);
559
579
}
560
580
}
561
581
}
562
582
progress.setValue (files.size ());
583
+ return count;
563
584
}
564
585
565
586
QString Doxygen::getProjectRoot ()
0 commit comments