From 066ea5ac5847a53c35967ad4741185aa0f4ad12b Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 27 Jun 2014 23:42:28 +0200 Subject: TaskListPlugin: Adjust after changes to IDocumentFactory Change-Id: I5c7256b581bb10ecaf9d3cd3b78b8d45dc60132b Reviewed-by: Tobias Hunger --- src/plugins/tasklist/stopmonitoringhandler.cpp | 2 +- src/plugins/tasklist/taskfile.cpp | 2 +- src/plugins/tasklist/taskfilefactory.cpp | 89 -------------------------- src/plugins/tasklist/taskfilefactory.h | 61 ------------------ src/plugins/tasklist/tasklist.pro | 2 - src/plugins/tasklist/tasklist.qbs | 2 - src/plugins/tasklist/tasklistplugin.cpp | 58 +++++++++++++++-- src/plugins/tasklist/tasklistplugin.h | 15 ++++- 8 files changed, 66 insertions(+), 165 deletions(-) delete mode 100644 src/plugins/tasklist/taskfilefactory.cpp delete mode 100644 src/plugins/tasklist/taskfilefactory.h (limited to 'src/plugins/tasklist') diff --git a/src/plugins/tasklist/stopmonitoringhandler.cpp b/src/plugins/tasklist/stopmonitoringhandler.cpp index 0b5cd6b8dc3..a4a09c8a3e2 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 fa695c5e2ab..8b105e81fcf 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 f8aea9f0346..00000000000 --- 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 -#include -#include -#include - -#include - -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 894f49f5fa9..00000000000 --- 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 -#include - -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 m_openFiles; -}; - -} // namespace Internal -} // namespace TaskList - -#endif // TASKFILEFACTORY_H diff --git a/src/plugins/tasklist/tasklist.pro b/src/plugins/tasklist/tasklist.pro index 29696e98820..e842884f664 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 b00c1e7505a..8b89df02d03 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 8f8c81e7ad1..d8c28177f84 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 +#include +#include #include #include #include @@ -43,16 +44,20 @@ #include #include +#include #include #include +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 c2f62141138..f8d0e9c5551 100644 --- a/src/plugins/tasklist/tasklistplugin.h +++ b/src/plugins/tasklist/tasklistplugin.h @@ -30,11 +30,13 @@ #ifndef TASKLISTPLUGIN_H #define TASKLISTPLUGIN_H +#include #include -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 m_openFiles; }; +} // namespace Internal } // namespace TaskList #endif // TASKLISTPLUGIN_H -- cgit v1.2.3