forked from qt-creator/qt-creator
TaskList: Make relative paths relative to the tasks file
... instead of relative to the project directory. This is much more intuitive. Change-Id: I2e8224fe998f7b762425a26970d5de85909a5d47 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
6412cda77f
commit
90ab6e9b94
@@ -97,15 +97,5 @@ bool TaskFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
|
|||||||
bool TaskFile::load(QString *errorString, const Utils::FileName &fileName)
|
bool TaskFile::load(QString *errorString, const Utils::FileName &fileName)
|
||||||
{
|
{
|
||||||
setFilePath(fileName);
|
setFilePath(fileName);
|
||||||
return TaskListPlugin::loadFile(errorString, m_baseDir, fileName);
|
return TaskListPlugin::loadFile(errorString, fileName);
|
||||||
}
|
|
||||||
|
|
||||||
Utils::FileName TaskFile::baseDir() const
|
|
||||||
{
|
|
||||||
return m_baseDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TaskFile::setBaseDir(const Utils::FileName &base)
|
|
||||||
{
|
|
||||||
m_baseDir = base;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,6 @@
|
|||||||
#define TASKFILE_H
|
#define TASKFILE_H
|
||||||
|
|
||||||
#include <coreplugin/idocument.h>
|
#include <coreplugin/idocument.h>
|
||||||
#include <utils/fileutils.h>
|
|
||||||
|
|
||||||
namespace ProjectExplorer { class Project; }
|
namespace ProjectExplorer { class Project; }
|
||||||
|
|
||||||
@@ -56,12 +55,6 @@ public:
|
|||||||
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
|
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
|
||||||
|
|
||||||
bool load(QString *errorString, const Utils::FileName &fileName);
|
bool load(QString *errorString, const Utils::FileName &fileName);
|
||||||
|
|
||||||
Utils::FileName baseDir() const;
|
|
||||||
void setBaseDir(const Utils::FileName &base);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Utils::FileName m_baseDir;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -37,8 +37,6 @@
|
|||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/idocumentfactory.h>
|
#include <coreplugin/idocumentfactory.h>
|
||||||
#include <coreplugin/documentmanager.h>
|
#include <coreplugin/documentmanager.h>
|
||||||
#include <projectexplorer/projecttree.h>
|
|
||||||
#include <projectexplorer/project.h>
|
|
||||||
#include <projectexplorer/session.h>
|
#include <projectexplorer/session.h>
|
||||||
#include <projectexplorer/task.h>
|
#include <projectexplorer/task.h>
|
||||||
#include <projectexplorer/taskhub.h>
|
#include <projectexplorer/taskhub.h>
|
||||||
@@ -54,7 +52,6 @@ using namespace ProjectExplorer;
|
|||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
static const char SESSION_FILE_KEY[] = "TaskList.File";
|
static const char SESSION_FILE_KEY[] = "TaskList.File";
|
||||||
static const char SESSION_BASE_KEY[] = "TaskList.BaseDir";
|
|
||||||
|
|
||||||
namespace TaskList {
|
namespace TaskList {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -109,7 +106,7 @@ static QString unescape(const QString &input)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parseTaskFile(QString *errorString, const FileName &base, const FileName &name)
|
static bool parseTaskFile(QString *errorString, const FileName &name)
|
||||||
{
|
{
|
||||||
QFile tf(name.toString());
|
QFile tf(name.toString());
|
||||||
if (!tf.open(QIODevice::ReadOnly)) {
|
if (!tf.open(QIODevice::ReadOnly)) {
|
||||||
@@ -118,6 +115,7 @@ static bool parseTaskFile(QString *errorString, const FileName &base, const File
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FileName parentDir = name.parentDir();
|
||||||
while (!tf.atEnd()) {
|
while (!tf.atEnd()) {
|
||||||
QStringList chunks = parseRawLine(tf.readLine());
|
QStringList chunks = parseRawLine(tf.readLine());
|
||||||
if (chunks.isEmpty())
|
if (chunks.isEmpty())
|
||||||
@@ -149,8 +147,8 @@ static bool parseTaskFile(QString *errorString, const FileName &base, const File
|
|||||||
if (!file.isEmpty()) {
|
if (!file.isEmpty()) {
|
||||||
file = QDir::fromNativeSeparators(file);
|
file = QDir::fromNativeSeparators(file);
|
||||||
QFileInfo fi(file);
|
QFileInfo fi(file);
|
||||||
if (fi.isRelative() && !base.isEmpty())
|
if (fi.isRelative())
|
||||||
file = FileName(base).appendPath(file).toString();
|
file = FileName(parentDir).appendPath(file).toString();
|
||||||
}
|
}
|
||||||
description = unescape(description);
|
description = unescape(description);
|
||||||
|
|
||||||
@@ -164,7 +162,7 @@ static bool parseTaskFile(QString *errorString, const FileName &base, const File
|
|||||||
// TaskListPlugin
|
// TaskListPlugin
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
IDocument *TaskListPlugin::openTasks(const FileName &base, const FileName &fileName)
|
IDocument *TaskListPlugin::openTasks(const FileName &fileName)
|
||||||
{
|
{
|
||||||
foreach (TaskFile *doc, m_openFiles) {
|
foreach (TaskFile *doc, m_openFiles) {
|
||||||
if (doc->filePath() == fileName)
|
if (doc->filePath() == fileName)
|
||||||
@@ -172,7 +170,6 @@ IDocument *TaskListPlugin::openTasks(const FileName &base, const FileName &fileN
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto file = new TaskFile(this);
|
auto file = new TaskFile(this);
|
||||||
file->setBaseDir(base);
|
|
||||||
|
|
||||||
QString errorString;
|
QString errorString;
|
||||||
if (!file->load(&errorString, fileName)) {
|
if (!file->load(&errorString, fileName)) {
|
||||||
@@ -206,10 +203,8 @@ bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMess
|
|||||||
|
|
||||||
m_fileFactory = new IDocumentFactory;
|
m_fileFactory = new IDocumentFactory;
|
||||||
m_fileFactory->addMimeType(QLatin1String("text/x-tasklist"));
|
m_fileFactory->addMimeType(QLatin1String("text/x-tasklist"));
|
||||||
m_fileFactory->setOpener([this](const QString &fileName) -> IDocument * {
|
m_fileFactory->setOpener([this](const QString &fileName) {
|
||||||
Project *project = ProjectTree::currentProject();
|
return openTasks(FileName::fromString(fileName));
|
||||||
return this->openTasks(project ? project->projectDirectory() : FileName(),
|
|
||||||
FileName::fromString(fileName));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
addAutoReleasedObject(m_fileFactory);
|
addAutoReleasedObject(m_fileFactory);
|
||||||
@@ -221,25 +216,21 @@ bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMess
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TaskListPlugin::loadFile(QString *errorString, const FileName &context,
|
bool TaskListPlugin::loadFile(QString *errorString, const FileName &fileName)
|
||||||
const FileName &fileName)
|
|
||||||
{
|
{
|
||||||
clearTasks();
|
clearTasks();
|
||||||
|
|
||||||
bool result = parseTaskFile(errorString, context, fileName);
|
bool result = parseTaskFile(errorString, fileName);
|
||||||
if (result) {
|
if (result)
|
||||||
SessionManager::setValue(QLatin1String(SESSION_BASE_KEY), context.toString());
|
|
||||||
SessionManager::setValue(QLatin1String(SESSION_FILE_KEY), fileName.toString());
|
SessionManager::setValue(QLatin1String(SESSION_FILE_KEY), fileName.toString());
|
||||||
} else {
|
else
|
||||||
stopMonitoring();
|
stopMonitoring();
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskListPlugin::stopMonitoring()
|
void TaskListPlugin::stopMonitoring()
|
||||||
{
|
{
|
||||||
SessionManager::setValue(QLatin1String(SESSION_BASE_KEY), QString());
|
|
||||||
SessionManager::setValue(QLatin1String(SESSION_FILE_KEY), QString());
|
SessionManager::setValue(QLatin1String(SESSION_FILE_KEY), QString());
|
||||||
|
|
||||||
foreach (TaskFile *document, m_instance->m_openFiles)
|
foreach (TaskFile *document, m_instance->m_openFiles)
|
||||||
@@ -256,10 +247,8 @@ void TaskListPlugin::loadDataFromSession()
|
|||||||
{
|
{
|
||||||
const FileName fileName = FileName::fromString(
|
const FileName fileName = FileName::fromString(
|
||||||
SessionManager::value(QLatin1String(SESSION_FILE_KEY)).toString());
|
SessionManager::value(QLatin1String(SESSION_FILE_KEY)).toString());
|
||||||
if (fileName.isEmpty())
|
if (!fileName.isEmpty())
|
||||||
return;
|
openTasks(fileName);
|
||||||
openTasks(FileName::fromString(
|
|
||||||
SessionManager::value(QLatin1String(SESSION_BASE_KEY)).toString()), fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -52,13 +52,12 @@ public:
|
|||||||
bool initialize(const QStringList &arguments, QString *errorMessage);
|
bool initialize(const QStringList &arguments, QString *errorMessage);
|
||||||
void extensionsInitialized() {}
|
void extensionsInitialized() {}
|
||||||
|
|
||||||
static bool loadFile(QString *errorString, const Utils::FileName &context,
|
static bool loadFile(QString *errorString, const Utils::FileName &fileName);
|
||||||
const Utils::FileName &fileName);
|
|
||||||
|
|
||||||
static void stopMonitoring();
|
static void stopMonitoring();
|
||||||
static void clearTasks();
|
static void clearTasks();
|
||||||
|
|
||||||
Core::IDocument *openTasks(const Utils::FileName &base, const Utils::FileName &fileName);
|
Core::IDocument *openTasks(const Utils::FileName &fileName);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void loadDataFromSession();
|
void loadDataFromSession();
|
||||||
|
|||||||
Reference in New Issue
Block a user