diff options
author | hjk <hjk121@nokiamail.com> | 2014-06-27 23:42:28 +0200 |
---|---|---|
committer | hjk <hjk121@nokiamail.com> | 2014-07-08 12:51:21 +0200 |
commit | 066ea5ac5847a53c35967ad4741185aa0f4ad12b (patch) | |
tree | e3fe7ec89715a916ef9ae67bce9bbd318b77d62b /src/plugins/tasklist | |
parent | 382b1d43eb87cbda882ed077dc21df2480b629f6 (diff) | |
download | qt-creator-066ea5ac5847a53c35967ad4741185aa0f4ad12b.tar.gz |
TaskListPlugin: Adjust after changes to IDocumentFactory
Change-Id: I5c7256b581bb10ecaf9d3cd3b78b8d45dc60132b
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
Diffstat (limited to 'src/plugins/tasklist')
-rw-r--r-- | src/plugins/tasklist/stopmonitoringhandler.cpp | 2 | ||||
-rw-r--r-- | src/plugins/tasklist/taskfile.cpp | 2 | ||||
-rw-r--r-- | src/plugins/tasklist/taskfilefactory.cpp | 89 | ||||
-rw-r--r-- | src/plugins/tasklist/taskfilefactory.h | 61 | ||||
-rw-r--r-- | src/plugins/tasklist/tasklist.pro | 2 | ||||
-rw-r--r-- | src/plugins/tasklist/tasklist.qbs | 2 | ||||
-rw-r--r-- | src/plugins/tasklist/tasklistplugin.cpp | 58 | ||||
-rw-r--r-- | src/plugins/tasklist/tasklistplugin.h | 15 |
8 files changed, 66 insertions, 165 deletions
diff --git a/src/plugins/tasklist/stopmonitoringhandler.cpp b/src/plugins/tasklist/stopmonitoringhandler.cpp index 0b5cd6b8dc..a4a09c8a3e 100644 --- a/src/plugins/tasklist/stopmonitoringhandler.cpp +++ b/src/plugins/tasklist/stopmonitoringhandler.cpp @@ -54,7 +54,7 @@ void StopMonitoringHandler::handle(const ProjectExplorer::Task &task) { QTC_ASSERT(canHandle(task), return); Q_UNUSED(task); - TaskList::TaskListPlugin::stopMonitoring(); + TaskListPlugin::stopMonitoring(); } QAction *StopMonitoringHandler::createAction(QObject *parent) const diff --git a/src/plugins/tasklist/taskfile.cpp b/src/plugins/tasklist/taskfile.cpp index fa695c5e2a..8b105e81fc 100644 --- a/src/plugins/tasklist/taskfile.cpp +++ b/src/plugins/tasklist/taskfile.cpp @@ -97,7 +97,7 @@ bool TaskFile::reload(QString *errorString, ReloadFlag flag, ChangeType type) bool TaskFile::open(QString *errorString, const QString &fileName) { setFilePath(fileName); - return TaskList::TaskListPlugin::loadFile(errorString, m_baseDir, fileName); + return TaskListPlugin::loadFile(errorString, m_baseDir, fileName); } QString TaskFile::baseDir() const diff --git a/src/plugins/tasklist/taskfilefactory.cpp b/src/plugins/tasklist/taskfilefactory.cpp deleted file mode 100644 index f8aea9f034..0000000000 --- a/src/plugins/tasklist/taskfilefactory.cpp +++ /dev/null @@ -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(); -} diff --git a/src/plugins/tasklist/taskfilefactory.h b/src/plugins/tasklist/taskfilefactory.h deleted file mode 100644 index 894f49f5fa..0000000000 --- a/src/plugins/tasklist/taskfilefactory.h +++ /dev/null @@ -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 diff --git a/src/plugins/tasklist/tasklist.pro b/src/plugins/tasklist/tasklist.pro index 29696e9882..e842884f66 100644 --- a/src/plugins/tasklist/tasklist.pro +++ b/src/plugins/tasklist/tasklist.pro @@ -4,11 +4,9 @@ HEADERS += tasklistplugin.h \ tasklistconstants.h \ stopmonitoringhandler.h \ taskfile.h \ - taskfilefactory.h \ SOURCES += tasklistplugin.cpp \ stopmonitoringhandler.cpp \ taskfile.cpp \ - taskfilefactory.cpp \ RESOURCES += tasklist.qrc diff --git a/src/plugins/tasklist/tasklist.qbs b/src/plugins/tasklist/tasklist.qbs index b00c1e7505..8b89df02d0 100644 --- a/src/plugins/tasklist/tasklist.qbs +++ b/src/plugins/tasklist/tasklist.qbs @@ -16,8 +16,6 @@ QtcPlugin { "stopmonitoringhandler.h", "taskfile.cpp", "taskfile.h", - "taskfilefactory.cpp", - "taskfilefactory.h", "tasklist.qrc", "tasklistconstants.h", "tasklistplugin.cpp", diff --git a/src/plugins/tasklist/tasklistplugin.cpp b/src/plugins/tasklist/tasklistplugin.cpp index 8f8c81e7ad..d8c28177f8 100644 --- a/src/plugins/tasklist/tasklistplugin.cpp +++ b/src/plugins/tasklist/tasklistplugin.cpp @@ -31,10 +31,11 @@ #include "stopmonitoringhandler.h" #include "taskfile.h" -#include "taskfilefactory.h" #include "tasklistconstants.h" #include <coreplugin/icore.h> +#include <coreplugin/idocumentfactory.h> +#include <coreplugin/documentmanager.h> #include <coreplugin/mimedatabase.h> #include <projectexplorer/projectexplorer.h> #include <projectexplorer/project.h> @@ -43,16 +44,20 @@ #include <projectexplorer/taskhub.h> #include <QDir> +#include <QMessageBox> #include <QStringList> #include <QtPlugin> +using namespace Core; using namespace ProjectExplorer; -using namespace TaskList::Internal; static const char SESSION_FILE_KEY[] = "TaskList.File"; static const char SESSION_BASE_KEY[] = "TaskList.BaseDir"; namespace TaskList { +namespace Internal { + +static TaskListPlugin *m_instance; static Task::TaskType typeFrom(const QString &typeName) { @@ -160,7 +165,35 @@ static bool parseTaskFile(QString *errorString, const QString &base, const QStri // 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) { @@ -172,7 +205,15 @@ bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMess if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":tasklist/TaskList.mimetypes.xml"), errorMessage)) 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(new StopMonitoringHandler); @@ -202,7 +243,9 @@ void TaskListPlugin::stopMonitoring() SessionManager::setValue(QLatin1String(SESSION_BASE_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() @@ -215,9 +258,10 @@ void TaskListPlugin::loadDataFromSession() const QString fileName = SessionManager::value(QLatin1String(SESSION_FILE_KEY)).toString(); if (fileName.isEmpty()) 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 -Q_EXPORT_PLUGIN(TaskList::TaskListPlugin) +Q_EXPORT_PLUGIN(TaskList::Internal::TaskListPlugin) diff --git a/src/plugins/tasklist/tasklistplugin.h b/src/plugins/tasklist/tasklistplugin.h index c2f6214113..f8d0e9c555 100644 --- a/src/plugins/tasklist/tasklistplugin.h +++ b/src/plugins/tasklist/tasklistplugin.h @@ -30,11 +30,13 @@ #ifndef TASKLISTPLUGIN_H #define TASKLISTPLUGIN_H +#include <coreplugin/idocumentfactory.h> #include <extensionsystem/iplugin.h> -namespace ProjectExplorer { class Project; } - namespace TaskList { +namespace Internal { + +class TaskFile; 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") public: + TaskListPlugin(); + bool initialize(const QStringList &arguments, QString *errorMessage); void extensionsInitialized() {} @@ -50,10 +54,17 @@ public: static void stopMonitoring(); static void clearTasks(); + Core::IDocument *openTasks(const QString &base, const QString &fileName); + public slots: void loadDataFromSession(); + +private: + Core::IDocumentFactory *m_fileFactory; + QList<TaskFile *> m_openFiles; }; +} // namespace Internal } // namespace TaskList #endif // TASKLISTPLUGIN_H |