diff --git a/doxygen.cpp b/doxygen.cpp index 60a345d..411c892 100644 --- a/doxygen.cpp +++ b/doxygen.cpp @@ -48,6 +48,7 @@ #include #include #include +#include using namespace CPlusPlus; using namespace ProjectExplorer; @@ -120,11 +121,11 @@ Symbol* currentSymbol(Core::IEditor *editor) // TODO: Recode it entirely. // TODO: Duplicate detection. -void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor) +bool Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor) { // before continuing, test if the editor is actually showing a file. if(!editor) - return; + return false; // get the widget for later. TextEditor::TextEditorWidget *editorWidget = qobject_cast( @@ -144,7 +145,7 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor editorWidget->gotoNextWord(); // infinite loop prevention if(lastLine == editor->currentLine() && lastColumn == editor->currentColumn()) - return; + return false; lastLine = editor->currentLine(); lastColumn = editor->currentColumn(); lastSymbol = currentSymbol(editor); @@ -152,30 +153,28 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor //qDebug() << lastLine << " " << lastColumn; if (!lastSymbol) { - return; + return false; } // We don't want to document multiple times. //QRegExp duplicate("\\brief\s*([^\n\r])+"); - // Todo: fix when doc is not saved - QRegExp duplicate("^(\\s|\t)?\\*/"); + QRegExp commentClosing("\\*/"); QString text(editorWidget->document()->toPlainText()); QStringList lines(text.split(QRegExp("\n|\r\n|\r"))); - for (int i= 1; i <= 10; i++) + for (int i= 1; i <= 5; i++) { int prevLine = lastLine - i; if (prevLine < 0) break; QString checkText(lines.at(prevLine)); - if (checkText.contains(duplicate)) + if (checkText.contains(commentClosing)) { - qDebug() << "Duplicate found in" << editor->document()->filePath().toString() << prevLine; - qDebug() << checkText; - return; + //qDebug() << "Duplicate found in" << editor->document()->filePath().toString() << prevLine; + //qDebug() << checkText; + return false; } } - QStringList scopes = scopesForSymbol(lastSymbol); Overview overview; overview.showArgumentNames = true; @@ -204,7 +203,7 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor // quickfix when calling the method on "};" (end class) or "}" (end namespace) if(indent.contains(QRegExp("^\\};?"))) { - return; + return false; } if(indent.endsWith('~')) @@ -273,7 +272,7 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor if(DoxySettings.shortVarDoc) { printAtEnd = true; - docToWrite = DoxySettings.DoxyComment.doxShortVarDoc + "TODO" + DoxySettings.DoxyComment.doxShortVarDocEnd; + docToWrite = DoxySettings.DoxyComment.doxShortVarDoc + "TODO: describe" + DoxySettings.DoxyComment.doxShortVarDocEnd; } else { @@ -288,7 +287,7 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor // Never noticed it before, a useless comment block because of the Q_OBJECT macro // so let's just ignore that will we? if(overview.prettyName(name) == "qt_metacall") - return; + return false; if(DoxySettings.verbosePrinting) docToWrite += indent + DoxySettings.DoxyComment.doxNewLine + "fn " + overview.prettyName(name) + "\n"; @@ -353,15 +352,18 @@ void Doxygen::createDocumentation(const DoxygenSettingsStruct &DoxySettings, Cor editorWidget->moveCursor(QTextCursor::EndOfLine); else editorWidget->moveCursor(QTextCursor::StartOfBlock); + editorWidget->insertPlainText(docToWrite); + return true; } + return false; } -void Doxygen::addFileComment(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor) +bool Doxygen::addFileComment(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor) { // before continuing, test if the editor is actually showing a file. if(!editor) - return; + return false; // get the widget for later. TextEditor::TextEditorWidget *editorWidget = qobject_cast( @@ -369,6 +371,8 @@ void Doxygen::addFileComment(const DoxygenSettingsStruct &DoxySettings, Core::IE // get our symbol editorWidget->gotoLine(1, 0); editorWidget->insertPlainText(DoxySettings.fileComment + "\n"); + + return true; } void Doxygen::addSymbol(const CPlusPlus::Symbol* symbol, QList &symmap) @@ -400,13 +404,13 @@ void Doxygen::addSymbol(const CPlusPlus::Symbol* symbol, QList &s } } -void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor) +uint Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor) { // before continuing, test if the editor is actually showing a file. if(!editor) { //qDebug() << "No editor"; - return; + return 0; } CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance(); @@ -414,7 +418,7 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi if(!modelManager) { //qDebug() << "No modelManager"; - return; + return 0; } const Snapshot snapshot = modelManager->snapshot(); @@ -422,7 +426,7 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi if(!doc) { //qDebug() << "No document"; - return; + return 0; } // TODO : check @@ -434,10 +438,9 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi addFileComment(DoxySettings, editor); } //qDebug() << "No global symbols"; - return; + return 0; } - // check that as well... Scope* scope = doc->scopeAt(0,0); if(!scope) @@ -447,7 +450,7 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi addFileComment(DoxySettings, editor); } //qDebug() << "No scope"; - return; + return 0; } unsigned symbolcount = scope->memberCount(); @@ -467,6 +470,7 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi TextEditor::TextEditorWidget *editorWidget = qobject_cast(editor->widget()); + uint count = 0; if (editorWidget) { QList::iterator it = symmap.end(); @@ -474,29 +478,45 @@ void Doxygen::documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEdi { const Symbol* sym = *(it-1); editorWidget->gotoLine(sym->line()); - createDocumentation(DoxySettings, editor); + if (createDocumentation(DoxySettings, editor)) + count++; } if(DoxySettings.fileCommentsEnabled) { - addFileComment(DoxySettings, editor); + if (addFileComment(DoxySettings, editor)) + count++; } } + //qDebug() << "Count" << count; + + return count; } -// TODO fix this!!! -void Doxygen::documentActiveProject(const DoxygenSettingsStruct &DoxySettings) +// TODO: fix this! Unused at the moment. +uint Doxygen::documentSpecificProject(const DoxygenSettingsStruct &DoxySettings) { - documentProject(ProjectExplorer::SessionManager::startupProject(), DoxySettings); + return documentProject(ProjectExplorer::SessionManager::startupProject(), DoxySettings); } -void Doxygen::documentOpenedProject(const DoxygenSettingsStruct &DoxySettings) +uint Doxygen::documentCurrentProject(const DoxygenSettingsStruct &DoxySettings) { - documentProject(ProjectExplorer::ProjectTree::currentProject(), DoxySettings); + return documentProject(ProjectExplorer::ProjectTree::currentProject(), DoxySettings); } -void Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings) +uint Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings) { + // prevent a crash if user launches this command with no project opened + // You don't need to have an editor open for that. + if (!p) { + QMessageBox::warning((QWidget*)parent(), + tr("Doxygen"), + tr("You don't have any current project."), + QMessageBox::Close, QMessageBox::NoButton); + return 0; + } + + uint count = 0; Core::EditorManager *editorManager = Core::EditorManager::instance(); QStringList files = p->files(ProjectExplorer::Project::ExcludeGeneratedFiles); QProgressDialog progress("Processing files...", "Cancel", 0, files.size()); @@ -533,7 +553,7 @@ void Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettings if(editor) { documented = true; - documentFile(DoxySettings, editor); + count += documentFile(DoxySettings, editor); } } @@ -555,11 +575,12 @@ void Doxygen::documentProject(ProjectExplorer::Project *p, const DoxygenSettings { Core::IEditor *editor = editorManager->openEditor(files[i]); if(editor) - addFileComment(DoxySettings, editor); + count += addFileComment(DoxySettings, editor); } } } progress.setValue(files.size()); + return count; } QString Doxygen::getProjectRoot() diff --git a/doxygen.h b/doxygen.h index cf05d32..65eea54 100644 --- a/doxygen.h +++ b/doxygen.h @@ -30,18 +30,21 @@ namespace DoxyPlugin { namespace Internal { -class Doxygen +class Doxygen : public QObject { public: static Doxygen* instance(); static QString getProjectRoot(); void addSymbol(const CPlusPlus::Symbol* symbol, QList &symmap); - void createDocumentation(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor); - void addFileComment(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor); - void documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor); - void documentProject(ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings); - void documentActiveProject(const DoxygenSettingsStruct &DoxySettings); - void documentOpenedProject(const DoxygenSettingsStruct &DoxySettings); + bool createDocumentation(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor); + bool addFileComment(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor); + uint documentFile(const DoxygenSettingsStruct &DoxySettings, Core::IEditor *editor); + uint documentProject(ProjectExplorer::Project *p, const DoxygenSettingsStruct &DoxySettings); + uint documentSpecificProject(const DoxygenSettingsStruct &DoxySettings); + uint documentCurrentProject(const DoxygenSettingsStruct &DoxySettings); + +signals: + void message(QString); private: Doxygen(); diff --git a/doxygenplugin.cpp b/doxygenplugin.cpp index ac789fe..9280f17 100644 --- a/doxygenplugin.cpp +++ b/doxygenplugin.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include @@ -152,7 +153,7 @@ bool DoxygenPlugin::initialize(const QStringList &arguments, QString *errorStrin command->setAttribute(Core::Command::CA_UpdateText); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F8"))); connect(m_doxygenDocumentActiveProjectAction, SIGNAL(triggered(bool)), - this, SLOT(documentActiveProject())); + this, SLOT(documentCurrentProject())); doxygenMenu->addAction(command); // "compile" documentation action @@ -203,18 +204,32 @@ void DoxygenPlugin::createDocumentation() void DoxygenPlugin::documentFile() { - Core::IEditor *editor = Core::EditorManager::instance()->currentEditor(); - Doxygen::instance()->documentFile(settings(), editor); + if (QMessageBox::question((QWidget*)this->parent(), + "Doxygen", "Document current File?", + QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) + { + Core::IEditor *editor = Core::EditorManager::instance()->currentEditor(); + uint count = Doxygen::instance()->documentFile(settings(), editor); + QString msg; + this->externalString(msg.sprintf("Doxygen blocs generated: %u", count)); + } } -void DoxygenPlugin::documentOpenedProject() +void DoxygenPlugin::documentSpecificProject() { - Doxygen::instance()->documentOpenedProject(settings()); + Doxygen::instance()->documentSpecificProject(settings()); } -void DoxygenPlugin::documentActiveProject() +void DoxygenPlugin::documentCurrentProject() { - Doxygen::instance()->documentActiveProject(settings()); + if (QMessageBox::question((QWidget*)this->parent(), + "Doxygen", "Document current project?", + QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) + { + uint count = Doxygen::instance()->documentCurrentProject(settings()); + QString msg; + this->externalString(msg.sprintf("Doxygen blocs generated: %u", count)); + } } bool DoxygenPlugin::buildDocumentation() // TODO: refactor @@ -262,7 +277,7 @@ void DoxygenPlugin::doxyfileWizard() // TODO: refactor ProjectExplorer::Project *p = ProjectExplorer::ProjectTree::currentProject(); if (!p) { QMessageBox::warning((QWidget*)parent(), - tr("No Current Project"), + tr("Doxygen"), tr("You don't have any current project."), QMessageBox::Close, QMessageBox::NoButton); return; @@ -348,9 +363,10 @@ DoxygenResponse DoxygenPlugin::runDoxygen(const QStringList &arguments, int time return response; } -void DoxygenPlugin::externalString(const QString& text, bool) +void DoxygenPlugin::externalString(const QString& text) { Core::MessageManager::write(text); + Core::MessageManager::showOutputPane(); } DoxygenSettingsStruct DoxygenPlugin::settings() const diff --git a/doxygenplugin.h b/doxygenplugin.h index f42da29..7b5b4b1 100644 --- a/doxygenplugin.h +++ b/doxygenplugin.h @@ -72,11 +72,11 @@ class DoxygenPlugin : public ExtensionSystem::IPlugin private slots: void createDocumentation(); void documentFile(); - void documentOpenedProject(); - void documentActiveProject(); + void documentSpecificProject(); + void documentCurrentProject(); bool buildDocumentation(); void doxyfileWizard(); - void externalString(const QString&, bool); + void externalString(const QString&); }; } // namespace Internal