diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 419f1f2f5db..e1058767cd9 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -43,7 +43,8 @@ SUBDIRS = plugin_coreplugin \ plugin_qmlprofiler \ plugin_remotelinux \ plugin_madde \ - plugin_valgrind + plugin_valgrind \ + plugin_todo isEmpty(IDE_PACKAGE_MODE) { SUBDIRS += plugin_helloworld \ @@ -51,7 +52,6 @@ isEmpty(IDE_PACKAGE_MODE) { } else:!isEmpty(UPDATEINFO_ENABLE) { SUBDIRS += plugin_updateinfo } - linux-* { SUBDIRS += debugger/ptracepreload.pro } @@ -306,3 +306,9 @@ plugin_macros.depends = plugin_texteditor plugin_macros.depends += plugin_find plugin_macros.depends += plugin_locator plugin_macros.depends += plugin_coreplugin + +plugin_todo.subdir = todo +plugin_todo.depends = plugin_coreplugin +plugin_todo.depends += plugin_projectexplorer +plugin_todo.depends += plugin_texteditor +plugin_todo.depends += plugin_cpptools \ No newline at end of file diff --git a/src/plugins/todo/INSTALL b/src/plugins/todo/INSTALL deleted file mode 100644 index e992d0a0271..00000000000 --- a/src/plugins/todo/INSTALL +++ /dev/null @@ -1,7 +0,0 @@ -Installation. -1. Download QtCreator sources. -2. Build QtCreator from sources or download and install binary. -3. Change todoplugin.pro, You need QTC_BUILD_DIR set to your path to qtcreator binary and set QTC_SOURCE_DIR your path to qtcreator source -4. Build plugin: - qmake - make diff --git a/src/plugins/todo/LICENSE.BSD b/src/plugins/todo/LICENSE.BSD deleted file mode 100644 index a3c72c27b54..00000000000 --- a/src/plugins/todo/LICENSE.BSD +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2010, Vasiliy Sorokin -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -* Neither the name of the vsorokin nor the names of its contributors may be used to endorse or -promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS -BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, -OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY -WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/plugins/todo/Todo.pluginspec.in b/src/plugins/todo/Todo.pluginspec.in new file mode 100644 index 00000000000..ad44b5dca89 --- /dev/null +++ b/src/plugins/todo/Todo.pluginspec.in @@ -0,0 +1,20 @@ + + Dmitry Savchenko + (C) 2012 Dmitry Savchenko, (C) 2010 Vasiliy Sorokin + +Commercial Usage + +Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia. + +GNU Lesser General Public License Usage + +Alternatively, this plugin may be used under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. Please review the following information to ensure the GNU Lesser General Public License version 2.1 requirements will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + + Adds pane that lists all TODO, FIXME, etc. entries in comments. + http://qt.nokia.com/ + + + + + + diff --git a/src/plugins/todo/addkeyworddialog.cpp b/src/plugins/todo/addkeyworddialog.cpp deleted file mode 100644 index 436a185627a..00000000000 --- a/src/plugins/todo/addkeyworddialog.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "addkeyworddialog.h" -#include "ui_addkeyworddialog.h" -#include - - -AddKeywordDialog::AddKeywordDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::AddKeywordDialog) -{ - ui->setupUi(this); - this->ui->listWidget->setViewMode(QListWidget::IconMode); - this->ui->listWidget->addItem(new QListWidgetItem(QIcon(":/info"), "information")); - this->ui->listWidget->addItem(new QListWidgetItem(QIcon(":/warning"), "warning")); - this->ui->listWidget->addItem(new QListWidgetItem(QIcon(":/error"), "error")); - connect(this->ui->pushButton, SIGNAL(clicked()), this, SLOT(chooseColor())); -} - -AddKeywordDialog::~AddKeywordDialog() -{ - delete ui; -} - -QString AddKeywordDialog::keywordName() -{ - return this->ui->lineEdit->text(); -} - -QColor AddKeywordDialog::keywordColor() -{ - return QColor(this->ui->colorEdit->text()); -} - -QIcon AddKeywordDialog::keywordIcon() -{ - return this->ui->listWidget->currentItem()->icon(); -} - -void AddKeywordDialog::chooseColor() -{ - QColorDialog *dialog = new QColorDialog(QColor(this->ui->colorEdit->text()),this); - this->ui->colorEdit->setText(dialog->getColor().name()); -} diff --git a/src/plugins/todo/addkeyworddialog.h b/src/plugins/todo/addkeyworddialog.h deleted file mode 100644 index 39c8e0d5721..00000000000 --- a/src/plugins/todo/addkeyworddialog.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ADDKEYWORDDIALOG_H -#define ADDKEYWORDDIALOG_H - -#include - -namespace Ui { - class AddKeywordDialog; -} - -class AddKeywordDialog : public QDialog -{ - Q_OBJECT - -public: - explicit AddKeywordDialog(QWidget *parent = 0); - ~AddKeywordDialog(); - QString keywordName(); - QColor keywordColor(); - QIcon keywordIcon(); - -public slots: - void chooseColor(); - -private: - Ui::AddKeywordDialog *ui; -}; - -#endif // ADDKEYWORDDIALOG_H diff --git a/src/plugins/todo/constants.h b/src/plugins/todo/constants.h new file mode 100644 index 00000000000..01ee0505fe9 --- /dev/null +++ b/src/plugins/todo/constants.h @@ -0,0 +1,92 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef CONSTANTS_H +#define CONSTANTS_H + +#include + +namespace Todo { +namespace Constants { + +// Default todo item background colors +const char COLOR_TODO_BG[] = "#ccffcc"; +const char COLOR_WARNING_BG[] = "#ffffcc"; +const char COLOR_FIXME_BG[] = "#ffcccc"; +const char COLOR_BUG_BG[] = "#ffcccc"; +const char COLOR_NOTE_BG[] = "#e0ebff"; + +// Todo item icons + +// http://en.wikipedia.org/wiki/File:Information_icon_with_gradient_background.svg, +// public domain, tuned a bit +const char ICON_INFO[] = ":/todoplugin/images/info.png"; + +// Dummy, needs to be changed +const char ICON_TODO[] = ":/todoplugin/images/todo.png"; + +const char ICON_WARNING[] = ":/projectexplorer/images/compile_warning.png"; +const char ICON_ERROR[] = ":/projectexplorer/images/compile_error.png"; + +// Public domain, I’m the author +const char ICON_CURRENT_FILE[] = ":/todoplugin/images/current-file.png"; +const char ICON_WHOLE_PROJECT[] = ":/todoplugin/images/whole-project.png"; + + +// Settings entries +const char SETTINGS_GROUP[] = "TodoPlugin"; +const char SCANNING_SCOPE[] = "ScanningScope"; +const char ITEMS_DISPLAY_PLACE[] = "ItemsDisplayPlace"; +const char KEYWORDS_LIST[] = "Keywords"; + +// TODO Output TreeWidget columns +enum OutputColumnIndex { + OUTPUT_COLUMN_TEXT, + OUTPUT_COLUMN_FILE, + OUTPUT_COLUMN_LINE, + OUTPUT_COLUMN_LAST +}; + +const char OUPTUT_COLUMN_TEXT_TITLE[] = QT_TRANSLATE_NOOP("TodoOutputPane", "Description"); +const char OUTPUT_COLUMN_FILE_TITLE[] = QT_TRANSLATE_NOOP("TodoOutputPane", "File"); +const char OUTPUT_COLUMN_LINE_TITLE[] = QT_TRANSLATE_NOOP("TodoOutputPane", "Line"); + +const int OUTPUT_TOOLBAR_SPACER_WIDHT = 25; + +const int OUTPUT_PANE_UPDATE_INTERVAL = 2000; +const char OUTPUT_PANE_TITLE[] = QT_TRANSLATE_NOOP("TodoOutputPane", "To-Do Entries"); + +} // namespace Constants +} // namespace Todo + +#endif // CONSTANTS_H diff --git a/src/plugins/todo/cpptodoitemsscanner.cpp b/src/plugins/todo/cpptodoitemsscanner.cpp new file mode 100644 index 00000000000..04aefdbe19d --- /dev/null +++ b/src/plugins/todo/cpptodoitemsscanner.cpp @@ -0,0 +1,113 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "cpptodoitemsscanner.h" + +#include +#include + +namespace Todo { +namespace Internal { + +CppTodoItemsScanner::CppTodoItemsScanner(const KeywordList &keywordList, QObject *parent) : + TodoItemsScanner(keywordList, parent) +{ + CPlusPlus::CppModelManagerInterface *modelManager = CPlusPlus::CppModelManagerInterface::instance(); + + connect(modelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)), this, + SLOT(documentUpdated(CPlusPlus::Document::Ptr)), Qt::DirectConnection); +} + +bool CppTodoItemsScanner::shouldProcessFile(const QString &fileName) +{ + CPlusPlus::CppModelManagerInterface *modelManager = CPlusPlus::CppModelManagerInterface::instance(); + + foreach (const CPlusPlus::CppModelManagerInterface::ProjectInfo &info, modelManager->projectInfos()) + if (info.project().data()->files(ProjectExplorer::Project::ExcludeGeneratedFiles).contains(fileName)) + return true; + + return false; +} + +void CppTodoItemsScanner::keywordListChanged() +{ + // We need to rescan everything known to the code model + // TODO: It would be nice to only tokenize the source files, not update the code model entirely. + + CPlusPlus::CppModelManagerInterface *modelManager = CPlusPlus::CppModelManagerInterface::instance(); + + QStringList filesToBeUpdated; + foreach (const CPlusPlus::CppModelManagerInterface::ProjectInfo &info, modelManager->projectInfos()) + filesToBeUpdated << info.project().data()->files(ProjectExplorer::Project::ExcludeGeneratedFiles); + + modelManager->updateSourceFiles(filesToBeUpdated); +} + +void CppTodoItemsScanner::documentUpdated(CPlusPlus::Document::Ptr doc) +{ + if (shouldProcessFile(doc->fileName())) + processDocument(doc); +} + +void CppTodoItemsScanner::processDocument(CPlusPlus::Document::Ptr doc) +{ + QList itemList; + + CPlusPlus::TranslationUnit *translationUnit = doc->translationUnit(); + + for (unsigned i = 0; i < translationUnit->commentCount(); ++i) { + + // Get comment source + CPlusPlus::Token token = doc->translationUnit()->commentAt(i); + QByteArray source = doc->utf8Source().mid(token.begin(), token.length()).trimmed(); + + if ((token.kind() == CPlusPlus::T_COMMENT) || (token.kind() == CPlusPlus::T_DOXY_COMMENT)) { + // Remove trailing "*/" + source = source.left(source.length() - 2); + } + + // Process every line of the comment + // TODO: Do not create QStringList, just iterate through a string tracking line endings. + QStringList commentLines = QString::fromUtf8(source).split("\n", QString::SkipEmptyParts); + unsigned lineNumber = 0; + translationUnit->getPosition(token.begin(), &lineNumber); + for (int j = 0; j < commentLines.count(); ++j) { + const QString &commentLine = commentLines.at(j); + processCommentLine(doc->fileName(), commentLine, lineNumber + j, itemList); + } + } + emit itemsFetched(doc->fileName(), itemList); +} + +} +} diff --git a/src/plugins/todo/cpptodoitemsscanner.h b/src/plugins/todo/cpptodoitemsscanner.h new file mode 100644 index 00000000000..dc5ff1d8daa --- /dev/null +++ b/src/plugins/todo/cpptodoitemsscanner.h @@ -0,0 +1,65 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef CPPTODOITEMSSCANNER_H +#define CPPTODOITEMSSCANNER_H + +#include "todoitemsscanner.h" + +#include + +namespace Todo { +namespace Internal { + +class CppTodoItemsScanner : public TodoItemsScanner +{ + Q_OBJECT + +public: + explicit CppTodoItemsScanner(const KeywordList &keywordList, QObject *parent = 0); + +protected: + bool shouldProcessFile(const QString &fileName); + void keywordListChanged(); + +private slots: + void documentUpdated(CPlusPlus::Document::Ptr doc); + +private: + void processDocument(CPlusPlus::Document::Ptr doc); +}; + +} +} + +#endif // CPPTODOITEMSSCANNER_H diff --git a/src/plugins/todo/icons.qrc b/src/plugins/todo/icons.qrc deleted file mode 100755 index 045f39daa08..00000000000 --- a/src/plugins/todo/icons.qrc +++ /dev/null @@ -1,8 +0,0 @@ - - - images/error.png - images/info.png - images/warning.png - images/todo.png - - diff --git a/src/plugins/todo/images/current-file.png b/src/plugins/todo/images/current-file.png new file mode 100644 index 00000000000..486c7112bf9 Binary files /dev/null and b/src/plugins/todo/images/current-file.png differ diff --git a/src/plugins/todo/images/error.png b/src/plugins/todo/images/error.png deleted file mode 100755 index 87cd0b0125d..00000000000 Binary files a/src/plugins/todo/images/error.png and /dev/null differ diff --git a/src/plugins/todo/images/info.png b/src/plugins/todo/images/info.png index f6af9f83f4d..5c800c3ce61 100755 Binary files a/src/plugins/todo/images/info.png and b/src/plugins/todo/images/info.png differ diff --git a/src/plugins/todo/images/todo.png b/src/plugins/todo/images/todo.png index 78e6b5840db..32160841b06 100644 Binary files a/src/plugins/todo/images/todo.png and b/src/plugins/todo/images/todo.png differ diff --git a/src/plugins/todo/images/warning.png b/src/plugins/todo/images/warning.png deleted file mode 100755 index 0bc86a3d12b..00000000000 Binary files a/src/plugins/todo/images/warning.png and /dev/null differ diff --git a/src/plugins/todo/images/whole-project.png b/src/plugins/todo/images/whole-project.png new file mode 100644 index 00000000000..595eea76f49 Binary files /dev/null and b/src/plugins/todo/images/whole-project.png differ diff --git a/src/plugins/todo/keyword.cpp b/src/plugins/todo/keyword.cpp index a1d549c34a4..e37f9655ea0 100644 --- a/src/plugins/todo/keyword.cpp +++ b/src/plugins/todo/keyword.cpp @@ -1,26 +1,61 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + #include "keyword.h" -Keyword::Keyword() +namespace Todo { +namespace Internal { + +Keyword::Keyword() : color(Qt::white) { } -Keyword::Keyword(QString name_, QIcon icon_, QColor warningColor_) : - name(name_), icon(icon_), warningColor(warningColor_) +bool Keyword::equals(const Keyword &other) const { + return (this->name == other.name) + && (this->iconResource == other.iconResource) + && (this->color == other.color); } -QDataStream &operator<<(QDataStream &out, const Keyword &myObj) +bool operator ==(Keyword &k1, Keyword &k2) { - out << myObj.name; - out << myObj.icon; - out << myObj.warningColor; - return out; + return k1.equals(k2); } -QDataStream &operator>>(QDataStream &in, Keyword &myObj) +bool operator !=(Keyword &k1, Keyword &k2) { - in >> myObj.name; - in >> myObj.icon; - in >> myObj.warningColor; - return in; + return !k1.equals(k2); } + +} // namespace Internal +} // namespace Todo diff --git a/src/plugins/todo/keyword.h b/src/plugins/todo/keyword.h index 41a59dc3b2d..d8f0bdf437d 100644 --- a/src/plugins/todo/keyword.h +++ b/src/plugins/todo/keyword.h @@ -1,3 +1,36 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + #ifndef KEYWORD_H #define KEYWORD_H @@ -7,23 +40,26 @@ #include #include +namespace Todo { +namespace Internal { + class Keyword { public: Keyword(); - Keyword(QString name_, QIcon icon_, QColor warningColor_); + QString name; - QIcon icon; - QColor warningColor; + QString iconResource; + QColor color; + bool equals(const Keyword &other) const; }; -typedef QList KeywordsList; +typedef QList KeywordList; -QDataStream &operator<<(QDataStream &out, const Keyword &myObj); -QDataStream &operator>>(QDataStream &in, Keyword &myObj); +bool operator ==(Keyword &k1, Keyword &k2); +bool operator !=(Keyword &k1, Keyword &k2); - -Q_DECLARE_METATYPE(KeywordsList) -Q_DECLARE_METATYPE(Keyword) +} // namespace Internal +} // namespace Todo #endif // KEYWORD_H diff --git a/src/plugins/todo/keyworddialog.cpp b/src/plugins/todo/keyworddialog.cpp new file mode 100644 index 00000000000..c40bb18bf65 --- /dev/null +++ b/src/plugins/todo/keyworddialog.cpp @@ -0,0 +1,106 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "keyworddialog.h" +#include "ui_keyworddialog.h" +#include "constants.h" + +#include + +namespace Todo { +namespace Internal { + +KeywordDialog::KeywordDialog(const Keyword &keyword, QWidget *parent) : + QDialog(parent), + ui(new Ui::AddKeywordDialog) +{ + ui->setupUi(this); + setupListWidget(keyword.iconResource); + setupColorWidgets(keyword.color); + ui->keywordNameEdit->setText(keyword.name); +} + +KeywordDialog::~KeywordDialog() +{ + delete ui; +} + +Keyword KeywordDialog::keyword() +{ + Keyword result; + result.name = ui->keywordNameEdit->text(); + result.iconResource = ui->listWidget->currentItem()->data(Qt::UserRole).toString(); + result.color = ui->colorEdit->text(); + + return result; +} + +void KeywordDialog::colorSelected(const QColor &color) +{ + ui->colorEdit->setText(color.name()); +} + +void KeywordDialog::setupListWidget(const QString &selectedIcon) +{ + ui->listWidget->setViewMode(QListWidget::IconMode); + + QListWidgetItem *item = new QListWidgetItem(QIcon(Constants::ICON_INFO), "information"); + item->setData(Qt::UserRole, Constants::ICON_INFO); + ui->listWidget->addItem(item); + + item = new QListWidgetItem(QIcon(Constants::ICON_WARNING), "warning"); + item->setData(Qt::UserRole, Constants::ICON_WARNING); + ui->listWidget->addItem(item); + + item = new QListWidgetItem(QIcon(Constants::ICON_ERROR), "error"); + item->setData(Qt::UserRole, Constants::ICON_ERROR); + ui->listWidget->addItem(item); + + for (int i = 0; i < ui->listWidget->count(); ++i) { + item = ui->listWidget->item(i); + if (item->data(Qt::UserRole).toString() == selectedIcon) { + ui->listWidget->setCurrentItem(item); + break; + } + } +} + +void KeywordDialog::setupColorWidgets(const QColor &color) +{ + ui->colorButton->setColor(color); + ui->colorEdit->setText(color.name()); + connect(ui->colorButton, SIGNAL(colorChanged(QColor)), SLOT(colorSelected(QColor))); +} + +} // namespace Internal +} // namespace Todo diff --git a/src/plugins/todo/keyworddialog.h b/src/plugins/todo/keyworddialog.h new file mode 100644 index 00000000000..191ae336187 --- /dev/null +++ b/src/plugins/todo/keyworddialog.h @@ -0,0 +1,69 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef ADDKEYWORDDIALOG_H +#define ADDKEYWORDDIALOG_H + +#include "keyword.h" + +#include + +namespace Todo { +namespace Internal { + +namespace Ui { + class AddKeywordDialog; +} + +class KeywordDialog : public QDialog +{ + Q_OBJECT +public: + KeywordDialog(const Keyword &keyword, QWidget *parent = 0); + ~KeywordDialog(); + + Keyword keyword(); + +private slots: + void colorSelected(const QColor &color); + +private: + void setupListWidget(const QString &selectedIcon); + void setupColorWidgets(const QColor &color); + Ui::AddKeywordDialog *ui; +}; + +} // namespace Internal +} // namespace Todo + +#endif // ADDKEYWORDDIALOG_H diff --git a/src/plugins/todo/addkeyworddialog.ui b/src/plugins/todo/keyworddialog.ui similarity index 68% rename from src/plugins/todo/addkeyworddialog.ui rename to src/plugins/todo/keyworddialog.ui index 3d7c0269870..31029151c60 100644 --- a/src/plugins/todo/addkeyworddialog.ui +++ b/src/plugins/todo/keyworddialog.ui @@ -1,23 +1,23 @@ - AddKeywordDialog - + Todo::Internal::AddKeywordDialog + 0 0 379 - 225 + 233 - Dialog + Keyword - Icons + Icon @@ -33,11 +33,8 @@ Color - - - QFormLayout::ExpandingFieldsGrow - - + + \#HHHHHH; @@ -47,10 +44,19 @@ - - - - Choose + + + + + 0 + 0 + + + + + 64 + 0 + @@ -64,7 +70,7 @@ - + @@ -85,12 +91,19 @@ + + + Utils::QtColorButton + QToolButton +
utils/qtcolorbutton.h
+
+
buttonBox accepted() - AddKeywordDialog + Todo::Internal::AddKeywordDialog accept() @@ -106,7 +119,7 @@ buttonBox rejected() - AddKeywordDialog + Todo::Internal::AddKeywordDialog reject() diff --git a/src/plugins/todo/lineparser.cpp b/src/plugins/todo/lineparser.cpp new file mode 100644 index 00000000000..1345f529e5b --- /dev/null +++ b/src/plugins/todo/lineparser.cpp @@ -0,0 +1,148 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "lineparser.h" + +#include + +namespace Todo { +namespace Internal { + +LineParser::LineParser() +{ +} + +LineParser::LineParser(const KeywordList &keywordList) +{ + setKeywordList(keywordList); +} + +void LineParser::setKeywordList(const KeywordList &keywordList) +{ + m_keywords = keywordList; +} + +QList LineParser::parse(const QString &line) +{ + QMap entryCandidates = findKeywordEntryCandidates(line); + QList entries = keywordEntriesFromCandidates(entryCandidates, line); + return todoItemsFromKeywordEntries(entries); +} + +LineParser::KeywordEntryCandidates LineParser::findKeywordEntryCandidates(const QString &line) +{ + KeywordEntryCandidates entryCandidates; + + for (int i = 0; i < m_keywords.count(); ++i) { + int searchFrom = -1; + forever { + int index = line.lastIndexOf(m_keywords.at(i).name + ":", searchFrom); + + if (index == -1) + break; // 'forever' loop exit condition + + searchFrom = index - line.length() - 1; + + if (!isFirstCharOfTheWord(index, line)) + continue; + + entryCandidates.insert(index, i); + } + } + + return entryCandidates; +} + +bool LineParser::isFirstCharOfTheWord(int index, const QString &line) +{ + return (index == 0) || !line.at(index - 1).isLetterOrNumber(); +} + +QList LineParser::keywordEntriesFromCandidates( + const QMap &candidates, const QString &line) +{ + // Ensure something is found + if (candidates.isEmpty()) + return QList(); + + // Convert candidates to entries + QList entries; + QMapIterator i(candidates); + i.toBack(); + + while (i.hasPrevious()) { + i.previous(); + + KeywordEntry entry; + + entry.keywordStart = i.key(); + entry.keywordIndex = i.value(); + + int keywordLength = m_keywords.at(entry.keywordIndex).name.length() + 1; // include colon + + int entryTextLength = -1; + if (!entries.empty()) + entryTextLength = entries.last().keywordStart - (entry.keywordStart + keywordLength); + + entry.text = line.mid(entry.keywordStart + keywordLength, entryTextLength).trimmed(); + + if (entry.text.isEmpty() && !entries.empty()) + // Take the text form the previous entry, consider: + // ': : ' + entry.text = entries.last().text; + + entries << entry; + } + + return entries; +} + +QList LineParser::todoItemsFromKeywordEntries(const QList &entries) +{ + QList todoItems; + + foreach (const KeywordEntry &entry, entries) { + TodoItem item; + item.text = QString("%1: %2") + .arg(m_keywords.at(entry.keywordIndex).name) + .arg(entry.text); + item.color = m_keywords.at(entry.keywordIndex).color; + item.iconResource = m_keywords.at(entry.keywordIndex).iconResource; + todoItems << item; + } + + return todoItems; +} + +} // namespace Internal +} // namespace Todo diff --git a/src/plugins/todo/lineparser.h b/src/plugins/todo/lineparser.h new file mode 100644 index 00000000000..fd29c6a0f61 --- /dev/null +++ b/src/plugins/todo/lineparser.h @@ -0,0 +1,75 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef LINEPARSER_H +#define LINEPARSER_H + +#include "keyword.h" +#include "todoitem.h" + +namespace Todo { +namespace Internal { + +class LineParser +{ +public: + LineParser(); + explicit LineParser(const KeywordList &keywordList); + + void setKeywordList(const KeywordList &keywordList); + QList parse(const QString &line); + +private: + + // map key here is keyword start position in the text line + // and map value is keyword index in m_keywords + typedef QMap KeywordEntryCandidates; + + struct KeywordEntry { + int keywordIndex; + int keywordStart; + QString text; + }; + + KeywordEntryCandidates findKeywordEntryCandidates(const QString &line); + bool isFirstCharOfTheWord(int index, const QString &line); + QList keywordEntriesFromCandidates(const QMap &candidates, const QString &line); + QList todoItemsFromKeywordEntries(const QList &entries); + + KeywordList m_keywords; +}; + +} // namespace Internal +} // namespace Todo + +#endif // LINEPARSER_H diff --git a/src/plugins/todo/optionsdialog.cpp b/src/plugins/todo/optionsdialog.cpp new file mode 100644 index 00000000000..e81ec86f1ea --- /dev/null +++ b/src/plugins/todo/optionsdialog.cpp @@ -0,0 +1,160 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "optionsdialog.h" +#include "ui_optionsdialog.h" +#include "keyworddialog.h" +#include "constants.h" + +namespace Todo { +namespace Internal { + +OptionsDialog::OptionsDialog(QWidget *parent) : + QWidget(parent), + ui(new Ui::OptionsDialog) +{ + ui->setupUi(this); + setButtonsEnabled(); + connect(ui->addButton, SIGNAL(clicked()), SLOT(addButtonClicked())); + connect(ui->removeButton, SIGNAL(clicked()), SLOT(removeButtonClicked())); + connect(ui->editButton, SIGNAL(clicked()), SLOT(editButtonClicked())); + connect(ui->resetButton, SIGNAL(clicked()), SLOT(resetButtonClicked())); +} + +OptionsDialog::~OptionsDialog() +{ + delete ui; +} + +void OptionsDialog::setSettings(const Settings &settings) +{ + uiFromSettings(settings); +} + +void OptionsDialog::addToKeywordsList(const Keyword &keyword) +{ + QListWidgetItem *item = new QListWidgetItem(QIcon(keyword.iconResource), keyword.name); + item->setData(Qt::UserRole, keyword.iconResource); + item->setBackgroundColor(keyword.color); + ui->keywordsList->addItem(item); +} + +Settings OptionsDialog::settings() +{ + return settingsFromUi(); +} + +void OptionsDialog::addButtonClicked() +{ + Keyword keyword; + KeywordDialog *addKeywordDialog = new KeywordDialog(keyword, this); + if (addKeywordDialog->exec() == QDialog::Accepted) { + keyword = addKeywordDialog->keyword(); + addToKeywordsList(keyword); + } +} + +void OptionsDialog::editButtonClicked() +{ + QListWidgetItem *item = ui->keywordsList->currentItem(); + + Keyword keyword; + keyword.name = item->text(); + keyword.iconResource = item->data(Qt::UserRole).toString(); + keyword.color = item->backgroundColor(); + + KeywordDialog *addKeywordDialog = new KeywordDialog(keyword, this); + if (addKeywordDialog->exec() == QDialog::Accepted) { + keyword = addKeywordDialog->keyword(); + item->setIcon(QIcon(keyword.iconResource)); + item->setText(keyword.name); + item->setData(Qt::UserRole, keyword.iconResource); + item->setBackgroundColor(keyword.color); + } +} + +void OptionsDialog::removeButtonClicked() +{ + ui->keywordsList->takeItem(ui->keywordsList->currentRow()); +} + +void OptionsDialog::resetButtonClicked() +{ + Settings newSettings; + newSettings.setDefault(); + uiFromSettings(newSettings); +} + +void OptionsDialog::setButtonsEnabled() +{ + bool isSomethingSelected = ui->keywordsList->selectedItems().count() != 0; + ui->removeButton->setEnabled(isSomethingSelected); + ui->editButton->setEnabled(isSomethingSelected); +} + + void OptionsDialog::uiFromSettings(const Settings &settings) + { + ui->scanInCurrentFileRadioButton->setChecked(settings.scanningScope == ScanningScopeCurrentFile); + ui->scanInProjectRadioButton->setChecked(settings.scanningScope == ScanningScopeProject); + + ui->keywordsList->clear(); + foreach (const Keyword &keyword, settings.keywords) + addToKeywordsList(keyword); + } + + Settings OptionsDialog::settingsFromUi() + { + Settings settings; + + if (ui->scanInCurrentFileRadioButton->isChecked()) + settings.scanningScope = ScanningScopeCurrentFile; + else + settings.scanningScope = ScanningScopeProject; + + settings.keywords.clear(); + for (int i = 0; i < ui->keywordsList->count(); ++i) { + QListWidgetItem *item = ui->keywordsList->item(i); + + Keyword keyword; + keyword.name = item->text(); + keyword.iconResource = item->data(Qt::UserRole).toString(); + keyword.color = item->backgroundColor(); + + settings.keywords << keyword; + } + + return settings; + } + +} // namespace Internal +} // namespace Todo diff --git a/src/plugins/todo/optionsdialog.h b/src/plugins/todo/optionsdialog.h new file mode 100644 index 00000000000..a353bcd5e05 --- /dev/null +++ b/src/plugins/todo/optionsdialog.h @@ -0,0 +1,77 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef OPTIONSDIALOG_H +#define OPTIONSDIALOG_H + +#include "keyword.h" +#include "settings.h" + +#include + +namespace Todo { +namespace Internal { + +namespace Ui { + class OptionsDialog; +} + +class OptionsDialog : public QWidget +{ + Q_OBJECT +public: + explicit OptionsDialog(QWidget *parent = 0); + ~OptionsDialog(); + + void setSettings(const Settings &settings); + Settings settings(); + +private slots: + void addButtonClicked(); + void editButtonClicked(); + void removeButtonClicked(); + void resetButtonClicked(); + void setButtonsEnabled(); + +private: + void uiFromSettings(const Settings &settings); + Settings settingsFromUi(); + void addToKeywordsList(const Keyword &keyword); + + Ui::OptionsDialog *ui; +}; + +} // namespace Internal +} // namespace Todo + +#endif // OPTIONSDIALOG_H diff --git a/src/plugins/todo/optionsdialog.ui b/src/plugins/todo/optionsdialog.ui new file mode 100644 index 00000000000..d8b4f6d963d --- /dev/null +++ b/src/plugins/todo/optionsdialog.ui @@ -0,0 +1,131 @@ + + + Todo::Internal::OptionsDialog + + + + 0 + 0 + 377 + 299 + + + + Form + + + + + + Keywords + + + + + + true + + + + + + + + + Add + + + + + + + Edit + + + + + + + Remove + + + + + + + Reset + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Scanning scope + + + + + + true + + + Scan in the whole project + + + + + + + Scan in the current opened file + + + true + + + + + + + + + + + + keywordsList + itemSelectionChanged() + Todo::Internal::OptionsDialog + setButtonsEnabled() + + + 247 + 176 + + + 5 + 137 + + + + + + setButtonsEnabled() + + diff --git a/src/plugins/todo/optionspage.cpp b/src/plugins/todo/optionspage.cpp new file mode 100644 index 00000000000..d8fe1ac9345 --- /dev/null +++ b/src/plugins/todo/optionspage.cpp @@ -0,0 +1,127 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "optionspage.h" +#include "constants.h" + +#include + +#include +#include + +Todo::Internal::OptionsDialog *some = 0; + +namespace Todo { +namespace Internal { + +OptionsPage::OptionsPage(const Settings &settings, QObject *parent) : + IOptionsPage(parent), + m_dialog(0) +{ + setSettings(settings); +} + +OptionsPage::~OptionsPage() +{ +} + +void OptionsPage::setSettings(const Settings &settings) +{ + m_settings = settings; +} + +QString OptionsPage::id() const +{ + return "TodoSettings"; +} + +QString OptionsPage::trName() const +{ + return tr("To-Do"); +} + +QString OptionsPage::category() const +{ + return "To-Do"; +} + +QString OptionsPage::trCategory() const +{ + return tr("To-Do"); +} + +QString OptionsPage::displayName() const +{ + return trName(); +} + +QString OptionsPage::displayCategory() const +{ + return trCategory(); +} + +QIcon OptionsPage::categoryIcon() const +{ + return QIcon(Constants::ICON_TODO); +} + + +QWidget *OptionsPage::createPage(QWidget *parent) +{ + m_dialog = new OptionsDialog(parent); + m_dialog->setSettings(m_settings); + return m_dialog; +} + +void OptionsPage::apply() +{ + Settings newSettings = m_dialog->settings(); + + if (newSettings != m_settings) { + m_settings = newSettings; + emit settingsChanged(m_settings); + } +} + +void OptionsPage::finish() +{ +} + +bool OptionsPage::matches(const QString &searchKeyWord) const +{ + return searchKeyWord == QString("todo"); +} + +} // namespace Internal +} // namespace Todo + diff --git a/src/plugins/todo/optionspage.h b/src/plugins/todo/optionspage.h new file mode 100644 index 00000000000..094fae75b8e --- /dev/null +++ b/src/plugins/todo/optionspage.h @@ -0,0 +1,77 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef SETTINGSPAGE_H +#define SETTINGSPAGE_H + +#include "optionsdialog.h" +#include "settings.h" + +#include + +namespace Todo { +namespace Internal { + +class OptionsPage : public Core::IOptionsPage +{ + Q_OBJECT +public: + OptionsPage(const Settings &settings, QObject *parent = 0); + ~OptionsPage(); + + void setSettings(const Settings &settings); + + QString id() const; + QString trName() const; + QString category() const; + QString trCategory() const; + QString displayName() const; + QIcon categoryIcon() const; + QString displayCategory() const; + QWidget *createPage(QWidget *parent); + void apply(); + void finish(); + bool matches(const QString &searchKeyWord) const; + +signals: + void settingsChanged(const Settings &settings); + +private: + OptionsDialog *m_dialog; + Settings m_settings; +}; + +} // namespace Internal +} // namespace Todo + +#endif // SETTINGSPAGE_H diff --git a/src/plugins/todo/qmljstodoitemsscanner.cpp b/src/plugins/todo/qmljstodoitemsscanner.cpp new file mode 100644 index 00000000000..c07ceee2fc6 --- /dev/null +++ b/src/plugins/todo/qmljstodoitemsscanner.cpp @@ -0,0 +1,102 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "qmljstodoitemsscanner.h" + +#include + +namespace Todo { +namespace Internal { + +QmlJsTodoItemsScanner::QmlJsTodoItemsScanner(const KeywordList &keywordList, QObject *parent) : + TodoItemsScanner(keywordList, parent) +{ + QmlJS::ModelManagerInterface *model = QmlJS::ModelManagerInterface::instance(); + connect(model, SIGNAL(documentUpdated(QmlJS::Document::Ptr)), + this, SLOT(documentUpdated(QmlJS::Document::Ptr)), Qt::DirectConnection); +} + +bool QmlJsTodoItemsScanner::shouldProcessFile(const QString &fileName) +{ + QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance(); + foreach (const QmlJS::ModelManagerInterface::ProjectInfo &info, modelManager->projectInfos()) + if (info.project->files(ProjectExplorer::Project::ExcludeGeneratedFiles).contains(fileName)) + return true; + + return false; +} + +void QmlJsTodoItemsScanner::keywordListChanged() +{ + // We need to rescan everything known to the code model + // TODO: It would be nice to only tokenize the source files, not update the code model entirely. + + QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance(); + + QStringList filesToBeUpdated; + foreach (const QmlJS::ModelManagerInterface::ProjectInfo &info, modelManager->projectInfos()) + filesToBeUpdated << info.project->files(ProjectExplorer::Project::ExcludeGeneratedFiles); + + modelManager->updateSourceFiles(filesToBeUpdated, false); +} + +void QmlJsTodoItemsScanner::documentUpdated(QmlJS::Document::Ptr doc) +{ + if (shouldProcessFile(doc->fileName())) + processDocument(doc); +} + +void QmlJsTodoItemsScanner::processDocument(QmlJS::Document::Ptr doc) +{ + QList itemList; + + foreach (const QmlJS::AST::SourceLocation &sourceLocation, doc->engine()->comments()) { + + QString source = doc->source().mid(sourceLocation.begin(), sourceLocation.length).trimmed(); + + // Process every line + // TODO: Do not create QStringList, just iterate through a string tracking line endings. + QStringList commentLines = source.split("\n", QString::SkipEmptyParts); + quint32 startLine = sourceLocation.startLine; + for (int j = 0; j < commentLines.count(); ++j) { + const QString &commentLine = commentLines.at(j); + processCommentLine(doc->fileName(), commentLine, startLine + j, itemList); + } + + } + + emit itemsFetched(doc->fileName(), itemList); +} + +} +} diff --git a/src/plugins/todo/qmljstodoitemsscanner.h b/src/plugins/todo/qmljstodoitemsscanner.h new file mode 100644 index 00000000000..beb8e28ff16 --- /dev/null +++ b/src/plugins/todo/qmljstodoitemsscanner.h @@ -0,0 +1,64 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef QMLJSTODOITEMSSCANNER_H +#define QMLJSTODOITEMSSCANNER_H + +#include "todoitemsscanner.h" + +#include + +namespace Todo { +namespace Internal { + +class QmlJsTodoItemsScanner : public TodoItemsScanner +{ + Q_OBJECT + +public: + explicit QmlJsTodoItemsScanner(const KeywordList &keywordList, QObject *parent = 0); + +protected: + bool shouldProcessFile(const QString &fileName); + void keywordListChanged(); + +private slots: + void documentUpdated(QmlJS::Document::Ptr doc); + +private: + void processDocument(QmlJS::Document::Ptr doc); +}; + +} +} +#endif // QMLJSTODOITEMSSCANNER_H diff --git a/src/plugins/todo/settings.cpp b/src/plugins/todo/settings.cpp new file mode 100644 index 00000000000..4481680b1bd --- /dev/null +++ b/src/plugins/todo/settings.cpp @@ -0,0 +1,138 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "settings.h" +#include "constants.h" + +namespace Todo { +namespace Internal { + +void Settings::save(QSettings *settings) const +{ + settings->beginGroup(Constants::SETTINGS_GROUP); + settings->setValue(Constants::SCANNING_SCOPE, scanningScope); + + settings->beginWriteArray(Constants::KEYWORDS_LIST); + for (int i = 0; i < keywords.size(); ++i) { + settings->setArrayIndex(i); + settings->setValue("name", keywords.at(i).name); + settings->setValue("color", keywords.at(i).color); + settings->setValue("iconResource", keywords.at(i).iconResource); + } + settings->endArray(); + + settings->endGroup(); + settings->sync(); +} + +void Settings::load(QSettings *settings) +{ + setDefault(); + + settings->beginGroup(Constants::SETTINGS_GROUP); + + scanningScope = static_cast(settings->value(Constants::SCANNING_SCOPE, + scanningScope).toInt()); + + KeywordList newKeywords; + int size = settings->beginReadArray(Constants::KEYWORDS_LIST); + if (size > 0) { + for (int i = 0; i < size; ++i) { + settings->setArrayIndex(i); + Keyword keyword; + keyword.name = settings->value("name").toString(); + keyword.color = settings->value("color").value(); + keyword.iconResource = settings->value("iconResource").toString(); + newKeywords << keyword; + } + keywords = newKeywords; + } + settings->endArray(); + + settings->endGroup(); +} + +void Settings::setDefault() +{ + scanningScope = ScanningScopeCurrentFile; + + keywords.clear(); + + Keyword keyword; + + keyword.name = QLatin1String("TODO"); + keyword.iconResource = QLatin1String(Constants::ICON_WARNING); + keyword.color = QColor(QLatin1String(Constants::COLOR_TODO_BG)); + keywords.append(keyword); + + keyword.name = QLatin1String("NOTE"); + keyword.iconResource = QLatin1String(Constants::ICON_INFO); + keyword.color = QColor(QLatin1String(Constants::COLOR_NOTE_BG)); + keywords.append(keyword); + + keyword.name = QLatin1String("FIXME"); + keyword.iconResource = QLatin1String(Constants::ICON_ERROR); + keyword.color = QColor(QLatin1String(Constants::COLOR_FIXME_BG)); + keywords.append(keyword); + + keyword.name = QLatin1String("BUG"); + keyword.iconResource = QLatin1String(Constants::ICON_ERROR); + keyword.color = QColor(QLatin1String(Constants::COLOR_BUG_BG)); + keywords.append(keyword); + + keyword.name = QLatin1String("WARNING"); + keyword.iconResource = QLatin1String(Constants::ICON_WARNING); + keyword.color = QColor(QLatin1String(Constants::COLOR_WARNING_BG)); + keywords.append(keyword); +} + +bool Settings::equals(const Settings &other) const +{ + return (keywords == other.keywords) + && (scanningScope == other.scanningScope); + +} + +bool operator ==(Settings &s1, Settings &s2) +{ + return s1.equals(s2); +} + +bool operator !=(Settings &s1, Settings &s2) +{ + return !s1.equals(s2); +} + +} // namespace Internal +} // namespace Todo + diff --git a/src/plugins/todo/settings.h b/src/plugins/todo/settings.h new file mode 100644 index 00000000000..74b12eaabe2 --- /dev/null +++ b/src/plugins/todo/settings.h @@ -0,0 +1,66 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef SETTINGS_H +#define SETTINGS_H + +#include "keyword.h" + +#include + +namespace Todo { +namespace Internal { + +enum ScanningScope { + ScanningScopeCurrentFile, + ScanningScopeProject +}; + +struct Settings { + KeywordList keywords; + ScanningScope scanningScope; + void save(QSettings *settings) const; + void load(QSettings *settings); + void setDefault(); + bool equals(const Settings &other) const; +}; + +bool operator ==(Settings &s1, Settings &s2); +bool operator !=(Settings &s1, Settings &s2); + +} // namespace Internal +} // namespace Todo + +Q_DECLARE_METATYPE(Todo::Internal::ScanningScope) + +#endif // SETTINGS_H diff --git a/src/plugins/todo/settingsdialog.cpp b/src/plugins/todo/settingsdialog.cpp deleted file mode 100644 index 0efd8dc86aa..00000000000 --- a/src/plugins/todo/settingsdialog.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include "settingsdialog.h" -#include "ui_settingsdialog.h" -#include "addkeyworddialog.h" - -SettingsDialog::SettingsDialog(QWidget *parent) : - QWidget(parent), - ui(new Ui::SettingsDialog) -{ - ui->setupUi(this); - connect(this->ui->addButton, SIGNAL(clicked()), this, SLOT(addButtonClicked())); - connect(this->ui->removeButton, SIGNAL(clicked()), this, SLOT(removeButtonClicked())); - connect(this->ui->resetButton, SIGNAL(clicked()), this, SLOT(resetButtonClicked())); - - connect(this->ui->buildIssuesRadioButton, SIGNAL(toggled(bool)), this, SIGNAL(settingsChanged())); - connect(this->ui->todoOutputRadioButton, SIGNAL(toggled(bool)), this, SIGNAL(settingsChanged())); - connect(this->ui->projectRadioButton, SIGNAL(toggled(bool)), this, SIGNAL(settingsChanged())); - connect(this->ui->currentFileRadioButton, SIGNAL(toggled(bool)), this, SIGNAL(settingsChanged())); - -} - -SettingsDialog::~SettingsDialog() -{ - delete ui; -} - -void SettingsDialog::setProjectRadioButtonEnabled(bool what) -{ - this->ui->projectRadioButton->setChecked(what); -} - -void SettingsDialog::setCurrentFileRadioButtonEnabled(bool what) -{ - this->ui->currentFileRadioButton->setChecked(what); -} - -void SettingsDialog::setBuildIssuesRadioButtonEnabled(bool what) -{ - this->ui->buildIssuesRadioButton->setChecked(what); -} - -void SettingsDialog::setTodoOutputRadioButtonEnabled(bool what) -{ - this->ui->todoOutputRadioButton->setChecked(what); -} - - -void SettingsDialog::addToKeywordsList(Keyword keyword) -{ - QListWidgetItem *item = new QListWidgetItem(keyword.icon, keyword.name); - item->setBackgroundColor(keyword.warningColor); - this->ui->keywordsList->addItem(item); -} - -void SettingsDialog::setKeywordsList(KeywordsList list) -{ - if (!list.count()) - { - resetButtonClicked(); - } - else - { - for (int i = 0; i < list.count(); ++i) - { - addToKeywordsList(list.at(i)); - } - } -} - -bool SettingsDialog::projectRadioButtonEnabled() -{ - return this->ui->projectRadioButton->isChecked(); -} - -bool SettingsDialog::currentFileRadioButtonEnabled() -{ - return this->ui->currentFileRadioButton->isChecked(); -} - -bool SettingsDialog::buildIssuesRadioButtonEnabled() -{ - return this->ui->buildIssuesRadioButton->isChecked(); -} - -bool SettingsDialog::todoOutputRadioButtonEnabled() -{ - return this->ui->todoOutputRadioButton->isChecked(); -} - -KeywordsList SettingsDialog::keywordsList() -{ - KeywordsList list; - for (int i = 0; i < this->ui->keywordsList->count(); ++i) - { - Keyword keyword; - keyword.name = this->ui->keywordsList->item(i)->text(); - keyword.icon = this->ui->keywordsList->item(i)->icon(); - keyword.warningColor = this->ui->keywordsList->item(i)->backgroundColor(); - list.append(keyword); - } - return list; -} - -void SettingsDialog::clearKeywordsList() -{ - this->ui->keywordsList->clear(); -} - -void SettingsDialog::addButtonClicked() -{ - Keyword keyword; - AddKeywordDialog *addKeywordDialog = new AddKeywordDialog(this); - if (addKeywordDialog->exec() == QDialog::Accepted) - { - keyword.name = addKeywordDialog->keywordName(); - keyword.icon = addKeywordDialog->keywordIcon(); - keyword.warningColor = addKeywordDialog->keywordColor(); - addToKeywordsList(keyword); - emit settingsChanged(); - } -} - -void SettingsDialog::removeButtonClicked() -{ - this->ui->keywordsList->takeItem(this->ui->keywordsList->currentRow()); - emit settingsChanged(); -} - -void SettingsDialog::resetButtonClicked() -{ - clearKeywordsList(); - addToKeywordsList(Keyword("TODO", QIcon(":/warning"), QColor("#BFFFC8"))); - addToKeywordsList(Keyword("NOTE", QIcon(":/info"), QColor("#E2DFFF"))); - addToKeywordsList(Keyword("FIXME", QIcon(":/error"), QColor("#FFBFBF"))); - addToKeywordsList(Keyword("BUG", QIcon(":/error"), QColor("#FFDFDF"))); - addToKeywordsList(Keyword("HACK", QIcon(":/info"), QColor("#FFFFAA"))); - - emit settingsChanged(); -} diff --git a/src/plugins/todo/settingsdialog.h b/src/plugins/todo/settingsdialog.h deleted file mode 100644 index 316137d3477..00000000000 --- a/src/plugins/todo/settingsdialog.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef SETTINGSDIALOG_H -#define SETTINGSDIALOG_H - -#include -#include "keyword.h" - -namespace Ui { - class SettingsDialog; -} - -class SettingsDialog : public QWidget -{ - Q_OBJECT - -public: - explicit SettingsDialog(QWidget *parent = 0); - ~SettingsDialog(); - void setProjectRadioButtonEnabled(bool what); - void setCurrentFileRadioButtonEnabled(bool what); - void setBuildIssuesRadioButtonEnabled(bool what); - void setTodoOutputRadioButtonEnabled(bool what); - - void addToKeywordsList(Keyword); - void setKeywordsList(KeywordsList); - - bool projectRadioButtonEnabled(); - bool currentFileRadioButtonEnabled(); - bool buildIssuesRadioButtonEnabled(); - bool todoOutputRadioButtonEnabled(); - KeywordsList keywordsList(); - -signals: - void settingsChanged(); - -private slots: - void clearKeywordsList(); - void addButtonClicked(); - void removeButtonClicked(); - void resetButtonClicked(); - -private: - Ui::SettingsDialog *ui; -}; - -#endif // SETTINGSDIALOG_H diff --git a/src/plugins/todo/settingsdialog.ui b/src/plugins/todo/settingsdialog.ui deleted file mode 100644 index 521a24c1ccb..00000000000 --- a/src/plugins/todo/settingsdialog.ui +++ /dev/null @@ -1,143 +0,0 @@ - - - SettingsDialog - - - - 0 - 0 - 740 - 423 - - - - Form - - - - - - - - - - - - - - - - Add - - - - - - - Remove - - - - - - - Reset - - - - - - - View options - - - - - - - - From current opened file - - - true - - - - - - - true - - - From projects - - - - - - - - - - - - Pane options - - - - - - - - Show in "TODO Output" - - - true - - - - - - - true - - - Show in "Build Issues" - - - - - - - - - - - - Icons and Colors show on -TODO Output pane only - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - diff --git a/src/plugins/todo/settingspage.cpp b/src/plugins/todo/settingspage.cpp deleted file mode 100644 index ef55cd1b1e9..00000000000 --- a/src/plugins/todo/settingspage.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "settingspage.h" -#include -#include -#include - -SettingsPage::SettingsPage(KeywordsList keywords, int projectOptions, int paneOptions, QObject *parent) : IOptionsPage(parent) -{ - this->keywords = keywords; - this->projectOptions = projectOptions; - this->paneOptions = paneOptions; -} - -SettingsPage::~SettingsPage() -{ - delete dialog; -} - -QString SettingsPage::id() const -{ - return "TodoSettings"; -} - -QString SettingsPage::trName() const -{ - return tr("TODO Plugin"); -} - -QString SettingsPage::category() const -{ - return "TODO"; -} - -QString SettingsPage::trCategory() const -{ - return tr("TODO"); -} - -QString SettingsPage::displayName() const -{ - return trName(); -} - -QString SettingsPage::displayCategory() const -{ - return trCategory(); -} - -QIcon SettingsPage::categoryIcon() const -{ - return QIcon(":/todo"); -} - - -QWidget *SettingsPage::createPage(QWidget *parent) -{ - settingsStatus = false; - - dialog = new SettingsDialog(parent); - dialog->setKeywordsList(keywords); - switch (projectOptions) - { - case 0: - dialog->setProjectRadioButtonEnabled(false); - dialog->setCurrentFileRadioButtonEnabled(true); - break; - case 1: - default: - dialog->setProjectRadioButtonEnabled(true); - dialog->setCurrentFileRadioButtonEnabled(false); - break; - } - - switch (paneOptions) - { - case 0: - dialog->setBuildIssuesRadioButtonEnabled(false); - dialog->setTodoOutputRadioButtonEnabled(true); - break; - case 1: - default: - dialog->setBuildIssuesRadioButtonEnabled(true); - dialog->setTodoOutputRadioButtonEnabled(false); - break; - } - connect(dialog, SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); - return dialog; -} - -void SettingsPage::apply() -{ - if (settingsStatus) - { - QSettings *settings = Core::ICore::instance()->settings(); - settings->beginGroup("TODOPlugin"); - projectOptions = dialog->currentFileRadioButtonEnabled() ? 0 : 1; - paneOptions = dialog->todoOutputRadioButtonEnabled() ? 0 : 1; - keywords = dialog->keywordsList(); - settings->setValue("project_options", projectOptions); - settings->setValue("pane_options", paneOptions); - settings->setValue("keywords", qVariantFromValue(keywords)); - - settings->endGroup(); - settings->sync(); - - QMessageBox::information(dialog, tr("Information"), tr("The TODO plugin settings change will take effect after a restart of Qt Creator.")); - settingsStatus = false; - } -} - -void SettingsPage::finish() -{ - //apply(); -} - -void SettingsPage::settingsChanged() -{ - settingsStatus = true; -} diff --git a/src/plugins/todo/settingspage.h b/src/plugins/todo/settingspage.h deleted file mode 100644 index 4f43f8afa88..00000000000 --- a/src/plugins/todo/settingspage.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef SETTINGSPAGE_H -#define SETTINGSPAGE_H - -#include -#include -#include "settingsdialog.h" - - -class SettingsPage : public Core::IOptionsPage -{ - Q_OBJECT -public: - - SettingsPage(KeywordsList keywords = KeywordsList(), int projectOptions = 0, int paneOptions = 0, QObject *parent = 0); - ~SettingsPage(); - - QString id() const; - QString trName() const; - QString category() const; - QString trCategory() const; - QString displayName() const; - QIcon categoryIcon() const; - QString displayCategory() const; - QWidget *createPage(QWidget *parent); - void apply(); - void finish(); - -public slots: - void settingsChanged(); - -private: - SettingsDialog *dialog; - bool settingsStatus; - int projectOptions; - int paneOptions; - KeywordsList keywords; -}; - -#endif // SETTINGSPAGE_H diff --git a/src/plugins/todo/todo.pro b/src/plugins/todo/todo.pro new file mode 100644 index 00000000000..97e6f95b648 --- /dev/null +++ b/src/plugins/todo/todo.pro @@ -0,0 +1,43 @@ +TEMPLATE = lib +TARGET = Todo + +include(../../qtcreatorplugin.pri) +include(todo_dependencies.pri) + +HEADERS += todoplugin.h \ + keyword.h \ + constants.h \ + todooutputpane.h \ + todoitem.h \ + settings.h \ + optionspage.h \ + optionsdialog.h\ + keyworddialog.h \ + todoitemsprovider.h \ + todoitemsmodel.h \ + todoitemsscanner.h \ + cpptodoitemsscanner.h \ + qmljstodoitemsscanner.h \ + lineparser.h +SOURCES += todoplugin.cpp \ + keyword.cpp \ + todooutputpane.cpp \ + optionspage.cpp \ + settings.cpp \ + optionsdialog.cpp \ + keyworddialog.cpp \ + todoitemsprovider.cpp \ + todoitemsmodel.cpp \ + todoitemsscanner.cpp \ + cpptodoitemsscanner.cpp \ + qmljstodoitemsscanner.cpp \ + lineparser.cpp +OTHER_FILES += \ + Todo.pluginspec.in + +RESOURCES += \ + todoplugin.qrc + +FORMS += \ + optionsdialog.ui \ + keyworddialog.ui diff --git a/src/plugins/todo/todo_dependencies.pri b/src/plugins/todo/todo_dependencies.pri new file mode 100644 index 00000000000..ceda7201eca --- /dev/null +++ b/src/plugins/todo/todo_dependencies.pri @@ -0,0 +1,5 @@ +include(../../plugins/coreplugin/coreplugin.pri) +include(../../plugins/projectexplorer/projectexplorer.pri) +include(../../plugins/texteditor/texteditor.pri) +include(../../plugins/cpptools/cpptools.pri) +include(../../libs/qmljs/qmljs.pri) diff --git a/src/plugins/todo/todoitem.h b/src/plugins/todo/todoitem.h new file mode 100644 index 00000000000..7065e4d8678 --- /dev/null +++ b/src/plugins/todo/todoitem.h @@ -0,0 +1,99 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef TODOITEM_H +#define TODOITEM_H + +#include "constants.h" + +#include +#include +#include + +namespace Todo { +namespace Internal { + +struct TodoItem +{ + QString text; + QString file; + int line; + QString iconResource; + QColor color; +}; + +class TodoItemSortPredicate +{ +public: + explicit TodoItemSortPredicate(Constants::OutputColumnIndex columnIndex, Qt::SortOrder order) : + m_columnIndex(columnIndex), + m_order(order) + {} + + inline bool operator()(const TodoItem &t1, const TodoItem &t2) + { + if (m_order == Qt::AscendingOrder) + return lessThan(t1, t2); + else + return lessThan(t2, t1); + } + + inline bool lessThan(const TodoItem &t1, const TodoItem &t2) + { + switch (m_columnIndex) { + case Constants::OUTPUT_COLUMN_TEXT: + return t1.text < t2.text; + + case Constants::OUTPUT_COLUMN_LINE: + return t1.line < t2.line; + + case Constants::OUTPUT_COLUMN_FILE: + return t1.file < t2.file; + + default: + Q_ASSERT(false); + return false; + } + } + +private: + Constants::OutputColumnIndex m_columnIndex; + Qt::SortOrder m_order; +}; + +} // namespace Internal +} // namespace Todo + +Q_DECLARE_METATYPE(Todo::Internal::TodoItem) + +#endif // TODOITEM_H diff --git a/src/plugins/todo/todoitemsmodel.cpp b/src/plugins/todo/todoitemsmodel.cpp new file mode 100644 index 00000000000..5227513488f --- /dev/null +++ b/src/plugins/todo/todoitemsmodel.cpp @@ -0,0 +1,152 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "todoitemsmodel.h" +#include "constants.h" + +namespace Todo { +namespace Internal { + +TodoItemsModel::TodoItemsModel(QObject *parent) : + QAbstractTableModel(parent), + m_todoItemsList(0), + m_currentSortColumn(Constants::OutputColumnIndex(0)), + m_currentSortOrder(Qt::AscendingOrder) +{ +} + +void TodoItemsModel::setTodoItemsList(QList *list) +{ + m_todoItemsList = list; + todoItemsListUpdated(); +} + +int TodoItemsModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + + // There's only one level of hierarchy + if (parent.isValid()) + return 0; + + if (!m_todoItemsList) + return 0; + + return m_todoItemsList->count(); +} + +int TodoItemsModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + + return Constants::OUTPUT_COLUMN_LAST; +} + +QVariant TodoItemsModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + TodoItem item = m_todoItemsList->at(index.row()); + + if (role == Qt::BackgroundColorRole) + return item.color; + + switch (index.column()) { + + case Constants::OUTPUT_COLUMN_TEXT: + switch (role) { + case Qt::DisplayRole: + return item.text; + case Qt::DecorationRole: + return QVariant::fromValue(QIcon(item.iconResource)); + } + break; + + case Constants::OUTPUT_COLUMN_FILE: + if (role == Qt::DisplayRole) + return item.file; + break; + + case Constants::OUTPUT_COLUMN_LINE: + if (role == Qt::DisplayRole) + return item.line; + break; + } + + return QVariant(); +} + +QVariant TodoItemsModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Vertical) + return QVariant(); + + if (role != Qt::DisplayRole) + return QVariant(); + + switch (section) { + case Constants::OUTPUT_COLUMN_TEXT: + return tr(Constants::OUPTUT_COLUMN_TEXT_TITLE); + + case Constants::OUTPUT_COLUMN_FILE: + return tr(Constants::OUTPUT_COLUMN_FILE_TITLE); + + case Constants::OUTPUT_COLUMN_LINE: + return tr(Constants::OUTPUT_COLUMN_LINE_TITLE); + + default: + return QVariant(); + } +} + +void TodoItemsModel::sort(int column, Qt::SortOrder order) +{ + m_currentSortColumn = Constants::OutputColumnIndex(column); + m_currentSortOrder = order; + + TodoItemSortPredicate predicate(m_currentSortColumn, m_currentSortOrder); + qSort(m_todoItemsList->begin(), m_todoItemsList->end(), predicate); + emit layoutChanged(); +} + +void TodoItemsModel::todoItemsListUpdated() +{ + if (!m_todoItemsList) + return; + + sort(m_currentSortColumn, m_currentSortOrder); +} + +} +} diff --git a/src/plugins/todo/todoitemsmodel.h b/src/plugins/todo/todoitemsmodel.h new file mode 100644 index 00000000000..be25e2eb1be --- /dev/null +++ b/src/plugins/todo/todoitemsmodel.h @@ -0,0 +1,73 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef TODOITEMSMODEL_H +#define TODOITEMSMODEL_H + +#include "todoitem.h" + +#include +#include + +namespace Todo { +namespace Internal { + +class TodoItemsModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + explicit TodoItemsModel(QObject *parent = 0); + + void setTodoItemsList(QList *list); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + + void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); + +public slots: + void todoItemsListUpdated(); + +private: + QList *m_todoItemsList; + Constants::OutputColumnIndex m_currentSortColumn; + Qt::SortOrder m_currentSortOrder; +}; + +} +} + +#endif // TODOITEMSMODEL_H diff --git a/src/plugins/todo/todoitemsprovider.cpp b/src/plugins/todo/todoitemsprovider.cpp new file mode 100644 index 00000000000..54c279936c9 --- /dev/null +++ b/src/plugins/todo/todoitemsprovider.cpp @@ -0,0 +1,188 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "todoitemsprovider.h" +#include "constants.h" +#include "cpptodoitemsscanner.h" +#include "qmljstodoitemsscanner.h" + +#include +#include +#include + +#include + +namespace Todo { +namespace Internal { + +TodoItemsProvider::TodoItemsProvider(Settings settings, QObject *parent) : + QObject(parent), + m_settings(settings) +{ + setupItemsModel(); + setupStartupProjectBinding(); + setupCurrentEditorBinding(); + setupUpdateListTimer(); + createScanners(); +} + +TodoItemsModel *TodoItemsProvider::todoItemsModel() +{ + return m_itemsModel; +} + +void TodoItemsProvider::settingsChanged(const Settings &newSettings) +{ + if (newSettings.keywords != m_settings.keywords) + foreach (TodoItemsScanner *scanner, m_scanners) + scanner->setKeywordList(newSettings.keywords); + + m_settings = newSettings; + + updateList(); +} + +void TodoItemsProvider::updateList() +{ + m_itemsList.clear(); + + // Show only items of the current file if any + if (m_settings.scanningScope == ScanningScopeCurrentFile) { + if (m_currentEditor) + m_itemsList = m_itemsHash.value(m_currentEditor->document()->fileName()); + } + + // Show only items of the startup project if any + else { + if (m_startupProject) + setItemsListWithinStartupProject(); + } + + m_itemsModel->todoItemsListUpdated(); +} + +void TodoItemsProvider::createScanners() +{ + qRegisterMetaType >("QList"); + + if (CPlusPlus::CppModelManagerInterface::instance()) + m_scanners << new CppTodoItemsScanner(m_settings.keywords, this); + + if (QmlJS::ModelManagerInterface::instance()) + m_scanners << new QmlJsTodoItemsScanner(m_settings.keywords, this); + + foreach (TodoItemsScanner *scanner, m_scanners) + connect(scanner, SIGNAL(itemsFetched(QString,QList)), this, + SLOT(itemsFetched(QString,QList)), Qt::QueuedConnection); +} + +void TodoItemsProvider::setItemsListWithinStartupProject() +{ + QHashIterator > it(m_itemsHash); + QStringList fileNames = m_startupProject->files(ProjectExplorer::Project::ExcludeGeneratedFiles); + while (it.hasNext()) { + it.next(); + if (fileNames.contains(it.key())) + m_itemsList << it.value(); + } +} + +void TodoItemsProvider::itemsFetched(const QString &fileName, const QList &items) +{ + // Replace old items with new ones + m_itemsHash.insert(fileName, items); + + m_shouldUpdateList = true; +} + +void TodoItemsProvider::startupProjectChanged(ProjectExplorer::Project *project) +{ + m_startupProject = project; + updateList(); +} + +void TodoItemsProvider::projectsFilesChanged() +{ + updateList(); +} + +void TodoItemsProvider::currentEditorChanged(Core::IEditor *editor) +{ + m_currentEditor = editor; + if (m_settings.scanningScope == ScanningScopeCurrentFile) + updateList(); +} + +void TodoItemsProvider::updateListTimeoutElapsed() +{ + if (m_shouldUpdateList) { + m_shouldUpdateList = false; + updateList(); + } +} + +void TodoItemsProvider::setupStartupProjectBinding() +{ + ProjectExplorer::ProjectExplorerPlugin *projectExplorerPlugin = ProjectExplorer::ProjectExplorerPlugin::instance(); + + m_startupProject = projectExplorerPlugin->startupProject(); + connect(projectExplorerPlugin->session(), SIGNAL(startupProjectChanged(ProjectExplorer::Project*)), + SLOT(startupProjectChanged(ProjectExplorer::Project*))); + connect(projectExplorerPlugin, SIGNAL(fileListChanged()), SLOT(projectsFilesChanged())); +} + +void TodoItemsProvider::setupCurrentEditorBinding() +{ + Core::EditorManager *editorManager = Core::EditorManager::instance(); + + m_currentEditor = editorManager->currentEditor(); + connect(editorManager, SIGNAL(currentEditorChanged(Core::IEditor*)), + SLOT(currentEditorChanged(Core::IEditor*))); +} + +void TodoItemsProvider::setupUpdateListTimer() +{ + m_shouldUpdateList = false; + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), SLOT(updateListTimeoutElapsed())); + timer->start(Constants::OUTPUT_PANE_UPDATE_INTERVAL); +} + +void TodoItemsProvider::setupItemsModel() +{ + m_itemsModel = new TodoItemsModel(this); + m_itemsModel->setTodoItemsList(&m_itemsList); +} + +} +} diff --git a/src/plugins/todo/todoitemsprovider.h b/src/plugins/todo/todoitemsprovider.h new file mode 100644 index 00000000000..149f2828fc8 --- /dev/null +++ b/src/plugins/todo/todoitemsprovider.h @@ -0,0 +1,101 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef TODOITEMSPROVIDER_H +#define TODOITEMSPROVIDER_H + +#include "todoitem.h" +#include "settings.h" +#include "todoitemsmodel.h" +#include "todoitemsscanner.h" + +#include +#include + +#include +#include + +namespace Todo { +namespace Internal { + +class TodoItemsProvider : public QObject +{ + Q_OBJECT + +public: + explicit TodoItemsProvider(Settings settings, QObject *parent = 0); + TodoItemsModel *todoItemsModel(); + +public slots: + void settingsChanged(const Settings &newSettings); + +signals: + void itemsUpdated(); + +private: + Settings m_settings; + TodoItemsModel *m_itemsModel; + + // All to-do items are stored here regardless current scanning scope + QHash > m_itemsHash; + + // This list contains only those to-do items that are within current scanning scope + QList m_itemsList; + + QList m_scanners; + + ProjectExplorer::Project *m_startupProject; + Core::IEditor* m_currentEditor; + + bool m_shouldUpdateList; + + void setupItemsModel(); + void setupStartupProjectBinding(); + void setupCurrentEditorBinding(); + void setupUpdateListTimer(); + void updateList(); + void createScanners(); + void setItemsListWithinStartupProject(); + +private slots: + void itemsFetched(const QString &fileName, const QList &items); + void startupProjectChanged(ProjectExplorer::Project *project); + void projectsFilesChanged(); + void currentEditorChanged(Core::IEditor *editor); + void updateListTimeoutElapsed(); +}; + +} +} + +#endif // TODOITEMSPROVIDER_H diff --git a/src/plugins/todo/todoitemsscanner.cpp b/src/plugins/todo/todoitemsscanner.cpp new file mode 100644 index 00000000000..7bd15a8e26c --- /dev/null +++ b/src/plugins/todo/todoitemsscanner.cpp @@ -0,0 +1,76 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "todoitemsscanner.h" +#include "lineparser.h" + +#include +#include + +namespace Todo { +namespace Internal { + +TodoItemsScanner::TodoItemsScanner(const KeywordList &keywordList, QObject *parent) : + QObject(parent) +{ + setKeywordList(keywordList); +} + +void TodoItemsScanner::setKeywordList(const KeywordList &keywordList) +{ + m_keywordList = keywordList; + keywordListChanged(); +} + +// Descendants can override and make a request for full rescan here if needed +void TodoItemsScanner::keywordListChanged() +{ +} + +// Descendants can use this to process comment lines +void TodoItemsScanner::processCommentLine(const QString &fileName, const QString &comment, + unsigned lineNumber, QList &outItemList) +{ + LineParser parser(m_keywordList); + QList newItemList = parser.parse(comment); + + for (int i = 0; i < newItemList.count(); ++i) { + newItemList[i].line = lineNumber; + newItemList[i].file = fileName; + } + + outItemList << newItemList; +} + +} +} diff --git a/src/plugins/todo/todoitemsscanner.h b/src/plugins/todo/todoitemsscanner.h new file mode 100644 index 00000000000..460632f185f --- /dev/null +++ b/src/plugins/todo/todoitemsscanner.h @@ -0,0 +1,69 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef TODOITEMSSCANNER_H +#define TODOITEMSSCANNER_H + +#include "todoitem.h" +#include "settings.h" + +#include + +namespace Todo { +namespace Internal { + +// TodoItemsScanner is an abstract class + +class TodoItemsScanner : public QObject +{ + Q_OBJECT + +public: + explicit TodoItemsScanner(const KeywordList &keywordList, QObject *parent = 0); + void setKeywordList(const KeywordList &keywordList); + +signals: + void itemsFetched(const QString &fileName, const QList &items); + +protected: + KeywordList m_keywordList; + + virtual void keywordListChanged(); + void processCommentLine(const QString &fileName, const QString &comment, unsigned lineNumber, + QList &outItemList); +}; + +} +} + +#endif // TODOITEMSSCANNER_H diff --git a/src/plugins/todo/todooutputpane.cpp b/src/plugins/todo/todooutputpane.cpp index 57fe83fba50..ae9413d7780 100755 --- a/src/plugins/todo/todooutputpane.cpp +++ b/src/plugins/todo/todooutputpane.cpp @@ -1,174 +1,248 @@ -/* - * - * TODO plugin - Add pane with list all TODO, FIXME, etc. comments. - * - * Copyright (C) 2010 VasiliySorokin - * - * Authors: Vasiliy Sorokin - * - * This file is part of TODO plugin for QtCreator. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of the vsorokin nor the names of its contributors may be used to endorse or - * promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * -*/ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + #include "todooutputpane.h" -#include -#include +#include "constants.h" + #include +#include -// TODO: make fix -// NOTE: make note -// HACK: make hack -// BUG: make bug +namespace Todo { +namespace Internal { -TodoOutputPane::TodoOutputPane(QObject *parent) : IOutputPane(parent) +TodoOutputPane::TodoOutputPane(TodoItemsModel *todoItemsModel, QObject *parent) : + IOutputPane(parent), + m_todoItemsModel(todoItemsModel) { - todoList = new QListWidget(); - todoList->setFlow(QListView::TopToBottom); - todoList->setFrameStyle(QFrame::NoFrame); - lastCurrentRow = 0; + createTreeView(); + createScopeButtons(); + setScanningScope(ScanningScopeCurrentFile); // default + connect(m_todoItemsModel, SIGNAL(layoutChanged()), SIGNAL(navigateStateUpdate())); } TodoOutputPane::~TodoOutputPane() { - delete todoList; + freeTreeView(); + freeScopeButtons(); } -void TodoOutputPane::addItem(const QString &text, const QString &file, const int rowNumber, const QIcon &icon, const QColor &color) +QWidget *TodoOutputPane::outputWidget(QWidget *parent) { - QListWidgetItem *newItem = new QListWidgetItem(); - newItem->setBackgroundColor(color); - newItem->setIcon(icon); - newItem->setData(Qt::UserRole + 1, file); - newItem->setData(Qt::UserRole + 2, rowNumber); - newItem->setToolTip(file + ":" + QString::number(rowNumber)); - - newItem->setText(file.right(file.size() - file.lastIndexOf("/") - 1) + ":" + QString::number(rowNumber) + ": " + text); - - todoList->addItem(newItem); -} - -QListWidget *TodoOutputPane::getTodoList() const -{ - return todoList; -} - - -QWidget *TodoOutputPane::outputWidget(QWidget */*parent*/) -{ - return todoList; + Q_UNUSED(parent) + return m_todoTreeView; } QList TodoOutputPane::toolBarWidgets() const { - return QList(); -} - -QString TodoOutputPane::name() const -{ - return tr("TODO Output"); + return QList() + << m_spacer + << m_currentFileButton + << m_wholeProjectButton; } QString TodoOutputPane::displayName() const { - return name(); + return tr(Constants::OUTPUT_PANE_TITLE); } int TodoOutputPane::priorityInStatusBar() const { - return 1; + return 1; } void TodoOutputPane::clearContents() { - todoList->clear(); } - -void TodoOutputPane::clearContents(QString filename) -{ - int i = 0; - lastCurrentRow = 0; - while (i < todoList->count()) - { - if (!filename.compare(todoList->item(i)->data(Qt::UserRole + 1).toString())) - { - if (lastCurrentRow == 0) - lastCurrentRow = todoList->currentRow(); - todoList->takeItem(i); - } - else - { - ++i; - } - } -} - - void TodoOutputPane::visibilityChanged(bool visible) { - todoList->setVisible(visible); + Q_UNUSED(visible) } void TodoOutputPane::setFocus() { - todoList->setFocus(); + m_todoTreeView->setFocus(); } -bool TodoOutputPane::hasFocus() +bool TodoOutputPane::hasFocus() const { - return todoList->hasFocus(); + return m_todoTreeView->hasFocus(); } -bool TodoOutputPane::canFocus() +bool TodoOutputPane::canFocus() const { return true; } -bool TodoOutputPane::canNavigate() +bool TodoOutputPane::canNavigate() const { - return todoList->count() > 1; + return true; } -bool TodoOutputPane::canNext() +bool TodoOutputPane::canNext() const { - return todoList->currentRow() < todoList->count() && todoList->count() > 1; + return m_todoTreeView->model()->rowCount() > 1; } -bool TodoOutputPane::canPrevious() +bool TodoOutputPane::canPrevious() const { - return todoList->currentRow() > 0 && todoList->count() > 1; + return m_todoTreeView->model()->rowCount() > 1; } void TodoOutputPane::goToNext() { - todoList->setCurrentRow(todoList->currentRow() + 1); + m_todoTreeView->selectionModel()->select(nextModelIndex(), QItemSelectionModel::SelectCurrent); } void TodoOutputPane::goToPrev() { - todoList->setCurrentRow(todoList->currentRow() - 1); + m_todoTreeView->selectionModel()->select(previousModelIndex(), QItemSelectionModel::SelectCurrent); } -void TodoOutputPane::sort() +void TodoOutputPane::setScanningScope(ScanningScope scanningScope) { - todoList->sortItems(Qt::AscendingOrder); - if (todoList->count() > 0) - todoList->setCurrentRow(lastCurrentRow < todoList->count() ? lastCurrentRow : todoList->count() - 1); + if (scanningScope == ScanningScopeCurrentFile) + m_currentFileButton->setChecked(true); + else if (scanningScope == ScanningScopeProject) + m_wholeProjectButton->setChecked(true); + else + Q_ASSERT_X(false, "Updating scanning scope buttons", "Unknown scanning scope enum value"); } + +void TodoOutputPane::scopeButtonClicked(QAbstractButton* button) +{ + if (button == m_currentFileButton) + emit scanningScopeChanged(ScanningScopeCurrentFile); + else if (button == m_wholeProjectButton) + emit scanningScopeChanged(ScanningScopeProject); +} + +void TodoOutputPane::todoTreeViewClicked(QModelIndex index) +{ + // Create a to-do item and notify that it was clicked on + + int row = index.row(); + + TodoItem item; + item.text = index.sibling(row, Constants::OUTPUT_COLUMN_TEXT).data().toString(); + item.file = index.sibling(row, Constants::OUTPUT_COLUMN_FILE).data().toString(); + item.line = index.sibling(row, Constants::OUTPUT_COLUMN_LINE).data().toInt(); + item.color = index.data(Qt::BackgroundColorRole).value(); + item.iconResource = index.sibling(row, Constants::OUTPUT_COLUMN_TEXT).data(Qt::DecorationRole).toString(); + + emit todoItemClicked(item); +} + +void TodoOutputPane::createTreeView() +{ + m_todoTreeView = new QTreeView(); + + m_todoTreeView->setRootIsDecorated(false); + m_todoTreeView->setFrameStyle(QFrame::NoFrame); + m_todoTreeView->setSortingEnabled(true); + m_todoTreeView->setModel(m_todoItemsModel); + + QHeaderView *header = m_todoTreeView->header(); + header->setResizeMode(Constants::OUTPUT_COLUMN_TEXT, QHeaderView::Stretch); + header->setResizeMode(Constants::OUTPUT_COLUMN_LINE, QHeaderView::ResizeToContents); + header->setResizeMode(Constants::OUTPUT_COLUMN_FILE, QHeaderView::ResizeToContents); + header->setStretchLastSection(false); + header->setMovable(false); + + connect(m_todoTreeView, SIGNAL(clicked(QModelIndex)), SLOT(todoTreeViewClicked(QModelIndex))); +} + +void TodoOutputPane::freeTreeView() +{ + delete m_todoTreeView; +} + +void TodoOutputPane::createScopeButtons() +{ + m_currentFileButton = new QToolButton(); + m_currentFileButton->setIcon(QIcon(QString(Constants::ICON_CURRENT_FILE))); + m_currentFileButton->setCheckable(true); + m_currentFileButton->setToolTip(tr("Scan in the current opened file")); + + m_wholeProjectButton = new QToolButton(); + m_wholeProjectButton->setIcon(QIcon(QString(Constants::ICON_WHOLE_PROJECT))); + m_wholeProjectButton->setCheckable(true); + m_wholeProjectButton->setToolTip(tr("Scan in the whole project")); + + m_scopeButtons = new QButtonGroup(); + m_scopeButtons->addButton(m_wholeProjectButton); + m_scopeButtons->addButton(m_currentFileButton); + connect(m_scopeButtons, SIGNAL(buttonClicked(QAbstractButton*)), SLOT(scopeButtonClicked(QAbstractButton*))); + + m_spacer = new QWidget; + m_spacer->setMinimumWidth(Constants::OUTPUT_TOOLBAR_SPACER_WIDHT); +} + +void TodoOutputPane::freeScopeButtons() +{ + delete m_currentFileButton; + delete m_wholeProjectButton; + delete m_scopeButtons; + delete m_spacer; +} + +QModelIndex TodoOutputPane::selectedModelIndex() +{ + QModelIndexList selectedIndexes = m_todoTreeView->selectionModel()->selectedIndexes(); + if (selectedIndexes.isEmpty()) + return QModelIndex(); + else + // There is only one item selected + return selectedIndexes.first(); +} + +QModelIndex TodoOutputPane::nextModelIndex() +{ + QModelIndex indexToBeSelected = m_todoTreeView->indexBelow(selectedModelIndex()); + if (!indexToBeSelected.isValid()) + return m_todoTreeView->model()->index(0, 0); + else + return indexToBeSelected; +} + +QModelIndex TodoOutputPane::previousModelIndex() +{ + QModelIndex indexToBeSelected = m_todoTreeView->indexAbove(selectedModelIndex()); + if (!indexToBeSelected.isValid()) + return m_todoTreeView->model()->index(m_todoTreeView->model()->rowCount() - 1, 0); + else + return indexToBeSelected; +} + +} // namespace Internal +} // namespace Todo diff --git a/src/plugins/todo/todooutputpane.h b/src/plugins/todo/todooutputpane.h index 2192eecc83a..3b2afc8d6fb 100755 --- a/src/plugins/todo/todooutputpane.h +++ b/src/plugins/todo/todooutputpane.h @@ -1,76 +1,106 @@ -/* - * - * TODO plugin - Add pane with list all TODO, FIXME, etc. comments. - * - * Copyright (C) 2010 VasiliySorokin - * - * Authors: Vasiliy Sorokin - * - * This file is part of TODO plugin for QtCreator. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of the vsorokin nor the names of its contributors may be used to endorse or - * promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * -*/ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ #ifndef TODOOUTPUTPANE_H #define TODOOUTPUTPANE_H #include "keyword.h" +#include "todoitem.h" +#include "settings.h" +#include "todoitemsmodel.h" + #include -#include -#include + +#include +#include +#include + +namespace Todo { +namespace Internal { class TodoOutputPane : public Core::IOutputPane { + Q_OBJECT + public: - TodoOutputPane(QObject *parent); + TodoOutputPane(TodoItemsModel *m_todoItemsModel, QObject *parent = 0); ~TodoOutputPane(); QWidget *outputWidget(QWidget *parent); QList toolBarWidgets() const; - QString name() const; QString displayName() const; - int priorityInStatusBar() const; - void clearContents(); - void clearContents(QString filename); void visibilityChanged(bool visible); - void setFocus(); - bool hasFocus(); - bool canFocus(); - - bool canNavigate(); - bool canNext(); - bool canPrevious(); + bool hasFocus() const; + bool canFocus() const; + bool canNavigate() const; + bool canNext() const; + bool canPrevious() const; void goToNext(); void goToPrev(); - void sort(); + void setScanningScope(ScanningScope scanningScope); - void addItem(const QString &text, const QString &file, const int rowNumber, const QIcon &icon, const QColor &color); - QListWidget *getTodoList() const; +signals: + void todoItemClicked(const TodoItem &item); + void scanningScopeChanged(ScanningScope scanningScope); + +private slots: + void scopeButtonClicked(QAbstractButton *button); + void todoTreeViewClicked(QModelIndex index); private: - QListWidget *todoList; - int lastCurrentRow; + QTreeView *m_todoTreeView; + QToolButton *m_currentFileButton; + QToolButton *m_wholeProjectButton; + QWidget *m_spacer; + QButtonGroup *m_scopeButtons; + QList *items; + TodoItemsModel *m_todoItemsModel; + + void createTreeView(); + void freeTreeView(); + void createScopeButtons(); + void freeScopeButtons(); + + QModelIndex selectedModelIndex(); + QModelIndex nextModelIndex(); + QModelIndex previousModelIndex(); }; +} // namespace Internal +} // namespace Todo + #endif // TODOOUTPUTPANE_H diff --git a/src/plugins/todo/todoplugin.cpp b/src/plugins/todo/todoplugin.cpp index 79c8df7fe29..0bd2a3008d7 100755 --- a/src/plugins/todo/todoplugin.cpp +++ b/src/plugins/todo/todoplugin.cpp @@ -1,376 +1,129 @@ -/* - * - * TODO plugin - Add pane with list all TODO, FIXME, etc. comments. - * - * Copyright (C) 2010 VasiliySorokin - * - * Authors: Vasiliy Sorokin - * - * This file is part of TODO plugin for QtCreator. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of the vsorokin nor the names of its contributors may be used to endorse or - * promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * -*/ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ #include "todoplugin.h" -#include -#include -#include +#include "constants.h" #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -TodoPlugin::TodoPlugin() +#include +#include +#include + +namespace Todo { +namespace Internal { + +TodoPlugin::TodoPlugin() : + m_todoOutputPane(0), + m_optionsPage(0), + m_todoItemsProvider(0) { - qRegisterMetaTypeStreamOperators("Keyword"); - qRegisterMetaTypeStreamOperators("KeywordsList"); - currentProject = 0; - inReading = false; - readSettings(); + qRegisterMetaType("TodoItem"); } TodoPlugin::~TodoPlugin() { -// Do notning -} - -void TodoPlugin::readSettings() -{ - QSettings *settings = Core::ICore::instance()->settings(); - settings->beginGroup("TODOPlugin"); - projectOptions = settings->value("project_options", 0).toInt(); - paneOptions = settings->value("pane_options", 0).toInt(); - KeywordsList defaultKeywords; - defaultKeywords.append(Keyword("TODO", QIcon(":/warning"), QColor("#BFFFC8"))); - defaultKeywords.append(Keyword("NOTE", QIcon(":/info"), QColor("#E2DFFF"))); - defaultKeywords.append(Keyword("FIXME", QIcon(":/error"), QColor("#FFBFBF"))); - defaultKeywords.append(Keyword("BUG", QIcon(":/error"), QColor("#FFDFDF"))); - defaultKeywords.append(Keyword("HACK", QIcon(":/info"), QColor("#FFFFAA"))); - - keywords = settings->value("keywords", qVariantFromValue(defaultKeywords)).value(); - settings->endGroup(); + m_settings.save(Core::ICore::settings()); } bool TodoPlugin::initialize(const QStringList& args, QString *errMsg) { Q_UNUSED(args); Q_UNUSED(errMsg); - patternString = generatePatternString(); - settingsPage = new SettingsPage(keywords, projectOptions, paneOptions, this); - if (paneOptions == 0) - { - outPane = new TodoOutputPane(this); - addAutoReleasedObject(outPane); - connect(outPane->getTodoList(), SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(gotoToRowInFile(QListWidgetItem*))); - connect(outPane->getTodoList(), SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(gotoToRowInFile(QListWidgetItem*))); - } - else - { - ExtensionSystem::PluginManager* pluginManager = ExtensionSystem::PluginManager::instance(); - taskHub = pluginManager->getObject(); - if (!taskHub) - { - paneOptions = 1; - outPane = new TodoOutputPane(this); - addAutoReleasedObject(outPane); - connect(outPane->getTodoList(), SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(gotoToRowInFile(QListWidgetItem*))); - connect(outPane->getTodoList(), SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(gotoToRowInFile(QListWidgetItem*))); - QMessageBox::warning((QWidget *)Core::ICore::instance()->mainWindow(), tr("TODO plugin"), tr("Task window object not found.\nWork in TODO Output pane.")); - } - else - { - taskHub->addCategory("todoplugin", tr("TODOs comments")); - } - } - addAutoReleasedObject(settingsPage); + m_settings.load(Core::ICore::settings()); + + createOptionsPage(); + createItemsProvider(); + createTodoOutputPane(); - connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), this, SLOT(currentEditorChanged(Core::IEditor*))); - if (projectOptions != 0) - { - connect(ProjectExplorer::ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project*)), this, SLOT(projectChanged(ProjectExplorer::Project *))); - } return true; } void TodoPlugin::extensionsInitialized() { -// Do nothing } -void TodoPlugin::shutdown() +void TodoPlugin::settingsChanged(const Settings &settings) { -// Do nothing + settings.save(Core::ICore::settings()); + m_settings = settings; + + m_todoItemsProvider->settingsChanged(m_settings); + m_todoOutputPane->setScanningScope(m_settings.scanningScope); + m_optionsPage->setSettings(m_settings); } -void TodoPlugin::showPane() +void TodoPlugin::scanningScopeChanged(ScanningScope scanningScope) { - if (paneOptions == 0) - { - outPane->visibilityChanged(true); - outPane->setFocus(); - } + Settings newSettings = m_settings; + newSettings.scanningScope = scanningScope; + settingsChanged(newSettings); } -void TodoPlugin::gotoToRowInFile(QListWidgetItem *item) +void TodoPlugin::todoItemClicked(const TodoItem &item) { - int row = item->data(Qt::UserRole + 2).toInt(); - QString file = item->data(Qt::UserRole + 1).toString(); - - if (QFileInfo(file).exists()) - { - Core::IEditor *editor = Core::EditorManager::instance()->openEditor(file); - editor->gotoLine(row); + if (QFileInfo(item.file).exists()) { + Core::IEditor *editor = Core::EditorManager::instance()->openEditor(item.file); + editor->gotoLine(item.line); } } -void TodoPlugin::currentEditorChanged(Core::IEditor *editor) +void TodoPlugin::createItemsProvider() { - if (inReading) - return; - if (projectOptions == 0) - { - if (paneOptions == 0) - { - outPane->clearContents(); - } - else - { - taskHub->clearTasks("todoplugin"); - } - } - - if (!editor) - { - return; - } - connect(editor->file(), SIGNAL(changed()), this, SLOT(fileChanged())); - QString fileName = editor->file()->fileName(); - if (projectOptions == 0) - readFile(fileName); - + m_todoItemsProvider = new TodoItemsProvider(m_settings); + addAutoReleasedObject(m_todoItemsProvider); } -void TodoPlugin::removeFromLocalTasks(QString filename) +void TodoPlugin::createTodoOutputPane() { - for (int i = 0; i < tasks.count(); ++i) - { - if (!tasks.at(i).file.compare(filename)) - { - tasks.removeAt(i); - } - } + m_todoOutputPane = new TodoOutputPane(m_todoItemsProvider->todoItemsModel()); + addAutoReleasedObject(m_todoOutputPane); + m_todoOutputPane->setScanningScope(m_settings.scanningScope); + connect(m_todoOutputPane, SIGNAL(scanningScopeChanged(ScanningScope)), SLOT(scanningScopeChanged(ScanningScope))); + connect(m_todoOutputPane, SIGNAL(todoItemClicked(TodoItem)), SLOT(todoItemClicked(TodoItem))); } -void TodoPlugin::addLocalTaskToTaskWindow() +void TodoPlugin::createOptionsPage() { - for (int i = 0; i < tasks.count(); ++i) - { - taskHub->addTask(tasks.at(i)); - } + m_optionsPage = new OptionsPage(m_settings); + addAutoReleasedObject(m_optionsPage); + connect(m_optionsPage, SIGNAL(settingsChanged(Settings)), SLOT(settingsChanged(Settings))); } -void TodoPlugin::fileChanged() -{ - Core::IFile *file = (Core::IFile *)sender(); - if (file) - { - if (projectOptions == 0) - { - if (paneOptions == 0) - { - outPane->clearContents(); - } - else - { - taskHub->clearTasks("todoplugin"); - } - } - else - { - if (paneOptions == 0) - { - outPane->clearContents(file->fileName()); - } - else - { - taskHub->clearTasks("todoplugin"); - removeFromLocalTasks(file->fileName()); - } - } - readFile(file->fileName()); - } -} +Q_EXPORT_PLUGIN2(Todo, TodoPlugin) -Keyword TodoPlugin::prepareOutputString(QString &text) -{ - Keyword keyword; - for(int i = 0; i < keywords.count(); ++i) - { - QRegExp keywordExp("//\\s*" + keywords.at(i).name + "(:|\\s)", Qt::CaseInsensitive); - if (text.contains(keywordExp)) - { - text = text.replace("\n", ""); - text = text.replace("\r", ""); - text = text.replace(keywordExp, keywords.at(i).name + ": "); - text = text.trimmed(); - keyword = keywords.at(i); - break; - } - } - return keyword; -} - -void TodoPlugin::readFile(QString fileName) -{ - QFile file(fileName); - if (!file.open(QFile::ReadOnly | QFile::Text)) - return; - int i = 1; - while (!file.atEnd()) - { - QString currentLine = file.readLine(); - if (currentLine.contains(QRegExp(patternString, Qt::CaseInsensitive))) - { - Keyword resultKeyword = prepareOutputString(currentLine); - QTextCodec *unicodeCodec = QTextCodec::codecForLocale(); - currentLine = unicodeCodec->toUnicode(currentLine.toAscii()); - if (paneOptions == 0) - { - outPane->addItem(currentLine, fileName, i, resultKeyword.icon, resultKeyword.warningColor); - if (!inReading) - outPane->sort(); - } - else - { - ProjectExplorer::Task task(ProjectExplorer::Task::Unknown, currentLine, fileName, i, "todoplugin"); - tasks.append(task); - } - } - ++i; - } - - if (paneOptions != 0 && !inReading) - { - qSort(tasks.begin(), tasks.end(), TodoPlugin::taskLessThan); - addLocalTaskToTaskWindow(); - } -} - -QString TodoPlugin::generatePatternString() -{ - QString result = ""; - - if (keywords.count()) - { - for (int i = 0; i < keywords.count() - 1; ++i) - { - result += "//\\s*" + keywords.at(i).name + "(:|\\s)|"; - } - result += "//\\s*" + keywords.at(keywords.count() - 1).name + "(:|\\s)"; - } - return result; -} - -void TodoPlugin::projectChanged(ProjectExplorer::Project *project) -{ - if (!project) - return; - if (inReading) - return; - currentProject = project; - if (paneOptions == 0) - { - outPane->clearContents(); - } - else - { - taskHub->clearTasks("todoplugin"); - } - inReading = true; - - QFuture result = QtConcurrent::run(&TodoPlugin::readCurrentProject, this); - Core::ICore::instance()->progressManager()->addTask(result, tr("Todoscan"), "Todo.Plugin.Scanning"); - -} - -void TodoPlugin::readCurrentProject(QFutureInterface &future, TodoPlugin *instance) -{ - QStringList filesList = instance->currentProject->files(ProjectExplorer::Project::ExcludeGeneratedFiles); - future.setProgressRange(0, filesList.count()-1); - for (int i = 0; i < filesList.count(); ++i) - { - instance->readFile(filesList.at(i)); - future.setProgressValue(i); - } - - if (instance->paneOptions == 0) - { - instance->outPane->sort(); - } - else - { - qSort(instance->tasks.begin(), instance->tasks.end(), TodoPlugin::taskLessThan); - instance->addLocalTaskToTaskWindow(); - } - - instance->inReading = false; - future.reportFinished(); -} - -bool TodoPlugin::taskLessThan(const ProjectExplorer::Task &t1, const ProjectExplorer::Task &t2) -{ - if (!t1.file.right(t1.file.size() - t1.file.lastIndexOf("/") - 1).compare(t2.file.right(t2.file.size() - t2.file.lastIndexOf("/") - 1))) - { - if (t1.line < t2.line) - { - return true; - } - else - { - return false; - } - } - else - { - return t1.file.right(t1.file.size() - t1.file.lastIndexOf("/") - 1).compare(t2.file.right(t2.file.size() - t2.file.lastIndexOf("/") - 1)) < 0; - } -} - - - -Q_EXPORT_PLUGIN(TodoPlugin) - - +} // namespace Internal +} // namespace Todo diff --git a/src/plugins/todo/todoplugin.h b/src/plugins/todo/todoplugin.h index 1623ac83f34..685b303d031 100755 --- a/src/plugins/todo/todoplugin.h +++ b/src/plugins/todo/todoplugin.h @@ -1,47 +1,51 @@ -/* - * - * TODO plugin - Add pane with list all TODO, FIXME, etc. comments. - * - * Copyright (C) 2010 VasiliySorokin - * - * Authors: Vasiliy Sorokin - * - * This file is part of TODO plugin for QtCreator. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * * Neither the name of the vsorokin nor the names of its contributors may be used to endorse or - * promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * -*/ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Dmitry Savchenko. +** Copyright (c) 2010 Vasiliy Sorokin. +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ #ifndef TODOPLUGIN_H #define TODOPLUGIN_H -#include -#include -#include -#include -#include -#include -#include -#include -#include "todooutputpane.h" -#include "settingspage.h" -#include "keyword.h" +#include "optionspage.h" +#include "keyword.h" +#include "todooutputpane.h" +#include "settings.h" +#include "todoitemsprovider.h" + +#include + +#include + +namespace Todo { +namespace Internal { class TodoPlugin : public ExtensionSystem::IPlugin { @@ -49,43 +53,28 @@ class TodoPlugin : public ExtensionSystem::IPlugin public: TodoPlugin(); ~TodoPlugin(); + void extensionsInitialized(); - bool initialize(const QStringList & arguments, QString * errorString); - void shutdown(); + bool initialize(const QStringList &arguments, QString *errorString); -public slots: - void showPane(); - void gotoToRowInFile(QListWidgetItem *); - void currentEditorChanged(Core::IEditor *editor); - void fileChanged(); - void projectChanged(ProjectExplorer::Project *); - -signals: - void updateFutureValue(int value); - void setFutureRange(int, int); +private slots: + void settingsChanged(const Settings &m_settings); + void scanningScopeChanged(ScanningScope scanningScope); + void todoItemClicked(const TodoItem &item); private: - void readFile(QString); - static void readCurrentProject(QFutureInterface &future, TodoPlugin* instance); - void removeFromLocalTasks(QString filename); - void addLocalTaskToTaskWindow(); + void createItemsProvider(); + void createTodoOutputPane(); + void createOptionsPage(); - static bool taskLessThan(const ProjectExplorer::Task &t1, const ProjectExplorer::Task &t2); - - Keyword prepareOutputString(QString &text); - QString generatePatternString(); - void readSettings(); - TodoOutputPane *outPane; - ProjectExplorer::TaskHub *taskHub; - SettingsPage *settingsPage; - QString patternString; - KeywordsList keywords; - int projectOptions; - int paneOptions; - ProjectExplorer::Project *currentProject; - QList tasks; - bool inReading; - QFutureInterface *progressObject; + Settings m_settings; + TodoOutputPane *m_todoOutputPane; + OptionsPage *m_optionsPage; + TodoItemsProvider *m_todoItemsProvider; }; + +} // namespace Internal +} // namespace Todo + #endif // TODOPLUGIN_H - + diff --git a/src/plugins/todo/todoplugin.pro b/src/plugins/todo/todoplugin.pro deleted file mode 100755 index 83ce31cda10..00000000000 --- a/src/plugins/todo/todoplugin.pro +++ /dev/null @@ -1,46 +0,0 @@ -CONFIG += release -TEMPLATE = lib -TARGET = todo -PROVIDER = vsorokin - -QTC_SOURCE_DIR = /home/vass/qt-creator -IDE_SOURCE_TREE = $$QTC_SOURCE_DIR -QTC_BUILD_DIR = /opt/qtcreator-2.1.81 - -DESTDIR = $$QTC_BUILD_DIR/lib/qtcreator/plugins/$$(PROVIDER) -IDE_BUILD_TREE = $$QTC_BUILD_DIR - -LIBS += -L$$IDE_BUILD_TREE/lib/qtcreator/ \ - -L$$IDE_BUILD_TREE/lib/qtcreator/plugins/Nokia - -include( $$IDE_SOURCE_TREE/src/qtcreatorplugin.pri ) -include( $$IDE_SOURCE_TREE/src/plugins/coreplugin/coreplugin.pri ) -include( $$IDE_SOURCE_TREE/src/plugins/projectexplorer/projectexplorer.pri ) -include( $$IDE_SOURCE_TREE/src/plugins/texteditor/texteditor.pri ) - -INCLUDEPATH += $$IDE_SOURCE_TREE/src \ - $$IDE_SOURCE_TREE/src/plugins \ - $$IDE_SOURCE_TREE/src/libs \ - $$IDE_SOURCE_TREE/src/libs/extensionsystem - - -HEADERS += todoplugin.h \ - todooutputpane.h \ - settingsdialog.h \ - settingspage.h \ - addkeyworddialog.h \ - keyword.h -SOURCES += todoplugin.cpp \ - todooutputpane.cpp \ - settingsdialog.cpp \ - settingspage.cpp \ - addkeyworddialog.cpp \ - keyword.cpp -OTHER_FILES += todo.pluginspec - -RESOURCES += \ - icons.qrc - -FORMS += \ - settingsdialog.ui \ - addkeyworddialog.ui diff --git a/src/plugins/todo/todoplugin.qrc b/src/plugins/todo/todoplugin.qrc new file mode 100644 index 00000000000..42ebc79ca6e --- /dev/null +++ b/src/plugins/todo/todoplugin.qrc @@ -0,0 +1,8 @@ + + + images/todo.png + images/info.png + images/current-file.png + images/whole-project.png + +