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

Change-Id: Ia0c84ef62f833b7967985c0913584ca6ccb03ed1
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
This commit is contained in:
Jochen Becher
2015-05-30 08:54:39 +02:00
parent c2b34fb1ef
commit 051bbb1cd0
8 changed files with 65 additions and 7 deletions

View File

@@ -150,6 +150,7 @@ void OptionsDialog::uiFromSettings(const Settings &settings)
{ {
ui->scanInCurrentFileRadioButton->setChecked(settings.scanningScope == ScanningScopeCurrentFile); ui->scanInCurrentFileRadioButton->setChecked(settings.scanningScope == ScanningScopeCurrentFile);
ui->scanInProjectRadioButton->setChecked(settings.scanningScope == ScanningScopeProject); ui->scanInProjectRadioButton->setChecked(settings.scanningScope == ScanningScopeProject);
ui->scanInSubprojectRadioButton->setChecked(settings.scanningScope == ScanningScopeSubProject);
ui->keywordsList->clear(); ui->keywordsList->clear();
foreach (const Keyword &keyword, settings.keywords) foreach (const Keyword &keyword, settings.keywords)
@@ -162,6 +163,8 @@ Settings OptionsDialog::settingsFromUi()
if (ui->scanInCurrentFileRadioButton->isChecked()) if (ui->scanInCurrentFileRadioButton->isChecked())
settings.scanningScope = ScanningScopeCurrentFile; settings.scanningScope = ScanningScopeCurrentFile;
else if (ui->scanInSubprojectRadioButton->isChecked())
settings.scanningScope = ScanningScopeSubProject;
else else
settings.scanningScope = ScanningScopeProject; settings.scanningScope = ScanningScopeProject;

View File

@@ -101,6 +101,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QRadioButton" name="scanInSubprojectRadioButton">
<property name="text">
<string>Scan the current subproject</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@@ -41,7 +41,8 @@ namespace Internal {
enum ScanningScope { enum ScanningScope {
ScanningScopeCurrentFile, ScanningScopeCurrentFile,
ScanningScopeProject ScanningScopeProject,
ScanningScopeSubProject
}; };
class Settings { class Settings {

View File

@@ -36,7 +36,10 @@
#include "todoitemsmodel.h" #include "todoitemsmodel.h"
#include "todoitemsscanner.h" #include "todoitemsscanner.h"
#include <projectexplorer/nodesvisitor.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/projecttree.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/idocument.h> #include <coreplugin/idocument.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
@@ -90,6 +93,10 @@ void TodoItemsProvider::updateList()
if (m_settings.scanningScope == ScanningScopeCurrentFile) { if (m_settings.scanningScope == ScanningScopeCurrentFile) {
if (m_currentEditor) if (m_currentEditor)
m_itemsList = m_itemsHash.value(m_currentEditor->document()->filePath().toString()); 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 // Show only items of the startup project if any
} else if (m_startupProject) { } else if (m_startupProject) {
setItemsListWithinStartupProject(); 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) void TodoItemsProvider::itemsFetched(const QString &fileName, const QList<TodoItem> &items)
{ {
// Replace old items with new ones // Replace old items with new ones
@@ -161,8 +196,10 @@ void TodoItemsProvider::projectsFilesChanged()
void TodoItemsProvider::currentEditorChanged(Core::IEditor *editor) void TodoItemsProvider::currentEditorChanged(Core::IEditor *editor)
{ {
m_currentEditor = editor; m_currentEditor = editor;
if (m_settings.scanningScope == ScanningScopeCurrentFile) if (m_settings.scanningScope == ScanningScopeCurrentFile
|| m_settings.scanningScope == ScanningScopeSubProject) {
updateList(); updateList();
}
} }
void TodoItemsProvider::updateListTimeoutElapsed() void TodoItemsProvider::updateListTimeoutElapsed()

View File

@@ -86,6 +86,7 @@ private:
void updateList(); void updateList();
void createScanners(); void createScanners();
void setItemsListWithinStartupProject(); void setItemsListWithinStartupProject();
void setItemsListWithinSubproject();
private slots: private slots:
void itemsFetched(const QString &fileName, const QList<TodoItem> &items); void itemsFetched(const QString &fileName, const QList<TodoItem> &items);

View File

@@ -37,10 +37,6 @@
#include <QObject> #include <QObject>
namespace ProjectExplorer {
class Project;
}
namespace Todo { namespace Todo {
namespace Internal { namespace Internal {

View File

@@ -72,7 +72,8 @@ QList<QWidget*> TodoOutputPane::toolBarWidgets() const
return QList<QWidget*>() return QList<QWidget*>()
<< m_spacer << m_spacer
<< m_currentFileButton << m_currentFileButton
<< m_wholeProjectButton; << m_wholeProjectButton
<< m_subProjectButton;
} }
QString TodoOutputPane::displayName() const QString TodoOutputPane::displayName() const
@@ -144,6 +145,8 @@ void TodoOutputPane::setScanningScope(ScanningScope scanningScope)
{ {
if (scanningScope == ScanningScopeCurrentFile) if (scanningScope == ScanningScopeCurrentFile)
m_currentFileButton->setChecked(true); m_currentFileButton->setChecked(true);
else if (scanningScope == ScanningScopeSubProject)
m_subProjectButton->setChecked(true);
else if (scanningScope == ScanningScopeProject) else if (scanningScope == ScanningScopeProject)
m_wholeProjectButton->setChecked(true); m_wholeProjectButton->setChecked(true);
else else
@@ -154,6 +157,8 @@ void TodoOutputPane::scopeButtonClicked(QAbstractButton* button)
{ {
if (button == m_currentFileButton) if (button == m_currentFileButton)
emit scanningScopeChanged(ScanningScopeCurrentFile); emit scanningScopeChanged(ScanningScopeCurrentFile);
else if (button == m_subProjectButton)
emit scanningScopeChanged(ScanningScopeSubProject);
else if (button == m_wholeProjectButton) else if (button == m_wholeProjectButton)
emit scanningScopeChanged(ScanningScopeProject); emit scanningScopeChanged(ScanningScopeProject);
setBadgeNumber(m_todoItemsModel->rowCount()); setBadgeNumber(m_todoItemsModel->rowCount());
@@ -205,9 +210,15 @@ void TodoOutputPane::createScopeButtons()
m_wholeProjectButton->setText(tr("Active Project")); m_wholeProjectButton->setText(tr("Active Project"));
m_wholeProjectButton->setToolTip(tr("Scan the whole 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 = new QButtonGroup();
m_scopeButtons->addButton(m_wholeProjectButton); m_scopeButtons->addButton(m_wholeProjectButton);
m_scopeButtons->addButton(m_currentFileButton); m_scopeButtons->addButton(m_currentFileButton);
m_scopeButtons->addButton(m_subProjectButton);
connect(m_scopeButtons, static_cast<void (QButtonGroup::*)(QAbstractButton *)>(&QButtonGroup::buttonClicked), connect(m_scopeButtons, static_cast<void (QButtonGroup::*)(QAbstractButton *)>(&QButtonGroup::buttonClicked),
this, &TodoOutputPane::scopeButtonClicked); this, &TodoOutputPane::scopeButtonClicked);
@@ -219,6 +230,7 @@ void TodoOutputPane::freeScopeButtons()
{ {
delete m_currentFileButton; delete m_currentFileButton;
delete m_wholeProjectButton; delete m_wholeProjectButton;
delete m_subProjectButton;
delete m_scopeButtons; delete m_scopeButtons;
delete m_spacer; delete m_spacer;
} }

View File

@@ -88,6 +88,7 @@ private:
TodoOutputTreeView *m_todoTreeView; TodoOutputTreeView *m_todoTreeView;
QToolButton *m_currentFileButton; QToolButton *m_currentFileButton;
QToolButton *m_wholeProjectButton; QToolButton *m_wholeProjectButton;
QToolButton *m_subProjectButton;
QWidget *m_spacer; QWidget *m_spacer;
QButtonGroup *m_scopeButtons; QButtonGroup *m_scopeButtons;
QList<TodoItem> *items; QList<TodoItem> *items;