2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Dmitry Savchenko
|
|
|
|
|
** Copyright (C) 2016 Vasiliy Sorokin
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
#include "todoitemsprovider.h"
|
|
|
|
|
#include "constants.h"
|
|
|
|
|
#include "cpptodoitemsscanner.h"
|
|
|
|
|
#include "qmljstodoitemsscanner.h"
|
2012-02-24 09:43:52 +01:00
|
|
|
#include "todoitemsmodel.h"
|
|
|
|
|
#include "todoitemsscanner.h"
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2015-05-30 08:54:39 +02:00
|
|
|
#include <projectexplorer/nodesvisitor.h>
|
2011-10-25 23:14:27 +03:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2015-05-30 08:54:39 +02:00
|
|
|
#include <projectexplorer/projectnodes.h>
|
|
|
|
|
#include <projectexplorer/projecttree.h>
|
2011-10-25 23:14:27 +03:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2011-10-25 23:14:27 +03:00
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
2013-09-05 11:46:07 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
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)
|
|
|
|
|
{
|
2015-05-18 22:47:20 +03:00
|
|
|
if (newSettings.keywords != m_settings.keywords) {
|
2011-10-25 23:14:27 +03:00
|
|
|
foreach (TodoItemsScanner *scanner, m_scanners)
|
2015-05-18 22:47:20 +03:00
|
|
|
scanner->setParams(newSettings.keywords);
|
|
|
|
|
}
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
m_settings = newSettings;
|
|
|
|
|
|
|
|
|
|
updateList();
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
void TodoItemsProvider::projectSettingsChanged(Project *project)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(project);
|
|
|
|
|
updateList();
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void TodoItemsProvider::updateList()
|
|
|
|
|
{
|
|
|
|
|
m_itemsList.clear();
|
|
|
|
|
|
|
|
|
|
// Show only items of the current file if any
|
|
|
|
|
if (m_settings.scanningScope == ScanningScopeCurrentFile) {
|
|
|
|
|
if (m_currentEditor)
|
2014-12-21 21:54:30 +02:00
|
|
|
m_itemsList = m_itemsHash.value(m_currentEditor->document()->filePath().toString());
|
2015-05-30 08:54:39 +02:00
|
|
|
// Show only items of the current sub-project
|
|
|
|
|
} else if (m_settings.scanningScope == ScanningScopeSubProject) {
|
|
|
|
|
if (m_startupProject)
|
|
|
|
|
setItemsListWithinSubproject();
|
2011-10-25 23:14:27 +03:00
|
|
|
// Show only items of the startup project if any
|
2015-05-18 22:47:20 +03:00
|
|
|
} else if (m_startupProject) {
|
|
|
|
|
setItemsListWithinStartupProject();
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_itemsModel->todoItemsListUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TodoItemsProvider::createScanners()
|
|
|
|
|
{
|
|
|
|
|
qRegisterMetaType<QList<TodoItem> >("QList<TodoItem>");
|
|
|
|
|
|
2014-09-15 00:12:27 +02:00
|
|
|
if (CppTools::CppModelManager::instance())
|
2011-10-25 23:14:27 +03:00
|
|
|
m_scanners << new CppTodoItemsScanner(m_settings.keywords, this);
|
|
|
|
|
|
|
|
|
|
if (QmlJS::ModelManagerInterface::instance())
|
|
|
|
|
m_scanners << new QmlJsTodoItemsScanner(m_settings.keywords, this);
|
|
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
foreach (TodoItemsScanner *scanner, m_scanners) {
|
2016-06-05 22:34:47 +03:00
|
|
|
connect(scanner, &TodoItemsScanner::itemsFetched, this,
|
|
|
|
|
&TodoItemsProvider::itemsFetched, Qt::QueuedConnection);
|
2015-05-18 22:47:20 +03:00
|
|
|
}
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TodoItemsProvider::setItemsListWithinStartupProject()
|
|
|
|
|
{
|
|
|
|
|
QHashIterator<QString, QList<TodoItem> > it(m_itemsHash);
|
2016-01-08 16:56:35 +01:00
|
|
|
QSet<QString> fileNames = QSet<QString>::fromList(m_startupProject->files(Project::SourceFiles));
|
2015-05-18 22:47:20 +03:00
|
|
|
|
|
|
|
|
QVariantMap settings = m_startupProject->namedSettings(QLatin1String(Constants::SETTINGS_NAME_KEY)).toMap();
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
2015-05-18 22:47:20 +03:00
|
|
|
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();
|
|
|
|
|
}
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-30 08:54:39 +02:00
|
|
|
void TodoItemsProvider::setItemsListWithinSubproject()
|
|
|
|
|
{
|
|
|
|
|
// TODO prefer current editor as source of sub-project
|
|
|
|
|
Node *node = ProjectTree::currentNode();
|
|
|
|
|
if (node) {
|
2016-11-09 13:39:59 +01:00
|
|
|
ProjectNode *projectNode = node->parentProjectNode();
|
2015-05-30 08:54:39 +02:00
|
|
|
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(
|
2016-01-08 16:56:35 +01:00
|
|
|
m_startupProject->files(ProjectExplorer::Project::SourceFiles));
|
2015-05-30 08:54:39 +02:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void TodoItemsProvider::itemsFetched(const QString &fileName, const QList<TodoItem> &items)
|
|
|
|
|
{
|
|
|
|
|
// Replace old items with new ones
|
|
|
|
|
m_itemsHash.insert(fileName, items);
|
|
|
|
|
|
|
|
|
|
m_shouldUpdateList = true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:56:02 +02:00
|
|
|
void TodoItemsProvider::startupProjectChanged(Project *project)
|
2011-10-25 23:14:27 +03:00
|
|
|
{
|
|
|
|
|
m_startupProject = project;
|
|
|
|
|
updateList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TodoItemsProvider::projectsFilesChanged()
|
|
|
|
|
{
|
|
|
|
|
updateList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TodoItemsProvider::currentEditorChanged(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
m_currentEditor = editor;
|
2015-05-30 08:54:39 +02:00
|
|
|
if (m_settings.scanningScope == ScanningScopeCurrentFile
|
|
|
|
|
|| m_settings.scanningScope == ScanningScopeSubProject) {
|
2011-10-25 23:14:27 +03:00
|
|
|
updateList();
|
2015-05-30 08:54:39 +02:00
|
|
|
}
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TodoItemsProvider::updateListTimeoutElapsed()
|
|
|
|
|
{
|
|
|
|
|
if (m_shouldUpdateList) {
|
|
|
|
|
m_shouldUpdateList = false;
|
|
|
|
|
updateList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TodoItemsProvider::setupStartupProjectBinding()
|
|
|
|
|
{
|
2013-09-05 11:46:07 +02:00
|
|
|
m_startupProject = SessionManager::startupProject();
|
2016-06-05 22:34:47 +03:00
|
|
|
connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
|
|
|
|
|
this, &TodoItemsProvider::startupProjectChanged);
|
|
|
|
|
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::fileListChanged,
|
|
|
|
|
this, &TodoItemsProvider::projectsFilesChanged);
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TodoItemsProvider::setupCurrentEditorBinding()
|
|
|
|
|
{
|
2012-05-08 09:43:14 +02:00
|
|
|
m_currentEditor = Core::EditorManager::currentEditor();
|
2016-06-05 22:34:47 +03:00
|
|
|
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
|
|
|
|
this, &TodoItemsProvider::currentEditorChanged);
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TodoItemsProvider::setupUpdateListTimer()
|
|
|
|
|
{
|
|
|
|
|
m_shouldUpdateList = false;
|
|
|
|
|
QTimer *timer = new QTimer(this);
|
2015-01-29 10:42:16 +01:00
|
|
|
connect(timer, &QTimer::timeout, this, &TodoItemsProvider::updateListTimeoutElapsed);
|
2011-10-25 23:14:27 +03:00
|
|
|
timer->start(Constants::OUTPUT_PANE_UPDATE_INTERVAL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TodoItemsProvider::setupItemsModel()
|
|
|
|
|
{
|
|
|
|
|
m_itemsModel = new TodoItemsModel(this);
|
|
|
|
|
m_itemsModel->setTodoItemsList(&m_itemsList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|