2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-08-26 12:27:16 +02:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-08-26 12:27:16 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-08-26 12:27:16 +02: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
|
|
|
|
|
** 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.
|
2010-08-26 12:27:16 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-08-26 12:27:16 +02:00
|
|
|
|
|
|
|
|
#include "taskfilefactory.h"
|
|
|
|
|
|
2010-08-27 16:26:16 +02:00
|
|
|
#include "taskfile.h"
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2011-09-07 09:26:29 +02:00
|
|
|
#include <coreplugin/id.h>
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/documentmanager.h>
|
2010-08-26 12:27:16 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QMessageBox>
|
2011-04-04 15:24:13 +02:00
|
|
|
|
2010-08-26 12:27:16 +02:00
|
|
|
using namespace TaskList::Internal;
|
|
|
|
|
|
2010-08-27 16:26:16 +02:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// TaskFileFactory
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
TaskFileFactory::TaskFileFactory(QObject * parent) :
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::IDocumentFactory(parent),
|
2010-08-26 12:27:16 +02:00
|
|
|
m_mimeTypes(QStringList() << QLatin1String("text/x-tasklist"))
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
TaskFileFactory::~TaskFileFactory()
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
QStringList TaskFileFactory::mimeTypes() const
|
|
|
|
|
{
|
|
|
|
|
return m_mimeTypes;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-07 09:26:29 +02:00
|
|
|
Core::Id TaskFileFactory::id() const
|
2010-08-26 12:27:16 +02:00
|
|
|
{
|
2012-11-20 07:18:01 +02:00
|
|
|
return Core::Id("ProjectExplorer.TaskFileFactory");
|
2010-08-26 12:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString TaskFileFactory::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return tr("Task file reader");
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::IDocument *TaskFileFactory::open(const QString &fileName)
|
2010-08-26 12:27:16 +02:00
|
|
|
{
|
2012-01-24 18:57:39 +01:00
|
|
|
ProjectExplorer::Project *context = ProjectExplorer::ProjectExplorerPlugin::currentProject();
|
2010-08-27 16:26:16 +02:00
|
|
|
return open(context, fileName);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::IDocument *TaskFileFactory::open(ProjectExplorer::Project *context, const QString &fileName)
|
2010-08-27 16:26:16 +02:00
|
|
|
{
|
|
|
|
|
TaskFile *file = new TaskFile(this);
|
|
|
|
|
file->setContext(context);
|
|
|
|
|
|
2011-04-04 15:24:13 +02:00
|
|
|
QString errorString;
|
|
|
|
|
if (!file->open(&errorString, fileName)) {
|
2012-01-24 15:36:40 +01:00
|
|
|
QMessageBox::critical(Core::ICore::mainWindow(), tr("File Error"), errorString);
|
2010-08-27 16:26:16 +02:00
|
|
|
delete file;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_openFiles.append(file);
|
|
|
|
|
|
|
|
|
|
// Register with filemanager:
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::DocumentManager::addDocument(file);
|
2010-08-27 16:26:16 +02:00
|
|
|
|
2010-08-26 12:27:16 +02:00
|
|
|
return file;
|
|
|
|
|
}
|
2010-08-27 16:26:16 +02:00
|
|
|
|
|
|
|
|
void TaskFileFactory::closeAllFiles()
|
|
|
|
|
{
|
2012-02-14 16:43:51 +01:00
|
|
|
foreach (Core::IDocument *document, m_openFiles)
|
|
|
|
|
document->deleteLater();
|
2010-08-27 16:26:16 +02:00
|
|
|
m_openFiles.clear();
|
|
|
|
|
}
|