Commit 051bbb1c authored by Jochen Becher's avatar Jochen Becher

Todo Plugin: Add showing To-Do Entries for current sub-project only

Change-Id: Ia0c84ef62f833b7967985c0913584ca6ccb03ed1
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Reviewed-by: default avatarLeena Miettinen <riitta-leena.miettinen@theqtcompany.com>
parent c2b34fb1
......@@ -150,6 +150,7 @@ void OptionsDialog::uiFromSettings(const Settings &settings)
{
ui->scanInCurrentFileRadioButton->setChecked(settings.scanningScope == ScanningScopeCurrentFile);
ui->scanInProjectRadioButton->setChecked(settings.scanningScope == ScanningScopeProject);
ui->scanInSubprojectRadioButton->setChecked(settings.scanningScope == ScanningScopeSubProject);
ui->keywordsList->clear();
foreach (const Keyword &keyword, settings.keywords)
......@@ -162,6 +163,8 @@ Settings OptionsDialog::settingsFromUi()
if (ui->scanInCurrentFileRadioButton->isChecked())
settings.scanningScope = ScanningScopeCurrentFile;
else if (ui->scanInSubprojectRadioButton->isChecked())
settings.scanningScope = ScanningScopeSubProject;
else
settings.scanningScope = ScanningScopeProject;
......
......@@ -101,6 +101,13 @@
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="scanInSubprojectRadioButton">
<property name="text">
<string>Scan the current subproject</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......
......@@ -41,7 +41,8 @@ namespace Internal {
enum ScanningScope {
ScanningScopeCurrentFile,
ScanningScopeProject
ScanningScopeProject,
ScanningScopeSubProject
};
class Settings {
......
......@@ -36,7 +36,10 @@
#include "todoitemsmodel.h"
#include "todoitemsscanner.h"
#include <projectexplorer/nodesvisitor.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/projecttree.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/idocument.h>
#include <projectexplorer/session.h>
......@@ -90,6 +93,10 @@ void TodoItemsProvider::updateList()
if (m_settings.scanningScope == ScanningScopeCurrentFile) {
if (m_currentEditor)
m_itemsList = m_itemsHash.value(m_currentEditor->document()->filePath().toString());
// Show only items of the current sub-project
} else if (m_settings.scanningScope == ScanningScopeSubProject) {
if (m_startupProject)
setItemsListWithinSubproject();
// Show only items of the startup project if any
} else if (m_startupProject) {
setItemsListWithinStartupProject();
......@@ -139,6 +146,34 @@ void TodoItemsProvider::setItemsListWithinStartupProject()
}
}
void TodoItemsProvider::setItemsListWithinSubproject()
{
// TODO prefer current editor as source of sub-project
Node *node = ProjectTree::currentNode();
if (node) {
ProjectNode *projectNode = node->projectNode();
if (projectNode) {
FindAllFilesVisitor filesVisitor;
projectNode->accept(&filesVisitor);
// files must be both in the current subproject and the startup-project.
QSet<Utils::FileName> subprojectFileNames =
QSet<Utils::FileName>::fromList(filesVisitor.filePaths());
QSet<QString> fileNames = QSet<QString>::fromList(
m_startupProject->files(ProjectExplorer::Project::ExcludeGeneratedFiles));
QHashIterator<QString, QList<TodoItem> > it(m_itemsHash);
while (it.hasNext()) {
it.next();
if (subprojectFileNames.contains(Utils::FileName::fromString(it.key()))
&& fileNames.contains(it.key())) {
m_itemsList << it.value();
}
}
}
}
}
void TodoItemsProvider::itemsFetched(const QString &fileName, const QList<TodoItem> &items)
{
// Replace old items with new ones
......@@ -161,8 +196,10 @@ void TodoItemsProvider::projectsFilesChanged()
void TodoItemsProvider::currentEditorChanged(Core::IEditor *editor)
{
m_currentEditor = editor;
if (m_settings.scanningScope == ScanningScopeCurrentFile)
if (m_settings.scanningScope == ScanningScopeCurrentFile
|| m_settings.scanningScope == ScanningScopeSubProject) {
updateList();
}
}
void TodoItemsProvider::updateListTimeoutElapsed()
......
......@@ -86,6 +86,7 @@ private:
void updateList();
void createScanners();
void setItemsListWithinStartupProject();
void setItemsListWithinSubproject();
private slots:
void itemsFetched(const QString &fileName, const QList<TodoItem> &items);
......
......@@ -37,10 +37,6 @@
#include <QObject>
namespace ProjectExplorer {
class Project;
}
namespace Todo {
namespace Internal {
......
......@@ -72,7 +72,8 @@ QList<QWidget*> TodoOutputPane::toolBarWidgets() const
return QList<QWidget*>()
<< m_spacer
<< m_currentFileButton
<< m_wholeProjectButton;
<< m_wholeProjectButton
<< m_subProjectButton;
}
QString TodoOutputPane::displayName() const
......@@ -144,6 +145,8 @@ void TodoOutputPane::setScanningScope(ScanningScope scanningScope)
{
if (scanningScope == ScanningScopeCurrentFile)
m_currentFileButton->setChecked(true);
else if (scanningScope == ScanningScopeSubProject)
m_subProjectButton->setChecked(true);
else if (scanningScope == ScanningScopeProject)
m_wholeProjectButton->setChecked(true);
else
......@@ -154,6 +157,8 @@ void TodoOutputPane::scopeButtonClicked(QAbstractButton* button)
{
if (button == m_currentFileButton)
emit scanningScopeChanged(ScanningScopeCurrentFile);
else if (button == m_subProjectButton)
emit scanningScopeChanged(ScanningScopeSubProject);
else if (button == m_wholeProjectButton)
emit scanningScopeChanged(ScanningScopeProject);
setBadgeNumber(m_todoItemsModel->rowCount());
......@@ -205,9 +210,15 @@ void TodoOutputPane::createScopeButtons()
m_wholeProjectButton->setText(tr("Active Project"));
m_wholeProjectButton->setToolTip(tr("Scan the whole active project."));
m_subProjectButton = new QToolButton();
m_subProjectButton->setCheckable(true);
m_subProjectButton->setText(tr("Subproject"));
m_subProjectButton->setToolTip(tr("Scan the current subproject."));
m_scopeButtons = new QButtonGroup();
m_scopeButtons->addButton(m_wholeProjectButton);
m_scopeButtons->addButton(m_currentFileButton);
m_scopeButtons->addButton(m_subProjectButton);
connect(m_scopeButtons, static_cast<void (QButtonGroup::*)(QAbstractButton *)>(&QButtonGroup::buttonClicked),
this, &TodoOutputPane::scopeButtonClicked);
......@@ -219,6 +230,7 @@ void TodoOutputPane::freeScopeButtons()
{
delete m_currentFileButton;
delete m_wholeProjectButton;
delete m_subProjectButton;
delete m_scopeButtons;
delete m_spacer;
}
......
......@@ -88,6 +88,7 @@ private:
TodoOutputTreeView *m_todoTreeView;
QToolButton *m_currentFileButton;
QToolButton *m_wholeProjectButton;
QToolButton *m_subProjectButton;
QWidget *m_spacer;
QButtonGroup *m_scopeButtons;
QList<TodoItem> *items;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment