forked from qt-creator/qt-creator
TaskListPlugin: Adjust after changes to IDocumentFactory
Change-Id: I5c7256b581bb10ecaf9d3cd3b78b8d45dc60132b Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -54,7 +54,7 @@ void StopMonitoringHandler::handle(const ProjectExplorer::Task &task)
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(canHandle(task), return);
|
QTC_ASSERT(canHandle(task), return);
|
||||||
Q_UNUSED(task);
|
Q_UNUSED(task);
|
||||||
TaskList::TaskListPlugin::stopMonitoring();
|
TaskListPlugin::stopMonitoring();
|
||||||
}
|
}
|
||||||
|
|
||||||
QAction *StopMonitoringHandler::createAction(QObject *parent) const
|
QAction *StopMonitoringHandler::createAction(QObject *parent) const
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ bool TaskFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
|
|||||||
bool TaskFile::open(QString *errorString, const QString &fileName)
|
bool TaskFile::open(QString *errorString, const QString &fileName)
|
||||||
{
|
{
|
||||||
setFilePath(fileName);
|
setFilePath(fileName);
|
||||||
return TaskList::TaskListPlugin::loadFile(errorString, m_baseDir, fileName);
|
return TaskListPlugin::loadFile(errorString, m_baseDir, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TaskFile::baseDir() const
|
QString TaskFile::baseDir() const
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
|
||||||
** Contact: http://www.qt-project.org/legal
|
|
||||||
**
|
|
||||||
** 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 Digia. For licensing terms and
|
|
||||||
** conditions see http://qt.digia.com/licensing. For further information
|
|
||||||
** use the contact form at http://qt.digia.com/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 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.
|
|
||||||
**
|
|
||||||
** In addition, as a special exception, Digia gives you certain additional
|
|
||||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "taskfilefactory.h"
|
|
||||||
|
|
||||||
#include "taskfile.h"
|
|
||||||
|
|
||||||
#include <projectexplorer/projectexplorer.h>
|
|
||||||
#include <projectexplorer/project.h>
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
#include <coreplugin/documentmanager.h>
|
|
||||||
|
|
||||||
#include <QMessageBox>
|
|
||||||
|
|
||||||
using namespace TaskList::Internal;
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// TaskFileFactory
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
TaskFileFactory::TaskFileFactory(QObject * parent) :
|
|
||||||
Core::IDocumentFactory(parent)
|
|
||||||
{
|
|
||||||
setId("ProjectExplorer.TaskFileFactory");
|
|
||||||
setDisplayName(tr("Task file reader"));
|
|
||||||
addMimeType(QLatin1String("text/x-tasklist"));
|
|
||||||
setOpener([this](const QString &fileName) -> Core::IDocument * {
|
|
||||||
ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject();
|
|
||||||
return this->open(project ? project->projectDirectory().toString() : QString(), fileName);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::IDocument *TaskFileFactory::open(const QString &base, const QString &fileName)
|
|
||||||
{
|
|
||||||
foreach (TaskFile *doc, m_openFiles) {
|
|
||||||
if (doc->filePath() == fileName)
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
TaskFile *file = new TaskFile(this);
|
|
||||||
file->setBaseDir(base);
|
|
||||||
|
|
||||||
QString errorString;
|
|
||||||
if (!file->open(&errorString, fileName)) {
|
|
||||||
QMessageBox::critical(Core::ICore::mainWindow(), tr("File Error"), errorString);
|
|
||||||
delete file;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_openFiles.append(file);
|
|
||||||
|
|
||||||
// Register with filemanager:
|
|
||||||
Core::DocumentManager::addDocument(file);
|
|
||||||
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TaskFileFactory::closeAllFiles()
|
|
||||||
{
|
|
||||||
foreach (TaskFile *document, m_openFiles)
|
|
||||||
document->deleteLater();
|
|
||||||
m_openFiles.clear();
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
|
||||||
** Contact: http://www.qt-project.org/legal
|
|
||||||
**
|
|
||||||
** 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 Digia. For licensing terms and
|
|
||||||
** conditions see http://qt.digia.com/licensing. For further information
|
|
||||||
** use the contact form at http://qt.digia.com/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 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.
|
|
||||||
**
|
|
||||||
** In addition, as a special exception, Digia gives you certain additional
|
|
||||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef TASKFILEFACTORY_H
|
|
||||||
#define TASKFILEFACTORY_H
|
|
||||||
|
|
||||||
#include <coreplugin/idocumentfactory.h>
|
|
||||||
#include <coreplugin/idocument.h>
|
|
||||||
|
|
||||||
namespace ProjectExplorer { class Project; }
|
|
||||||
|
|
||||||
namespace TaskList {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class TaskFile;
|
|
||||||
|
|
||||||
class TaskFileFactory : public Core::IDocumentFactory
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
TaskFileFactory(QObject *parent = 0);
|
|
||||||
|
|
||||||
Core::IDocument *open(const QString &base, const QString &fileName);
|
|
||||||
|
|
||||||
void closeAllFiles();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QList<TaskFile *> m_openFiles;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace TaskList
|
|
||||||
|
|
||||||
#endif // TASKFILEFACTORY_H
|
|
||||||
@@ -4,11 +4,9 @@ HEADERS += tasklistplugin.h \
|
|||||||
tasklistconstants.h \
|
tasklistconstants.h \
|
||||||
stopmonitoringhandler.h \
|
stopmonitoringhandler.h \
|
||||||
taskfile.h \
|
taskfile.h \
|
||||||
taskfilefactory.h \
|
|
||||||
|
|
||||||
SOURCES += tasklistplugin.cpp \
|
SOURCES += tasklistplugin.cpp \
|
||||||
stopmonitoringhandler.cpp \
|
stopmonitoringhandler.cpp \
|
||||||
taskfile.cpp \
|
taskfile.cpp \
|
||||||
taskfilefactory.cpp \
|
|
||||||
|
|
||||||
RESOURCES += tasklist.qrc
|
RESOURCES += tasklist.qrc
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ QtcPlugin {
|
|||||||
"stopmonitoringhandler.h",
|
"stopmonitoringhandler.h",
|
||||||
"taskfile.cpp",
|
"taskfile.cpp",
|
||||||
"taskfile.h",
|
"taskfile.h",
|
||||||
"taskfilefactory.cpp",
|
|
||||||
"taskfilefactory.h",
|
|
||||||
"tasklist.qrc",
|
"tasklist.qrc",
|
||||||
"tasklistconstants.h",
|
"tasklistconstants.h",
|
||||||
"tasklistplugin.cpp",
|
"tasklistplugin.cpp",
|
||||||
|
|||||||
@@ -31,10 +31,11 @@
|
|||||||
|
|
||||||
#include "stopmonitoringhandler.h"
|
#include "stopmonitoringhandler.h"
|
||||||
#include "taskfile.h"
|
#include "taskfile.h"
|
||||||
#include "taskfilefactory.h"
|
|
||||||
#include "tasklistconstants.h"
|
#include "tasklistconstants.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/idocumentfactory.h>
|
||||||
|
#include <coreplugin/documentmanager.h>
|
||||||
#include <coreplugin/mimedatabase.h>
|
#include <coreplugin/mimedatabase.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
@@ -43,16 +44,20 @@
|
|||||||
#include <projectexplorer/taskhub.h>
|
#include <projectexplorer/taskhub.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace TaskList::Internal;
|
|
||||||
|
|
||||||
static const char SESSION_FILE_KEY[] = "TaskList.File";
|
static const char SESSION_FILE_KEY[] = "TaskList.File";
|
||||||
static const char SESSION_BASE_KEY[] = "TaskList.BaseDir";
|
static const char SESSION_BASE_KEY[] = "TaskList.BaseDir";
|
||||||
|
|
||||||
namespace TaskList {
|
namespace TaskList {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
static TaskListPlugin *m_instance;
|
||||||
|
|
||||||
static Task::TaskType typeFrom(const QString &typeName)
|
static Task::TaskType typeFrom(const QString &typeName)
|
||||||
{
|
{
|
||||||
@@ -160,7 +165,35 @@ static bool parseTaskFile(QString *errorString, const QString &base, const QStri
|
|||||||
// TaskListPlugin
|
// TaskListPlugin
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
static TaskFileFactory *m_fileFactory = 0;
|
Core::IDocument *TaskListPlugin::openTasks(const QString &base, const QString &fileName)
|
||||||
|
{
|
||||||
|
foreach (TaskFile *doc, m_openFiles) {
|
||||||
|
if (doc->filePath() == fileName)
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskFile *file = new TaskFile(this);
|
||||||
|
file->setBaseDir(base);
|
||||||
|
|
||||||
|
QString errorString;
|
||||||
|
if (!file->open(&errorString, fileName)) {
|
||||||
|
QMessageBox::critical(Core::ICore::mainWindow(), tr("File Error"), errorString);
|
||||||
|
delete file;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_openFiles.append(file);
|
||||||
|
|
||||||
|
// Register with filemanager:
|
||||||
|
Core::DocumentManager::addDocument(file);
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskListPlugin::TaskListPlugin()
|
||||||
|
{
|
||||||
|
m_instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||||
{
|
{
|
||||||
@@ -172,7 +205,15 @@ bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMess
|
|||||||
if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":tasklist/TaskList.mimetypes.xml"), errorMessage))
|
if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":tasklist/TaskList.mimetypes.xml"), errorMessage))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_fileFactory = new TaskFileFactory(this);
|
m_fileFactory = new IDocumentFactory;
|
||||||
|
m_fileFactory->setId("ProjectExplorer.TaskFileFactory");
|
||||||
|
m_fileFactory->setDisplayName(tr("Task file reader"));
|
||||||
|
m_fileFactory->addMimeType(QLatin1String("text/x-tasklist"));
|
||||||
|
m_fileFactory->setOpener([this](const QString &fileName) -> IDocument * {
|
||||||
|
ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject();
|
||||||
|
return this->openTasks(project ? project->projectDirectory().toString() : QString(), fileName);
|
||||||
|
});
|
||||||
|
|
||||||
addAutoReleasedObject(m_fileFactory);
|
addAutoReleasedObject(m_fileFactory);
|
||||||
addAutoReleasedObject(new StopMonitoringHandler);
|
addAutoReleasedObject(new StopMonitoringHandler);
|
||||||
|
|
||||||
@@ -202,7 +243,9 @@ void TaskListPlugin::stopMonitoring()
|
|||||||
SessionManager::setValue(QLatin1String(SESSION_BASE_KEY), QString());
|
SessionManager::setValue(QLatin1String(SESSION_BASE_KEY), QString());
|
||||||
SessionManager::setValue(QLatin1String(SESSION_FILE_KEY), QString());
|
SessionManager::setValue(QLatin1String(SESSION_FILE_KEY), QString());
|
||||||
|
|
||||||
m_fileFactory->closeAllFiles();
|
foreach (TaskFile *document, m_instance->m_openFiles)
|
||||||
|
document->deleteLater();
|
||||||
|
m_instance->m_openFiles.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskListPlugin::clearTasks()
|
void TaskListPlugin::clearTasks()
|
||||||
@@ -215,9 +258,10 @@ void TaskListPlugin::loadDataFromSession()
|
|||||||
const QString fileName = SessionManager::value(QLatin1String(SESSION_FILE_KEY)).toString();
|
const QString fileName = SessionManager::value(QLatin1String(SESSION_FILE_KEY)).toString();
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
m_fileFactory->open(SessionManager::value(QLatin1String(SESSION_BASE_KEY)).toString(), fileName);
|
openTasks(SessionManager::value(QLatin1String(SESSION_BASE_KEY)).toString(), fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
} // namespace TaskList
|
} // namespace TaskList
|
||||||
|
|
||||||
Q_EXPORT_PLUGIN(TaskList::TaskListPlugin)
|
Q_EXPORT_PLUGIN(TaskList::Internal::TaskListPlugin)
|
||||||
|
|||||||
@@ -30,11 +30,13 @@
|
|||||||
#ifndef TASKLISTPLUGIN_H
|
#ifndef TASKLISTPLUGIN_H
|
||||||
#define TASKLISTPLUGIN_H
|
#define TASKLISTPLUGIN_H
|
||||||
|
|
||||||
|
#include <coreplugin/idocumentfactory.h>
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
namespace ProjectExplorer { class Project; }
|
|
||||||
|
|
||||||
namespace TaskList {
|
namespace TaskList {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class TaskFile;
|
||||||
|
|
||||||
class TaskListPlugin : public ExtensionSystem::IPlugin
|
class TaskListPlugin : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
@@ -42,6 +44,8 @@ class TaskListPlugin : public ExtensionSystem::IPlugin
|
|||||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "TaskList.json")
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "TaskList.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
TaskListPlugin();
|
||||||
|
|
||||||
bool initialize(const QStringList &arguments, QString *errorMessage);
|
bool initialize(const QStringList &arguments, QString *errorMessage);
|
||||||
void extensionsInitialized() {}
|
void extensionsInitialized() {}
|
||||||
|
|
||||||
@@ -50,10 +54,17 @@ public:
|
|||||||
static void stopMonitoring();
|
static void stopMonitoring();
|
||||||
static void clearTasks();
|
static void clearTasks();
|
||||||
|
|
||||||
|
Core::IDocument *openTasks(const QString &base, const QString &fileName);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void loadDataFromSession();
|
void loadDataFromSession();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Core::IDocumentFactory *m_fileFactory;
|
||||||
|
QList<TaskFile *> m_openFiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
} // namespace TaskList
|
} // namespace TaskList
|
||||||
|
|
||||||
#endif // TASKLISTPLUGIN_H
|
#endif // TASKLISTPLUGIN_H
|
||||||
|
|||||||
Reference in New Issue
Block a user