Commit 073dddf8 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

invent project file names for generated projects

too many places want a proper project file name
therefore go back to inventing one
but have some additional bool that tells if we really
loaded stuff from disk
parent 73191cdc
Pipeline #144846 passed with stage
in 3 minutes and 31 seconds
......@@ -28,6 +28,7 @@
KateProject::KateProject(QThreadPool &threadPool, KateProjectPlugin *plugin, const QString &fileName)
: m_threadPool(threadPool)
, m_plugin(plugin)
, m_fileBacked(true)
, m_fileName(QFileInfo(fileName).canonicalFilePath())
, m_baseDir(QFileInfo(fileName).canonicalPath())
{
......@@ -47,7 +48,9 @@ KateProject::KateProject(QThreadPool &threadPool, KateProjectPlugin *plugin, con
KateProject::KateProject(QThreadPool &threadPool, KateProjectPlugin *plugin, const QVariantMap &globalProject, const QString &directory)
: m_threadPool(threadPool)
, m_plugin(plugin)
, m_baseDir(directory)
, m_fileBacked(false)
, m_fileName(QDir(QDir(directory).canonicalPath()).filePath(QStringLiteral(".kateproject")))
, m_baseDir(QDir(directory).canonicalPath())
, m_globalProject(globalProject)
{
// try to load the project map, will start worker thread, too
......@@ -59,7 +62,7 @@ KateProject::~KateProject()
saveNotesDocument();
// stop watching if we have some real project file
if (!m_fileName.isEmpty()) {
if (m_fileBacked && !m_fileName.isEmpty()) {
m_plugin->fileWatcher().removePath(m_fileName);
}
}
......@@ -127,6 +130,11 @@ QJsonDocument KateProject::readJSONFile(const QString &fileName)
QVariantMap KateProject::readProjectFile() const
{
// not file back => will not work
if (!m_fileBacked) {
return QVariantMap();
}
// bail out on error
QJsonDocument project(readJSONFile(m_fileName));
if (project.isNull()) {
......@@ -182,9 +190,11 @@ bool KateProject::load(const QVariantMap &globalProject, bool force)
/**
* support out-of-source project files
* ensure we handle relative paths properly => relative to the potential invented .kateproject file name
*/
if (!globalProject[QStringLiteral("directory")].toString().isEmpty()) {
m_baseDir = QFileInfo(globalProject[QStringLiteral("directory")].toString()).canonicalFilePath();
const auto baseDir = globalProject[QStringLiteral("directory")].toString();
if (!baseDir.isEmpty()) {
m_baseDir = QFileInfo(QFileInfo(m_fileName).dir(), baseDir).canonicalFilePath();
}
/**
......
......@@ -77,6 +77,15 @@ public:
return !name().isEmpty();
}
/**
* Is this a file backed project or just generated from e.g. opening a directory or VCS?
* @return file backed project? e.g. was this read from a .kateproject file?
*/
bool isFileBacked() const
{
return m_fileBacked;
}
/**
* Try to reload a project.
* If the reload fails, e.g. because the file is not readable or corrupt, nothing will happen!
......@@ -87,7 +96,8 @@ public:
/**
* Accessor to file name.
* Non-empty if really a project from some disk file, else empty e.g. for auto generated projects from VCS.
* Even for projects generated from version control or by open directory we will create a fake name,
* as the project file name is used in many places as unique identifier for the project.
* @return file name
*/
const QString &fileName() const
......@@ -286,6 +296,11 @@ private:
*/
KateProjectPlugin *const m_plugin;
/**
* file backed project? e.g. was this read from a .kateproject file?
*/
const bool m_fileBacked;
/**
* project file name, will stay constant
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment