forked from qt-creator/qt-creator
TaskList: Fix crash
Fix crash when a tasks-file with relative paths is reloaded after its project was closed. Change-Id: I3d0b6a3b459e391a3415d765941b2685e601b19f Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -38,8 +38,7 @@ using namespace TaskList::Internal;
|
|||||||
// TaskFile
|
// TaskFile
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
TaskFile::TaskFile(QObject *parent) : Core::IDocument(parent),
|
TaskFile::TaskFile(QObject *parent) : Core::IDocument(parent)
|
||||||
m_context(0)
|
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
TaskFile::~TaskFile()
|
TaskFile::~TaskFile()
|
||||||
@@ -101,16 +100,15 @@ 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_context, fileName);
|
return TaskList::TaskListPlugin::loadFile(errorString, m_baseDir, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectExplorer::Project *TaskFile::context() const
|
QString TaskFile::baseDir() const
|
||||||
{
|
{
|
||||||
return m_context;
|
return m_baseDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskFile::setContext(ProjectExplorer::Project *context)
|
void TaskFile::setBaseDir(const QString &base)
|
||||||
{
|
{
|
||||||
m_context = context;
|
m_baseDir = base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,11 +59,11 @@ public:
|
|||||||
|
|
||||||
bool open(QString *errorString, const QString &fileName);
|
bool open(QString *errorString, const QString &fileName);
|
||||||
|
|
||||||
ProjectExplorer::Project *context() const;
|
QString baseDir() const;
|
||||||
void setContext(ProjectExplorer::Project *context);
|
void setBaseDir(const QString &base);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProjectExplorer::Project *m_context;
|
QString m_baseDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "taskfile.h"
|
#include "taskfile.h"
|
||||||
|
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
|
#include <projectexplorer/project.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/documentmanager.h>
|
#include <coreplugin/documentmanager.h>
|
||||||
|
|
||||||
@@ -53,14 +54,14 @@ TaskFileFactory::TaskFileFactory(QObject * parent) :
|
|||||||
|
|
||||||
Core::IDocument *TaskFileFactory::open(const QString &fileName)
|
Core::IDocument *TaskFileFactory::open(const QString &fileName)
|
||||||
{
|
{
|
||||||
ProjectExplorer::Project *context = ProjectExplorer::ProjectExplorerPlugin::currentProject();
|
ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject();
|
||||||
return open(context, fileName);
|
return open(project ? project->projectDirectory() : QString(), fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument *TaskFileFactory::open(ProjectExplorer::Project *context, const QString &fileName)
|
Core::IDocument *TaskFileFactory::open(const QString &base, const QString &fileName)
|
||||||
{
|
{
|
||||||
TaskFile *file = new TaskFile(this);
|
TaskFile *file = new TaskFile(this);
|
||||||
file->setContext(context);
|
file->setBaseDir(base);
|
||||||
|
|
||||||
QString errorString;
|
QString errorString;
|
||||||
if (!file->open(&errorString, fileName)) {
|
if (!file->open(&errorString, fileName)) {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public:
|
|||||||
TaskFileFactory(QObject *parent = 0);
|
TaskFileFactory(QObject *parent = 0);
|
||||||
|
|
||||||
Core::IDocument *open(const QString &fileName);
|
Core::IDocument *open(const QString &fileName);
|
||||||
Core::IDocument *open(ProjectExplorer::Project *context, const QString &fileName);
|
Core::IDocument *open(const QString &base, const QString &fileName);
|
||||||
|
|
||||||
void closeAllFiles();
|
void closeAllFiles();
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ using namespace ProjectExplorer;
|
|||||||
using namespace TaskList::Internal;
|
using namespace TaskList::Internal;
|
||||||
|
|
||||||
static const char SESSION_FILE_KEY[] = "TaskList.File";
|
static const char SESSION_FILE_KEY[] = "TaskList.File";
|
||||||
static const char SESSION_CONTEXT_KEY[] = "TaskList.Context";
|
static const char SESSION_BASE_KEY[] = "TaskList.BaseDir";
|
||||||
|
|
||||||
namespace TaskList {
|
namespace TaskList {
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ static QString unescape(const QString &input)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parseTaskFile(QString *errorString, Project *context, const QString &name)
|
static bool parseTaskFile(QString *errorString, const QString &base, const QString &name)
|
||||||
{
|
{
|
||||||
QFile tf(name);
|
QFile tf(name);
|
||||||
if (!tf.open(QIODevice::ReadOnly)) {
|
if (!tf.open(QIODevice::ReadOnly)) {
|
||||||
@@ -142,8 +142,8 @@ static bool parseTaskFile(QString *errorString, Project *context, const QString
|
|||||||
if (!file.isEmpty()) {
|
if (!file.isEmpty()) {
|
||||||
file = QDir::fromNativeSeparators(file);
|
file = QDir::fromNativeSeparators(file);
|
||||||
QFileInfo fi(file);
|
QFileInfo fi(file);
|
||||||
if (fi.isRelative() && context) {
|
if (fi.isRelative() && !base.isEmpty()) {
|
||||||
QString fullPath = context->projectDirectory() + QLatin1Char('/') + file;
|
QString fullPath = base + QLatin1Char('/') + file;
|
||||||
fi.setFile(fullPath);
|
fi.setFile(fullPath);
|
||||||
file = fi.absoluteFilePath();
|
file = fi.absoluteFilePath();
|
||||||
}
|
}
|
||||||
@@ -182,14 +182,13 @@ bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMess
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TaskListPlugin::loadFile(QString *errorString, Project *context, const QString &fileName)
|
bool TaskListPlugin::loadFile(QString *errorString, const QString &context, const QString &fileName)
|
||||||
{
|
{
|
||||||
clearTasks();
|
clearTasks();
|
||||||
|
|
||||||
bool result = parseTaskFile(errorString, context, fileName);
|
bool result = parseTaskFile(errorString, context, fileName);
|
||||||
if (result) {
|
if (result) {
|
||||||
SessionManager::setValue(QLatin1String(SESSION_CONTEXT_KEY),
|
SessionManager::setValue(QLatin1String(SESSION_BASE_KEY), context);
|
||||||
context ? context->projectFilePath() : QString());
|
|
||||||
SessionManager::setValue(QLatin1String(SESSION_FILE_KEY), fileName);
|
SessionManager::setValue(QLatin1String(SESSION_FILE_KEY), fileName);
|
||||||
} else {
|
} else {
|
||||||
stopMonitoring();
|
stopMonitoring();
|
||||||
@@ -200,7 +199,7 @@ bool TaskListPlugin::loadFile(QString *errorString, Project *context, const QStr
|
|||||||
|
|
||||||
void TaskListPlugin::stopMonitoring()
|
void TaskListPlugin::stopMonitoring()
|
||||||
{
|
{
|
||||||
SessionManager::setValue(QLatin1String(SESSION_CONTEXT_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();
|
m_fileFactory->closeAllFiles();
|
||||||
@@ -216,8 +215,7 @@ 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;
|
||||||
Project *project = SessionManager::projectForFile(SessionManager::value(QLatin1String(SESSION_CONTEXT_KEY)).toString());
|
m_fileFactory->open(SessionManager::value(QLatin1String(SESSION_BASE_KEY)).toString(), fileName);
|
||||||
m_fileFactory->open(project, fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace TaskList
|
} // namespace TaskList
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public:
|
|||||||
bool initialize(const QStringList &arguments, QString *errorMessage);
|
bool initialize(const QStringList &arguments, QString *errorMessage);
|
||||||
void extensionsInitialized() {}
|
void extensionsInitialized() {}
|
||||||
|
|
||||||
static bool loadFile(QString *errorString, ProjectExplorer::Project *context, const QString &fileName);
|
static bool loadFile(QString *errorString, const QString &context, const QString &fileName);
|
||||||
|
|
||||||
static void stopMonitoring();
|
static void stopMonitoring();
|
||||||
static void clearTasks();
|
static void clearTasks();
|
||||||
|
|||||||
Reference in New Issue
Block a user