diff --git a/src/plugins/todo/constants.h b/src/plugins/todo/constants.h index be84c10248ec0a5d90686e0e28500e8cc1d2b70f..f16165d5636345f8823c29797abd0e01e1895667 100644 --- a/src/plugins/todo/constants.h +++ b/src/plugins/todo/constants.h @@ -54,6 +54,8 @@ const char ITEMS_DISPLAY_PLACE[] = "ItemsDisplayPlace"; const char KEYWORDS_LIST[] = "Keywords"; const char OUTPUT_PANE_TEXT_WIDTH[] = "OutputPaneTextColumnWidth"; const char OUTPUT_PANE_FILE_WIDTH[] = "OutputPaneFileColumnWidth"; +const char SETTINGS_NAME_KEY[] = "TodoProjectSettings"; +const char EXCLUDES_LIST_KEY[] = "ExcludesList"; // TODO Output TreeWidget columns enum OutputColumnIndex { diff --git a/src/plugins/todo/cpptodoitemsscanner.cpp b/src/plugins/todo/cpptodoitemsscanner.cpp index 4a1dd384d0cd16b5f0e0c54376b97ccc958799a6..3239a0c9b7e34d85875847a0ba31ceb3382eb0a0 100644 --- a/src/plugins/todo/cpptodoitemsscanner.cpp +++ b/src/plugins/todo/cpptodoitemsscanner.cpp @@ -46,9 +46,11 @@ CppTodoItemsScanner::CppTodoItemsScanner(const KeywordList &keywordList, QObject connect(modelManager, &CppTools::CppModelManager::documentUpdated, this, &CppTodoItemsScanner::documentUpdated, Qt::DirectConnection); + + setParams(keywordList); } -void CppTodoItemsScanner::keywordListChanged() +void CppTodoItemsScanner::scannerParamsChanged() { // 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. @@ -72,7 +74,6 @@ void CppTodoItemsScanner::documentUpdated(CPlusPlus::Document::Ptr doc) void CppTodoItemsScanner::processDocument(CPlusPlus::Document::Ptr doc) { QList itemList; - CPlusPlus::TranslationUnit *translationUnit = doc->translationUnit(); for (unsigned i = 0; i < translationUnit->commentCount(); ++i) { diff --git a/src/plugins/todo/cpptodoitemsscanner.h b/src/plugins/todo/cpptodoitemsscanner.h index 771be2fdbc1563190a6ae08006f0e4b26a8a0ed0..43d4b091c42be3aa8ee9d6df3695fa3ef5ea965d 100644 --- a/src/plugins/todo/cpptodoitemsscanner.h +++ b/src/plugins/todo/cpptodoitemsscanner.h @@ -47,7 +47,7 @@ public: explicit CppTodoItemsScanner(const KeywordList &keywordList, QObject *parent = 0); protected: - void keywordListChanged(); + void scannerParamsChanged(); private slots: void documentUpdated(CPlusPlus::Document::Ptr doc); diff --git a/src/plugins/todo/optionsdialog.cpp b/src/plugins/todo/optionsdialog.cpp index 8f675a647f113f451113ed106f459d6c1a20fbdb..8fb5ca260519b62c3e17e5bcb9295f9731dc7b4a 100644 --- a/src/plugins/todo/optionsdialog.cpp +++ b/src/plugins/todo/optionsdialog.cpp @@ -44,12 +44,12 @@ OptionsDialog::OptionsDialog(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())); - connect(ui->keywordsList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), SLOT(itemDoubleClicked(QListWidgetItem*))); + setKeywordsButtonsEnabled(); + connect(ui->addKeywordButton, SIGNAL(clicked()), SLOT(addKeywordButtonClicked())); + connect(ui->removeKeywordButton, SIGNAL(clicked()), SLOT(removeKeywordButtonClicked())); + connect(ui->editKeywordButton, SIGNAL(clicked()), SLOT(editKeywordButtonClicked())); + connect(ui->resetKeywordsButton, SIGNAL(clicked()), SLOT(resetKeywordsButtonClicked())); + connect(ui->keywordsList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), SLOT(keywordDoubleClicked(QListWidgetItem*))); } OptionsDialog::~OptionsDialog() @@ -57,9 +57,9 @@ OptionsDialog::~OptionsDialog() delete ui; } -void OptionsDialog::itemDoubleClicked(QListWidgetItem *item) +void OptionsDialog::keywordDoubleClicked(QListWidgetItem *item) { - editItem(item); + editKeyword(item); } void OptionsDialog::setSettings(const Settings &settings) @@ -91,7 +91,7 @@ Settings OptionsDialog::settings() return settingsFromUi(); } -void OptionsDialog::addButtonClicked() +void OptionsDialog::addKeywordButtonClicked() { Keyword keyword; KeywordDialog *keywordDialog = new KeywordDialog(keyword, keywordNames(), this); @@ -101,13 +101,13 @@ void OptionsDialog::addButtonClicked() } } -void OptionsDialog::editButtonClicked() +void OptionsDialog::editKeywordButtonClicked() { QListWidgetItem *item = ui->keywordsList->currentItem(); - editItem(item); + editKeyword(item); } -void OptionsDialog::editItem(QListWidgetItem *item) +void OptionsDialog::editKeyword(QListWidgetItem *item) { Keyword keyword; keyword.name = item->text(); @@ -127,58 +127,58 @@ void OptionsDialog::editItem(QListWidgetItem *item) } } -void OptionsDialog::removeButtonClicked() +void OptionsDialog::removeKeywordButtonClicked() { - ui->keywordsList->takeItem(ui->keywordsList->currentRow()); + delete ui->keywordsList->takeItem(ui->keywordsList->currentRow()); } -void OptionsDialog::resetButtonClicked() +void OptionsDialog::resetKeywordsButtonClicked() { Settings newSettings; newSettings.setDefault(); uiFromSettings(newSettings); } -void OptionsDialog::setButtonsEnabled() +void OptionsDialog::setKeywordsButtonsEnabled() { bool isSomethingSelected = ui->keywordsList->selectedItems().count() != 0; - ui->removeButton->setEnabled(isSomethingSelected); - ui->editButton->setEnabled(isSomethingSelected); + ui->removeKeywordButton->setEnabled(isSomethingSelected); + ui->editKeywordButton->setEnabled(isSomethingSelected); } - void OptionsDialog::uiFromSettings(const Settings &settings) - { - ui->scanInCurrentFileRadioButton->setChecked(settings.scanningScope == ScanningScopeCurrentFile); - ui->scanInProjectRadioButton->setChecked(settings.scanningScope == ScanningScopeProject); +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); - } + ui->keywordsList->clear(); + foreach (const Keyword &keyword, settings.keywords) + addToKeywordsList(keyword); +} - Settings OptionsDialog::settingsFromUi() - { - Settings settings; +Settings OptionsDialog::settingsFromUi() +{ + Settings settings; - if (ui->scanInCurrentFileRadioButton->isChecked()) - settings.scanningScope = ScanningScopeCurrentFile; - else - settings.scanningScope = ScanningScopeProject; + 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); + 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(); + Keyword keyword; + keyword.name = item->text(); + keyword.iconResource = item->data(Qt::UserRole).toString(); + keyword.color = item->backgroundColor(); - settings.keywords << keyword; - } + settings.keywords << keyword; + } - return settings; - } + return settings; +} } // namespace Internal } // namespace Todo diff --git a/src/plugins/todo/optionsdialog.h b/src/plugins/todo/optionsdialog.h index 5ea22c51b94c6a8f3b51d140f66ec83c4d023c78..2b50917309ef35540be121c936ff782559f4eeba 100644 --- a/src/plugins/todo/optionsdialog.h +++ b/src/plugins/todo/optionsdialog.h @@ -57,18 +57,18 @@ public: Settings settings(); private slots: - void addButtonClicked(); - void editButtonClicked(); - void removeButtonClicked(); - void resetButtonClicked(); - void setButtonsEnabled(); - void itemDoubleClicked(QListWidgetItem *item); + void addKeywordButtonClicked(); + void editKeywordButtonClicked(); + void removeKeywordButtonClicked(); + void resetKeywordsButtonClicked(); + void setKeywordsButtonsEnabled(); + void keywordDoubleClicked(QListWidgetItem *item); private: void uiFromSettings(const Settings &settings); Settings settingsFromUi(); void addToKeywordsList(const Keyword &keyword); - void editItem(QListWidgetItem *item); + void editKeyword(QListWidgetItem *item); QSet keywordNames(); Ui::OptionsDialog *ui; diff --git a/src/plugins/todo/optionsdialog.ui b/src/plugins/todo/optionsdialog.ui index b07912b5e93a6d11d06c5993bbd87d4c5100e4d2..a440652155acc78c23cd512a091639bc266b62eb 100644 --- a/src/plugins/todo/optionsdialog.ui +++ b/src/plugins/todo/optionsdialog.ui @@ -6,8 +6,8 @@ 0 0 - 377 - 299 + 444 + 482 @@ -30,28 +30,28 @@ - + Add - + Edit - + Remove - + Reset @@ -112,7 +112,7 @@ keywordsList itemSelectionChanged() Todo::Internal::OptionsDialog - setButtonsEnabled() + setKeywordsButtonsEnabled() 247 @@ -126,6 +126,6 @@ - setButtonsEnabled() + setKeywordsButtonsEnabled() diff --git a/src/plugins/todo/qmljstodoitemsscanner.cpp b/src/plugins/todo/qmljstodoitemsscanner.cpp index 1d35b6af7c7bf46be693ea0aee5e08b24258a9c3..41451301c2f3815dd39bb0f55491be9c6ef3af7b 100644 --- a/src/plugins/todo/qmljstodoitemsscanner.cpp +++ b/src/plugins/todo/qmljstodoitemsscanner.cpp @@ -44,19 +44,22 @@ QmlJsTodoItemsScanner::QmlJsTodoItemsScanner(const KeywordList &keywordList, QOb QmlJS::ModelManagerInterface *model = QmlJS::ModelManagerInterface::instance(); connect(model, &QmlJS::ModelManagerInterface::documentUpdated, this, &QmlJsTodoItemsScanner::documentUpdated, Qt::DirectConnection); + + setParams(keywordList); } bool QmlJsTodoItemsScanner::shouldProcessFile(const QString &fileName) { QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance(); - foreach (const QmlJS::ModelManagerInterface::ProjectInfo &info, modelManager->projectInfos()) + foreach (const QmlJS::ModelManagerInterface::ProjectInfo &info, modelManager->projectInfos()) { if (info.sourceFiles.contains(fileName)) return true; + } return false; } -void QmlJsTodoItemsScanner::keywordListChanged() +void QmlJsTodoItemsScanner::scannerParamsChanged() { // 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. @@ -81,7 +84,6 @@ 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 diff --git a/src/plugins/todo/qmljstodoitemsscanner.h b/src/plugins/todo/qmljstodoitemsscanner.h index 3ade03166fce2c2c8e0a5ef5987c476754bcf24c..8ea0f8edb91090ebba325ba4dadc5deb43d7e332 100644 --- a/src/plugins/todo/qmljstodoitemsscanner.h +++ b/src/plugins/todo/qmljstodoitemsscanner.h @@ -48,7 +48,7 @@ public: protected: bool shouldProcessFile(const QString &fileName); - void keywordListChanged(); + void scannerParamsChanged() override; private slots: void documentUpdated(QmlJS::Document::Ptr doc); diff --git a/src/plugins/todo/settings.cpp b/src/plugins/todo/settings.cpp index 35d351d60185af7755ef21ed09af5430196a44b6..a6aaee6cb88a07dd75826632e781d75895cf60a6 100644 --- a/src/plugins/todo/settings.cpp +++ b/src/plugins/todo/settings.cpp @@ -72,12 +72,12 @@ void Settings::load(QSettings *settings) scanningScope).toInt()); KeywordList newKeywords; - const int size = settings->beginReadArray(QLatin1String(Constants::KEYWORDS_LIST)); - if (size > 0) { + const int keywordsSize = settings->beginReadArray(QLatin1String(Constants::KEYWORDS_LIST)); + if (keywordsSize > 0) { const QString nameKey = QLatin1String("name"); const QString colorKey = QLatin1String("color"); const QString iconResourceKey = QLatin1String("iconResource"); - for (int i = 0; i < size; ++i) { + for (int i = 0; i < keywordsSize; ++i) { settings->setArrayIndex(i); Keyword keyword; keyword.name = settings->value(nameKey).toString(); @@ -129,8 +129,7 @@ void Settings::setDefault() bool Settings::equals(const Settings &other) const { return (keywords == other.keywords) - && (scanningScope == other.scanningScope); - + && (scanningScope == other.scanningScope); } bool operator ==(Settings &s1, Settings &s2) diff --git a/src/plugins/todo/todo.pro b/src/plugins/todo/todo.pro index f430c04daf0295dac28a8f2b4a7be65aae9cd036..a485a50a8a607bf6eb994d7c0fed2f1e98405206 100644 --- a/src/plugins/todo/todo.pro +++ b/src/plugins/todo/todo.pro @@ -16,7 +16,9 @@ HEADERS += todoplugin.h \ qmljstodoitemsscanner.h \ lineparser.h \ todooutputtreeview.h \ - todooutputtreeviewdelegate.h + todooutputtreeviewdelegate.h \ + todoprojectsettingswidget.h + SOURCES += todoplugin.cpp \ keyword.cpp \ todooutputpane.cpp \ @@ -31,11 +33,13 @@ SOURCES += todoplugin.cpp \ qmljstodoitemsscanner.cpp \ lineparser.cpp \ todooutputtreeview.cpp \ - todooutputtreeviewdelegate.cpp + todooutputtreeviewdelegate.cpp \ + todoprojectsettingswidget.cpp RESOURCES += \ todoplugin.qrc FORMS += \ optionsdialog.ui \ - keyworddialog.ui + keyworddialog.ui \ + todoprojectsettingswidget.ui diff --git a/src/plugins/todo/todo.qbs b/src/plugins/todo/todo.qbs index cfeae575cdd0c1da8dd613e00f6100009472f414..e72b2862e67724921f5653a97a351fd355b4dbdc 100644 --- a/src/plugins/todo/todo.qbs +++ b/src/plugins/todo/todo.qbs @@ -26,6 +26,9 @@ QtcPlugin { "optionsdialog.cpp", "optionsdialog.h", "optionsdialog.ui", + "todoprojectsettingswidget.cpp", + "todoprojectsettingswidget.h", + "todoprojectsettingswidget.ui", "optionspage.cpp", "optionspage.h", "qmljstodoitemsscanner.cpp", diff --git a/src/plugins/todo/todoitemsprovider.cpp b/src/plugins/todo/todoitemsprovider.cpp index ccad022cfde0e7118c38b633b72e1176163b742d..8308cdc7aff0f7aa99dde49c1be4ea992001d67d 100644 --- a/src/plugins/todo/todoitemsprovider.cpp +++ b/src/plugins/todo/todoitemsprovider.cpp @@ -66,15 +66,22 @@ TodoItemsModel *TodoItemsProvider::todoItemsModel() void TodoItemsProvider::settingsChanged(const Settings &newSettings) { - if (newSettings.keywords != m_settings.keywords) + if (newSettings.keywords != m_settings.keywords) { foreach (TodoItemsScanner *scanner, m_scanners) - scanner->setKeywordList(newSettings.keywords); + scanner->setParams(newSettings.keywords); + } m_settings = newSettings; updateList(); } +void TodoItemsProvider::projectSettingsChanged(Project *project) +{ + Q_UNUSED(project); + updateList(); +} + void TodoItemsProvider::updateList() { m_itemsList.clear(); @@ -84,9 +91,8 @@ void TodoItemsProvider::updateList() if (m_currentEditor) m_itemsList = m_itemsHash.value(m_currentEditor->document()->filePath().toString()); // Show only items of the startup project if any - } else { - if (m_startupProject) - setItemsListWithinStartupProject(); + } else if (m_startupProject) { + setItemsListWithinStartupProject(); } m_itemsModel->todoItemsListUpdated(); @@ -102,19 +108,34 @@ void TodoItemsProvider::createScanners() if (QmlJS::ModelManagerInterface::instance()) m_scanners << new QmlJsTodoItemsScanner(m_settings.keywords, this); - foreach (TodoItemsScanner *scanner, m_scanners) + 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); QSet fileNames = QSet::fromList(m_startupProject->files(Project::ExcludeGeneratedFiles)); + + QVariantMap settings = m_startupProject->namedSettings(QLatin1String(Constants::SETTINGS_NAME_KEY)).toMap(); + while (it.hasNext()) { it.next(); - if (fileNames.contains(it.key())) - m_itemsList << it.value(); + QString fileName = it.key(); + if (fileNames.contains(fileName)) { + bool skip = false; + for (const QVariant &pattern : settings[QLatin1String(Constants::EXCLUDES_LIST_KEY)].toList()) { + QRegExp re(pattern.toString()); + if (re.indexIn(fileName) != -1) { + skip = true; + break; + } + } + if (!skip) + m_itemsList << it.value(); + } } } diff --git a/src/plugins/todo/todoitemsprovider.h b/src/plugins/todo/todoitemsprovider.h index dfb209e044b051c66bb81e9ceef9bc9f1d3b038c..75a64cb1d3b339e66ac0e7219e439992be077384 100644 --- a/src/plugins/todo/todoitemsprovider.h +++ b/src/plugins/todo/todoitemsprovider.h @@ -57,6 +57,7 @@ public: public slots: void settingsChanged(const Settings &newSettings); + void projectSettingsChanged(ProjectExplorer::Project *project); signals: void itemsUpdated(); diff --git a/src/plugins/todo/todoitemsscanner.cpp b/src/plugins/todo/todoitemsscanner.cpp index 31826bb3c908732e37b63d2921bc31db32df833a..b8d1a3bbf288a057da634ce93da53035fcc03c1c 100644 --- a/src/plugins/todo/todoitemsscanner.cpp +++ b/src/plugins/todo/todoitemsscanner.cpp @@ -39,25 +39,20 @@ namespace Todo { namespace Internal { TodoItemsScanner::TodoItemsScanner(const KeywordList &keywordList, QObject *parent) : - QObject(parent) + QObject(parent), m_keywordList(keywordList) { - setKeywordList(keywordList); } -void TodoItemsScanner::setKeywordList(const KeywordList &keywordList) +void TodoItemsScanner::setParams(const KeywordList &keywordList) { m_keywordList = keywordList; - keywordListChanged(); + scannerParamsChanged(); } -// 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) + unsigned lineNumber, QList &outItemList) { LineParser parser(m_keywordList); QList newItemList = parser.parse(comment); diff --git a/src/plugins/todo/todoitemsscanner.h b/src/plugins/todo/todoitemsscanner.h index 32286d7e58d6aba85768a1cdd109877e44d31cc2..b6313227ca56d4dc401531d62f7aa006dbd659a4 100644 --- a/src/plugins/todo/todoitemsscanner.h +++ b/src/plugins/todo/todoitemsscanner.h @@ -37,6 +37,10 @@ #include +namespace ProjectExplorer { +class Project; +} + namespace Todo { namespace Internal { @@ -48,7 +52,7 @@ class TodoItemsScanner : public QObject public: explicit TodoItemsScanner(const KeywordList &keywordList, QObject *parent = 0); - void setKeywordList(const KeywordList &keywordList); + void setParams(const KeywordList &keywordList); signals: void itemsFetched(const QString &fileName, const QList &items); @@ -56,9 +60,11 @@ signals: protected: KeywordList m_keywordList; - virtual void keywordListChanged(); - void processCommentLine(const QString &fileName, const QString &comment, unsigned lineNumber, - QList &outItemList); + // Descendants can override and make a request for full rescan here if needed + virtual void scannerParamsChanged() = 0; + + void processCommentLine(const QString &fileName, const QString &comment, + unsigned lineNumber, QList &outItemList); }; } diff --git a/src/plugins/todo/todoplugin.cpp b/src/plugins/todo/todoplugin.cpp index 9d33ba4ae00f3c9ddce34d6cb653c5bc6e8e6abf..68156167d6c9ccbf48d1053e98b46d8655c4ebb4 100644 --- a/src/plugins/todo/todoplugin.cpp +++ b/src/plugins/todo/todoplugin.cpp @@ -35,10 +35,12 @@ #include "keyword.h" #include "todooutputpane.h" #include "todoitemsprovider.h" +#include "todoprojectsettingswidget.h" #include #include #include +#include #include #include @@ -71,6 +73,23 @@ bool TodoPlugin::initialize(const QStringList& args, QString *errMsg) createItemsProvider(); createTodoOutputPane(); + auto panelFactory = new ProjectExplorer::ProjectPanelFactory(); + panelFactory->setPriority(100); + panelFactory->setDisplayName(TodoProjectSettingsWidget::tr("To-Do Settings")); + panelFactory->setCreateWidgetFunction([this, panelFactory](ProjectExplorer::Project *project) -> QWidget * { + auto *panel = new ProjectExplorer::PropertiesPanel; + panel->setDisplayName(panelFactory->displayName()); + auto *widget = new TodoProjectSettingsWidget(project); + connect(widget, &TodoProjectSettingsWidget::projectSettingsChanged, + m_todoItemsProvider, [this, project](){m_todoItemsProvider->projectSettingsChanged(project);}); + panel->setWidget(widget); + auto *panelsWidget = new ProjectExplorer::PanelsWidget(); + panelsWidget->addPropertiesPanel(panel); + panelsWidget->setFocusProxy(widget); + return panelsWidget; + }); + ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory); + return true; } diff --git a/src/plugins/todo/todoprojectsettingswidget.cpp b/src/plugins/todo/todoprojectsettingswidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..64b61eed5c5ba8d22abfdcdb96342bd12d9e7d5e --- /dev/null +++ b/src/plugins/todo/todoprojectsettingswidget.cpp @@ -0,0 +1,136 @@ +/************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ +#include "todoprojectsettingswidget.h" +#include "ui_todoprojectsettingswidget.h" +#include "constants.h" + +#include + +namespace Todo { +namespace Internal { + +static const QString EXCLUDE_PLACEHOLDER = QObject::tr(""); + +TodoProjectSettingsWidget::TodoProjectSettingsWidget(ProjectExplorer::Project *project) : + QWidget(0), + ui(new Ui::TodoProjectSettingsWidget), + m_project(project) +{ + ui->setupUi(this); + + setExcludedPatternsButtonsEnabled(); + connect(ui->addExcludedPatternButton, &QPushButton::clicked, + this, &TodoProjectSettingsWidget::addExcludedPatternButtonClicked); + connect(ui->removeExcludedPatternButton, &QPushButton::clicked, + this, &TodoProjectSettingsWidget::removeExcludedPatternButtonClicked); + connect(ui->excludedPatternsList, &QListWidget::itemChanged, + this, &TodoProjectSettingsWidget::excludedPatternChanged, Qt::QueuedConnection); + + loadSettings(); +} + +TodoProjectSettingsWidget::~TodoProjectSettingsWidget() +{ + delete ui; +} + +QListWidgetItem *TodoProjectSettingsWidget::addToExcludedPatternsList(const QString &pattern) +{ + QListWidgetItem *item = new QListWidgetItem(pattern); + item->setFlags(item->flags() | Qt::ItemIsEditable); + prepareItem(item); + ui->excludedPatternsList->addItem(item); + return item; +} + +void TodoProjectSettingsWidget::loadSettings() +{ + QVariant s = m_project->namedSettings(QLatin1String(Constants::SETTINGS_NAME_KEY)); + QVariantMap settings = s.toMap(); + ui->excludedPatternsList->clear(); + for (const QVariant &pattern : settings[QLatin1String(Constants::EXCLUDES_LIST_KEY)].toList()) + addToExcludedPatternsList(pattern.toString()); +} + +void TodoProjectSettingsWidget::saveSettings() +{ + QVariantMap settings; + QVariantList excludes; + + for (int i = 0; i < ui->excludedPatternsList->count(); ++i) + excludes << ui->excludedPatternsList->item(i)->text(); + + settings[QLatin1String(Constants::EXCLUDES_LIST_KEY)] = excludes; + + m_project->setNamedSettings(QLatin1String(Constants::SETTINGS_NAME_KEY), settings); + emit projectSettingsChanged(); +} + +void TodoProjectSettingsWidget::prepareItem(QListWidgetItem *item) const +{ + if (QRegExp(item->text()).isValid()) + item->setForeground(QBrush(ui->excludedPatternsList->palette().color(QPalette::Active, QPalette::Text))); + else + item->setForeground(QBrush(Qt::red)); +} + +void TodoProjectSettingsWidget::addExcludedPatternButtonClicked() +{ + if (ui->excludedPatternsList->findItems(EXCLUDE_PLACEHOLDER, Qt::MatchFixedString).count()) + return; + ui->excludedPatternsList->editItem(addToExcludedPatternsList(EXCLUDE_PLACEHOLDER)); +} + +void TodoProjectSettingsWidget::removeExcludedPatternButtonClicked() +{ + delete ui->excludedPatternsList->takeItem(ui->excludedPatternsList->currentRow()); + saveSettings(); +} + +void TodoProjectSettingsWidget::setExcludedPatternsButtonsEnabled() +{ + bool isSomethingSelected = ui->excludedPatternsList->selectedItems().count() != 0; + ui->removeExcludedPatternButton->setEnabled(isSomethingSelected); +} + +void TodoProjectSettingsWidget::excludedPatternChanged(QListWidgetItem *item) +{ + if (item->text().isEmpty() || item->text() == EXCLUDE_PLACEHOLDER) { + ui->excludedPatternsList->removeItemWidget(item); + delete item; + } else { + prepareItem(item); + } + saveSettings(); + ui->excludedPatternsList->setCurrentItem(nullptr); +} + +} // namespace Internal +} // namespace Todo diff --git a/src/plugins/todo/todoprojectsettingswidget.h b/src/plugins/todo/todoprojectsettingswidget.h new file mode 100644 index 0000000000000000000000000000000000000000..9c9f5a8139ef916bfeac67259f614f28c42846d6 --- /dev/null +++ b/src/plugins/todo/todoprojectsettingswidget.h @@ -0,0 +1,80 @@ +/************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ +#ifndef TODO_INTERNAL_TODOPROJECTSETTINGSWIDGET_H +#define TODO_INTERNAL_TODOPROJECTSETTINGSWIDGET_H + +#include + +QT_BEGIN_NAMESPACE +class QListWidgetItem; +QT_END_NAMESPACE + +namespace ProjectExplorer { +class Project; +} + +namespace Todo { +namespace Internal { + +namespace Ui { +class TodoProjectSettingsWidget; +} + +class TodoProjectSettingsWidget : public QWidget +{ + Q_OBJECT + +public: + explicit TodoProjectSettingsWidget(ProjectExplorer::Project *project); + ~TodoProjectSettingsWidget(); + +signals: + void projectSettingsChanged(); + +private slots: + void addExcludedPatternButtonClicked(); + void removeExcludedPatternButtonClicked(); + void setExcludedPatternsButtonsEnabled(); + void excludedPatternChanged(QListWidgetItem *item); + +private: + QListWidgetItem *addToExcludedPatternsList(const QString &pattern); + void loadSettings(); + void saveSettings(); + void prepareItem(QListWidgetItem *item) const; + + Ui::TodoProjectSettingsWidget *ui; + ProjectExplorer::Project *m_project; +}; + + +} // namespace Internal +} // namespace Todo +#endif // TODO_INTERNAL_TODOPROJECTSETTINGSWIDGET_H diff --git a/src/plugins/todo/todoprojectsettingswidget.ui b/src/plugins/todo/todoprojectsettingswidget.ui new file mode 100644 index 0000000000000000000000000000000000000000..2b43e1d96c0af90a3c8bd8156c77854f8f21e097 --- /dev/null +++ b/src/plugins/todo/todoprojectsettingswidget.ui @@ -0,0 +1,91 @@ + + + Todo::Internal::TodoProjectSettingsWidget + + + + 0 + 0 + 814 + 330 + + + + + + + Excluded Files + + + + + + Regular expressions for file paths to be excluded from scanning. + + + true + + + + + + + + + Add + + + + + + + Remove + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 40 + + + + + + + + + + + + + + + excludedPatternsList + itemSelectionChanged() + Todo::Internal::TodoProjectSettingsWidget + setExcludedPatternsButtonsEnabled() + + + 170 + 381 + + + 221 + 240 + + + + + + setExcludedPatternsButtonsEnabled() + +