forked from qt-creator/qt-creator
Improve TaskList plugin
* Automatically reload task lists. * Add task handler to stop the reloading * Add some really simple API for other plugins to use.
This commit is contained in:
69
src/plugins/tasklist/stopmonitoringhandler.cpp
Normal file
69
src/plugins/tasklist/stopmonitoringhandler.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file 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 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.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "stopmonitoringhandler.h"
|
||||
|
||||
#include "tasklistconstants.h"
|
||||
#include "tasklistplugin.h"
|
||||
|
||||
#include <projectexplorer/task.h>
|
||||
|
||||
#include <QtGui/QAction>
|
||||
|
||||
using namespace TaskList;
|
||||
using namespace TaskList::Internal;
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// StopMonitoringHandler
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
StopMonitoringHandler::StopMonitoringHandler() :
|
||||
ProjectExplorer::ITaskHandler(QLatin1String("TaskList.StopMonitoringHandler"))
|
||||
{ }
|
||||
|
||||
StopMonitoringHandler::~StopMonitoringHandler()
|
||||
{ }
|
||||
|
||||
bool StopMonitoringHandler::canHandle(const ProjectExplorer::Task &task)
|
||||
{
|
||||
return task.category == QLatin1String(Constants::TASKLISTTASK_ID);
|
||||
}
|
||||
|
||||
void StopMonitoringHandler::handle(const ProjectExplorer::Task &task)
|
||||
{
|
||||
Q_ASSERT(canHandle(task));
|
||||
TaskList::TaskListPlugin::instance()->stopMonitoring();
|
||||
}
|
||||
|
||||
QAction *StopMonitoringHandler::createAction(QObject *parent)
|
||||
{
|
||||
QAction *stopMonitoringAction = new QAction(tr("Stop monitoring"), parent);
|
||||
stopMonitoringAction->setToolTip(tr("Stop monitoring task files."));
|
||||
return stopMonitoringAction;
|
||||
}
|
||||
@@ -27,40 +27,26 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef TASKLISTMANAGER_H
|
||||
#define TASKLISTMANAGER_H
|
||||
#ifndef STOPMONITORINGHANDLER_H
|
||||
#define STOPMONITORINGHANDLER_H
|
||||
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class TaskHub;
|
||||
} // namespace ProjectExplorer
|
||||
#include <projectexplorer/itaskhandler.h>
|
||||
|
||||
namespace TaskList {
|
||||
namespace Internal {
|
||||
|
||||
class TaskListManager : public QObject
|
||||
class StopMonitoringHandler : public ProjectExplorer::ITaskHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TaskListManager(QObject *parent = 0);
|
||||
~TaskListManager();
|
||||
StopMonitoringHandler();
|
||||
~StopMonitoringHandler();
|
||||
|
||||
public slots:
|
||||
void setTaskFile(const QString &name);
|
||||
|
||||
private:
|
||||
void parseTaskFile(const QString &name);
|
||||
QStringList parseRawLine(const QByteArray &raw);
|
||||
QString unescape(const QString &input) const;
|
||||
|
||||
ProjectExplorer::TaskHub *m_hub;
|
||||
bool canHandle(const ProjectExplorer::Task &);
|
||||
void handle(const ProjectExplorer::Task &);
|
||||
QAction *createAction(QObject *parent = 0);
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace TaskList
|
||||
|
||||
#endif // TASKLISTMANAGER_H
|
||||
#endif // STOPMONITORINGHANDLER_H
|
||||
128
src/plugins/tasklist/taskfile.cpp
Normal file
128
src/plugins/tasklist/taskfile.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file 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 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.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "taskfile.h"
|
||||
|
||||
#include "tasklistplugin.h"
|
||||
|
||||
using namespace TaskList;
|
||||
using namespace TaskList::Internal;
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// TaskFile
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
TaskFile::TaskFile(QObject *parent) : Core::IFile(parent),
|
||||
m_context(0)
|
||||
{ }
|
||||
|
||||
TaskFile::~TaskFile()
|
||||
{ }
|
||||
|
||||
bool TaskFile::save(const QString &fileName)
|
||||
{
|
||||
Q_UNUSED(fileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
QString TaskFile::fileName() const
|
||||
{
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
QString TaskFile::defaultPath() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString TaskFile::suggestedFileName() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString TaskFile::mimeType() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool TaskFile::isModified() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TaskFile::isReadOnly() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TaskFile::isSaveAsAllowed() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Core::IFile::ReloadBehavior TaskFile::reloadBehavior(ChangeTrigger state, ChangeType type) const
|
||||
{
|
||||
Q_UNUSED(state);
|
||||
if (type != TypePermissions)
|
||||
return BehaviorSilent;
|
||||
return BehaviorAsk;
|
||||
}
|
||||
|
||||
void TaskFile::reload(ReloadFlag flag, ChangeType type)
|
||||
{
|
||||
Q_UNUSED(flag);
|
||||
|
||||
if (type == TypePermissions)
|
||||
return;
|
||||
open(m_fileName);
|
||||
if (type == TypeRemoved)
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
void TaskFile::rename(const QString &newName)
|
||||
{
|
||||
Q_UNUSED(newName);
|
||||
}
|
||||
|
||||
bool TaskFile::open(const QString &fileName)
|
||||
{
|
||||
m_fileName = fileName;
|
||||
return TaskList::TaskListPlugin::instance()->loadFile(m_context, m_fileName);
|
||||
}
|
||||
|
||||
ProjectExplorer::Project *TaskFile::context() const
|
||||
{
|
||||
return m_context;
|
||||
}
|
||||
|
||||
void TaskFile::setContext(ProjectExplorer::Project *context)
|
||||
{
|
||||
m_context = context;
|
||||
}
|
||||
|
||||
76
src/plugins/tasklist/taskfile.h
Normal file
76
src/plugins/tasklist/taskfile.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file 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 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.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef TASKFILE_H
|
||||
#define TASKFILE_H
|
||||
|
||||
#include <coreplugin/ifile.h>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class Project;
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
namespace TaskList {
|
||||
namespace Internal {
|
||||
|
||||
class TaskFile : public Core::IFile
|
||||
{
|
||||
public:
|
||||
TaskFile(QObject *parent);
|
||||
~TaskFile();
|
||||
|
||||
bool save(const QString &fileName = QString());
|
||||
QString fileName() const;
|
||||
|
||||
QString defaultPath() const;
|
||||
QString suggestedFileName() const;
|
||||
QString mimeType() const;
|
||||
|
||||
bool isModified() const;
|
||||
bool isReadOnly() const;
|
||||
bool isSaveAsAllowed() const;
|
||||
|
||||
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
|
||||
void reload(ReloadFlag flag, ChangeType type);
|
||||
void rename(const QString &newName);
|
||||
|
||||
bool open(const QString &fileName);
|
||||
|
||||
ProjectExplorer::Project *context() const;
|
||||
void setContext(ProjectExplorer::Project *context);
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
ProjectExplorer::Project *m_context;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace TaskList
|
||||
|
||||
#endif // TASKFILE_H
|
||||
@@ -29,13 +29,20 @@
|
||||
|
||||
#include "taskfilefactory.h"
|
||||
|
||||
#include "tasklistmanager.h"
|
||||
#include "taskfile.h"
|
||||
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/filemanager.h>
|
||||
|
||||
using namespace TaskList::Internal;
|
||||
|
||||
TaskFileFactory::TaskFileFactory(TaskListManager *manager) :
|
||||
Core::IFileFactory(0),
|
||||
m_manager(manager),
|
||||
// --------------------------------------------------------------------------
|
||||
// TaskFileFactory
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
TaskFileFactory::TaskFileFactory(QObject * parent) :
|
||||
Core::IFileFactory(parent),
|
||||
m_mimeTypes(QStringList() << QLatin1String("text/x-tasklist"))
|
||||
{ }
|
||||
|
||||
@@ -59,7 +66,32 @@ QString TaskFileFactory::displayName() const
|
||||
|
||||
Core::IFile *TaskFileFactory::open(const QString &fileName)
|
||||
{
|
||||
Core::IFile *file = 0;
|
||||
m_manager->setTaskFile(fileName);
|
||||
ProjectExplorer::Project * context =
|
||||
ProjectExplorer::ProjectExplorerPlugin::instance()->currentProject();
|
||||
return open(context, fileName);
|
||||
}
|
||||
|
||||
Core::IFile *TaskFileFactory::open(ProjectExplorer::Project *context, const QString &fileName)
|
||||
{
|
||||
TaskFile *file = new TaskFile(this);
|
||||
file->setContext(context);
|
||||
|
||||
if (!file->open(fileName)) {
|
||||
delete file;
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_openFiles.append(file);
|
||||
|
||||
// Register with filemanager:
|
||||
Core::ICore::instance()->fileManager()->addFile(file);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
void TaskFileFactory::closeAllFiles()
|
||||
{
|
||||
foreach(Core::IFile *file, m_openFiles)
|
||||
file->deleteLater();
|
||||
m_openFiles.clear();
|
||||
}
|
||||
|
||||
@@ -32,18 +32,22 @@
|
||||
|
||||
#include <coreplugin/ifilefactory.h>
|
||||
|
||||
#include <coreplugin/ifile.h>
|
||||
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class Project;
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
namespace TaskList {
|
||||
namespace Internal {
|
||||
|
||||
class TaskListManager;
|
||||
|
||||
class TaskFileFactory : public Core::IFileFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TaskFileFactory(TaskListManager *manager);
|
||||
TaskFileFactory(QObject *parent = 0);
|
||||
~TaskFileFactory();
|
||||
|
||||
QStringList mimeTypes() const;
|
||||
@@ -52,10 +56,13 @@ public:
|
||||
QString displayName() const;
|
||||
|
||||
Core::IFile *open(const QString &fileName);
|
||||
Core::IFile *open(ProjectExplorer::Project *context, const QString &fileName);
|
||||
|
||||
void closeAllFiles();
|
||||
|
||||
private:
|
||||
TaskListManager * m_manager;
|
||||
QStringList m_mimeTypes;
|
||||
QList<Core::IFile *> m_openFiles;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -6,12 +6,16 @@ include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(../../plugins/projectexplorer/projectexplorer.pri)
|
||||
|
||||
HEADERS += tasklistplugin.h \
|
||||
tasklist_export.h \
|
||||
tasklistconstants.h \
|
||||
stopmonitoringhandler.h \
|
||||
taskfile.h \
|
||||
taskfilefactory.h \
|
||||
tasklistmanager.h
|
||||
|
||||
SOURCES += tasklistplugin.cpp \
|
||||
stopmonitoringhandler.cpp \
|
||||
taskfile.cpp \
|
||||
taskfilefactory.cpp \
|
||||
tasklistmanager.cpp
|
||||
|
||||
RESOURCES += tasklist.qrc
|
||||
|
||||
|
||||
41
src/plugins/tasklist/tasklist_export.h
Normal file
41
src/plugins/tasklist/tasklist_export.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file 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 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.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef TASKLIST_TASKLIST_EXPORT_H
|
||||
#define TASKLIST_TASKLIST_EXPORT_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(TASKLIST_LIBRARY)
|
||||
# define TASKLIST_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define TASKLIST_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // TASKLIST_TASKLIST_EXPORT_H
|
||||
41
src/plugins/tasklist/tasklistconstants.h
Normal file
41
src/plugins/tasklist/tasklistconstants.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file 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 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.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef TASKLIST_TASKLISTCONSTANTS_H
|
||||
#define TASKLIST_TASKLISTCONSTANTS_H
|
||||
|
||||
namespace TaskList {
|
||||
namespace Constants {
|
||||
|
||||
const char * const TASKLISTTASK_ID = "TaskList.TaskListTaskId";
|
||||
|
||||
} // namespace Constants
|
||||
} // namespace TaskList
|
||||
|
||||
#endif // TASKLIST_TASKLISTCONSTANTS_H
|
||||
@@ -1,150 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file 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 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.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "tasklistmanager.h"
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <projectexplorer/taskhub.h>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QFile>
|
||||
|
||||
namespace {
|
||||
const char * const TASKLIST_ID = "TaskList.ListId";
|
||||
|
||||
ProjectExplorer::Task::TaskType typeFrom(const QString &taskType)
|
||||
{
|
||||
QString type = taskType.toLower();
|
||||
if (type.startsWith("warn"))
|
||||
return ProjectExplorer::Task::Warning;
|
||||
else if (type.startsWith("err"))
|
||||
return ProjectExplorer::Task::Error;
|
||||
return ProjectExplorer::Task::Unknown;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
using namespace TaskList::Internal;
|
||||
|
||||
TaskListManager::TaskListManager(QObject *parent) :
|
||||
QObject(parent),
|
||||
m_hub(0)
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
m_hub = pm->getObject<ProjectExplorer::TaskHub>();
|
||||
m_hub->addCategory(QLatin1String(TASKLIST_ID), tr("My tasks"));
|
||||
}
|
||||
|
||||
TaskListManager::~TaskListManager()
|
||||
{ }
|
||||
|
||||
void TaskListManager::setTaskFile(const QString &name)
|
||||
{
|
||||
m_hub->clearTasks(QLatin1String(TASKLIST_ID));
|
||||
parseTaskFile(name);
|
||||
}
|
||||
|
||||
void TaskListManager::parseTaskFile(const QString &name)
|
||||
{
|
||||
QFile tf(name);
|
||||
if (!tf.open(QIODevice::ReadOnly))
|
||||
return;
|
||||
while (!tf.atEnd())
|
||||
{
|
||||
QStringList chunks = parseRawLine(tf.readLine());
|
||||
if (chunks.isEmpty())
|
||||
continue;
|
||||
|
||||
QString description;
|
||||
QString file;
|
||||
ProjectExplorer::Task::TaskType type = ProjectExplorer::Task::Unknown;
|
||||
int line = -1;
|
||||
|
||||
if (chunks.count() == 1) {
|
||||
description = chunks.at(0);
|
||||
} else if (chunks.count() == 2) {
|
||||
type = typeFrom(chunks.at(0));
|
||||
description = chunks.at(1);
|
||||
} else if (chunks.count() == 3) {
|
||||
file = chunks.at(0);
|
||||
type = typeFrom(chunks.at(1));
|
||||
description = chunks.at(2);
|
||||
} else if (chunks.count() >= 4) {
|
||||
file = chunks.at(0);
|
||||
bool ok;
|
||||
line = chunks.at(1).toInt(&ok);
|
||||
if (!ok)
|
||||
line = -1;
|
||||
type = typeFrom(chunks.at(2));
|
||||
description = chunks.at(3);
|
||||
}
|
||||
m_hub->addTask(ProjectExplorer::Task(type, description, file, line, QLatin1String(TASKLIST_ID)));
|
||||
}
|
||||
}
|
||||
|
||||
QStringList TaskListManager::parseRawLine(const QByteArray &raw)
|
||||
{
|
||||
QStringList result;
|
||||
QString line = QString::fromUtf8(raw.constData());
|
||||
if (line.startsWith(QChar('#')))
|
||||
return result;
|
||||
|
||||
result = line.split(QChar('\t'));
|
||||
for (int i = 0; i < result.count(); ++i)
|
||||
result[i] = unescape(result.at(i));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QString TaskListManager::unescape(const QString &input) const
|
||||
{
|
||||
QString result;
|
||||
for (int i = 0; i < input.count(); ++i) {
|
||||
if (input.at(i) == QChar('\\')) {
|
||||
if (i == input.count() - 1)
|
||||
continue;
|
||||
if (input.at(i + 1) == QChar('n')) {
|
||||
result.append(QChar('\n'));
|
||||
++i;
|
||||
continue;
|
||||
} else if (input.at(i + 1) == QChar('t')) {
|
||||
result.append(QChar('\t'));
|
||||
++i;
|
||||
continue;
|
||||
} else if (input.at(i + 1) == QChar('\\')) {
|
||||
result.append(QChar('\\'));
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
result.append(input.at(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -29,38 +29,202 @@
|
||||
|
||||
#include "tasklistplugin.h"
|
||||
|
||||
#include "stopmonitoringhandler.h"
|
||||
#include "taskfile.h"
|
||||
#include "taskfilefactory.h"
|
||||
#include "tasklistmanager.h"
|
||||
#include "tasklistconstants.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/task.h>
|
||||
#include <projectexplorer/taskhub.h>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
using namespace TaskList::Internal;
|
||||
namespace {
|
||||
|
||||
TaskListPlugin::TaskListPlugin()
|
||||
{ }
|
||||
ProjectExplorer::Task::TaskType typeFrom(const QString &typeName)
|
||||
{
|
||||
ProjectExplorer::Task::TaskType type = ProjectExplorer::Task::Unknown;
|
||||
QString tmp = typeName.toLower();
|
||||
if (tmp.startsWith(QLatin1String("warn")))
|
||||
type = ProjectExplorer::Task::Warning;
|
||||
else if (tmp.startsWith(QLatin1String("err")))
|
||||
type = ProjectExplorer::Task::Error;
|
||||
return type;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
using namespace TaskList;
|
||||
|
||||
TaskListPlugin *TaskListPlugin::m_instance = 0;
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// TaskListPluginPrivate
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
class Internal::TaskListPluginPrivate {
|
||||
public:
|
||||
bool parseTaskFile(ProjectExplorer::Project *context, const QString &name)
|
||||
{
|
||||
QFile tf(name);
|
||||
if (!tf.open(QIODevice::ReadOnly))
|
||||
return false;
|
||||
|
||||
while (!tf.atEnd())
|
||||
{
|
||||
QStringList chunks = parseRawLine(tf.readLine());
|
||||
if (chunks.isEmpty())
|
||||
continue;
|
||||
|
||||
QString description;
|
||||
QString file;
|
||||
ProjectExplorer::Task::TaskType type = ProjectExplorer::Task::Unknown;
|
||||
int line = -1;
|
||||
|
||||
if (chunks.count() == 1) {
|
||||
description = chunks.at(0);
|
||||
} else if (chunks.count() == 2) {
|
||||
type = typeFrom(chunks.at(0));
|
||||
description = chunks.at(1);
|
||||
} else if (chunks.count() == 3) {
|
||||
file = chunks.at(0);
|
||||
type = typeFrom(chunks.at(1));
|
||||
description = chunks.at(2);
|
||||
} else if (chunks.count() >= 4) {
|
||||
file = chunks.at(0);
|
||||
bool ok;
|
||||
line = chunks.at(1).toInt(&ok);
|
||||
if (!ok)
|
||||
line = -1;
|
||||
type = typeFrom(chunks.at(2));
|
||||
description = chunks.at(3);
|
||||
}
|
||||
if (!file.isEmpty()) {
|
||||
QFileInfo fi(file);
|
||||
if (fi.isRelative() && context) {
|
||||
QString fullPath = context->projectDirectory() + '/' + file;
|
||||
fi.setFile(fullPath);
|
||||
file = fi.absoluteFilePath();
|
||||
}
|
||||
}
|
||||
|
||||
hub->addTask(ProjectExplorer::Task(type, description, file, line, QLatin1String(Constants::TASKLISTTASK_ID)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList parseRawLine(const QByteArray &raw)
|
||||
{
|
||||
QStringList result;
|
||||
QString line = QString::fromUtf8(raw.constData());
|
||||
if (line.startsWith(QChar('#')))
|
||||
return result;
|
||||
|
||||
result = line.split(QChar('\t'));
|
||||
for (int i = 0; i < result.count(); ++i)
|
||||
result[i] = unescape(result.at(i));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QString unescape(const QString &input) const
|
||||
{
|
||||
QString result;
|
||||
for (int i = 0; i < input.count(); ++i) {
|
||||
if (input.at(i) == QChar('\\')) {
|
||||
if (i == input.count() - 1)
|
||||
continue;
|
||||
if (input.at(i + 1) == QChar('n')) {
|
||||
result.append(QChar('\n'));
|
||||
++i;
|
||||
continue;
|
||||
} else if (input.at(i + 1) == QChar('t')) {
|
||||
result.append(QChar('\t'));
|
||||
++i;
|
||||
continue;
|
||||
} else if (input.at(i + 1) == QChar('\\')) {
|
||||
result.append(QChar('\\'));
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
result.append(input.at(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ProjectExplorer::TaskHub *hub;
|
||||
TaskFileFactory *fileFactory;
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// TaskListPlugin
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
TaskListPlugin::TaskListPlugin() :
|
||||
d(new Internal::TaskListPluginPrivate)
|
||||
{
|
||||
m_instance = this;
|
||||
}
|
||||
|
||||
TaskListPlugin::~TaskListPlugin()
|
||||
{ }
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
TaskListPlugin *TaskListPlugin::instance()
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
{
|
||||
Q_UNUSED(arguments)
|
||||
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
d->hub = pm->getObject<ProjectExplorer::TaskHub>();
|
||||
|
||||
//: Category under which tasklist tasks are listed in build issues view
|
||||
d->hub->addCategory(QLatin1String(Constants::TASKLISTTASK_ID), tr("My tasks"));
|
||||
|
||||
Core::ICore *core = Core::ICore::instance();
|
||||
if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":tasklist/TaskList.mimetypes.xml"), errorMessage))
|
||||
return false;
|
||||
|
||||
TaskListManager * manager = new TaskListManager(this);
|
||||
addAutoReleasedObject(new TaskFileFactory(manager));
|
||||
d->fileFactory = new Internal::TaskFileFactory(this);
|
||||
addAutoReleasedObject(d->fileFactory);
|
||||
addAutoReleasedObject(new Internal::StopMonitoringHandler);
|
||||
return true;
|
||||
}
|
||||
|
||||
void TaskListPlugin::extensionsInitialized()
|
||||
{ }
|
||||
|
||||
bool TaskListPlugin::loadFile(ProjectExplorer::Project *context, const QString &fileName)
|
||||
{
|
||||
clearTasks();
|
||||
return d->parseTaskFile(context, fileName);
|
||||
}
|
||||
|
||||
bool TaskListPlugin::monitorFile(ProjectExplorer::Project *context, const QString &fileName)
|
||||
{
|
||||
return d->fileFactory->open(context, fileName);
|
||||
}
|
||||
|
||||
void TaskListPlugin::stopMonitoring()
|
||||
{
|
||||
d->fileFactory->closeAllFiles();
|
||||
}
|
||||
|
||||
void TaskListPlugin::clearTasks()
|
||||
{
|
||||
d->hub->clearTasks(QLatin1String(Constants::TASKLISTTASK_ID));
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN(TaskListPlugin)
|
||||
|
||||
@@ -32,8 +32,14 @@
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class Project;
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
namespace TaskList {
|
||||
namespace Internal {
|
||||
class TaskListPluginPrivate;
|
||||
} // namespace
|
||||
|
||||
class TaskListPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
@@ -43,12 +49,23 @@ public:
|
||||
TaskListPlugin();
|
||||
~TaskListPlugin();
|
||||
|
||||
static TaskListPlugin *instance();
|
||||
|
||||
bool initialize(const QStringList &arguments, QString *errorMessage);
|
||||
|
||||
void extensionsInitialized();
|
||||
|
||||
bool loadFile(ProjectExplorer::Project *context, const QString &fileName);
|
||||
bool monitorFile(ProjectExplorer::Project *context, const QString &fileName);
|
||||
|
||||
void stopMonitoring();
|
||||
void clearTasks();
|
||||
|
||||
private:
|
||||
static TaskListPlugin *m_instance;
|
||||
Internal::TaskListPluginPrivate * const d;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace TaskList
|
||||
|
||||
#endif // TASKLISTPLUGIN_H
|
||||
|
||||
Reference in New Issue
Block a user