Commit b8915171 authored by Alex Neundorf's avatar Alex Neundorf Committed by Christoph Cullmann

merge the support for out-of-source project files to the projects plugin

REVIEW: 109122
parent 45755085
......@@ -77,9 +77,10 @@ bool KateProject::load (const QString &fileName)
return false;
/**
* set new filename
* set new filename and base directory
*/
m_fileName = fileName;
m_baseDir = QFileInfo(m_fileName).canonicalPath();
/**
* trigger reload
......@@ -116,6 +117,12 @@ bool KateProject::reload (bool force)
if (globalProject["name"].toString().isEmpty())
return false;
/**
* support out-of-source project files
*/
if (!globalProject["directory"].toString().isEmpty())
m_baseDir = QFileInfo (globalProject["directory"].toString()).canonicalFilePath ();
/**
* anything changed?
* else be done without forced reload!
......@@ -136,7 +143,7 @@ bool KateProject::reload (bool force)
/**
* trigger worker to REALLY load the project model and stuff
*/
QMetaObject::invokeMethod (m_worker, "loadProject", Qt::QueuedConnection, Q_ARG(QString, m_fileName), Q_ARG(QVariantMap, m_projectMap));
QMetaObject::invokeMethod (m_worker, "loadProject", Qt::QueuedConnection, Q_ARG(QString, m_baseDir), Q_ARG(QVariantMap, m_projectMap));
/**
* done ok ;)
......
......@@ -124,6 +124,11 @@ class KateProject : public QObject
{
return m_fileName;
}
const QString baseDir () const
{
return m_baseDir;
}
/**
* Accessor to project map containing the whole project info.
......@@ -255,6 +260,11 @@ class KateProject : public QObject
*/
QString m_fileName;
/**
* base directory of the project
*/
QString m_baseDir;
/**
* project name
*/
......
......@@ -71,7 +71,7 @@ KateProjectPlugin::KateProjectPlugin (QObject* parent, const QList<QVariant>&)
* open project for working dir!
*/
projectForDir (QDir::current ());
/**
* close again
*/
......@@ -91,7 +91,7 @@ KateProjectPlugin::~KateProjectPlugin()
/**
* cleanup open projects
*/
foreach (KateProject *project, m_fileName2Project) {
foreach (KateProject *project, m_projects) {
/**
* remove path
*/
......@@ -106,7 +106,7 @@ KateProjectPlugin::~KateProjectPlugin()
/**
* cleanup list
*/
m_fileName2Project.clear ();
m_projects.clear ();
}
Kate::PluginView *KateProjectPlugin::createView( Kate::MainWindow *mainWindow )
......@@ -114,30 +114,13 @@ Kate::PluginView *KateProjectPlugin::createView( Kate::MainWindow *mainWindow )
return new KateProjectPluginView ( this, mainWindow );
}
KateProject *KateProjectPlugin::projectForFileName (const QString &fileName)
KateProject *KateProjectPlugin::createProjectForFileName (const QString &fileName)
{
/**
* canonicalize file path
*/
QString canonicalFilePath = QFileInfo (fileName).canonicalFilePath ();
/**
* abort if empty
*/
if (canonicalFilePath.isEmpty())
return 0;
/**
* first: lookup in existing projects
*/
if (m_fileName2Project.contains (canonicalFilePath))
return m_fileName2Project.value (canonicalFilePath);
/**
* else: try to load or fail
* try to load or fail
*/
KateProject *project = new KateProject ();
if (!project->load (canonicalFilePath)) {
if (!project->load (fileName)) {
delete project;
return 0;
}
......@@ -145,8 +128,8 @@ KateProject *KateProjectPlugin::projectForFileName (const QString &fileName)
/**
* remember project and emit & return it
*/
m_fileName2Project[canonicalFilePath] = project;
m_fileWatcher.addPath (QFileInfo (canonicalFilePath).canonicalPath());
m_projects.append(project);
m_fileWatcher.addPath (QFileInfo(fileName).canonicalPath());
emit projectCreated (project);
return project;
}
......@@ -167,8 +150,16 @@ KateProject *KateProjectPlugin::projectForDir (QDir dir)
/**
* check for project and load it if found
*/
QString canonicalPath = dir.canonicalPath();
QString canonicalFileName = canonicalPath + QString("/.kateproject");
foreach (KateProject *project, m_projects) {
if (project->baseDir() == canonicalPath || project->fileName() == canonicalFileName)
return project;
}
if (dir.exists (".kateproject"))
return projectForFileName (dir.absolutePath () + "/.kateproject");
return createProjectForFileName (canonicalFileName);
/**
* else: cd up, if possible or abort
......@@ -241,9 +232,13 @@ void KateProjectPlugin::slotDirectoryChanged (const QString &path)
/**
* auto-reload, if there
*/
KateProject *project = projectForFileName (QFileInfo (path + "/.kateproject").canonicalFilePath ());
if (project)
project->reload ();
QString fileName = path + QString("/.kateproject");
foreach (KateProject *project, m_projects) {
if (project->fileName() == fileName) {
project->reload();
break;
}
}
}
// kate: space-indent on; indent-width 2; replace-tabs on;
......@@ -44,14 +44,13 @@ class KateProjectPlugin : public Kate::Plugin
Kate::PluginView *createView( Kate::MainWindow *mainWindow );
/**
* Get project for given project filename.
* Will open a new one if not already open, else return the already open one.
* Create new project for given project filename.
* Null pointer if no project can be opened.
* File name will be canonicalized!
* @param fileName file name for the project
* @param fileName canonicalized file name for the project
* @return project or null if not openable
*/
KateProject *projectForFileName (const QString &fileName);
KateProject *createProjectForFileName (const QString &fileName);
/**
* Search and open project for given dir, if possible.
......@@ -77,7 +76,7 @@ class KateProjectPlugin : public Kate::Plugin
*/
QList<KateProject *> projects () const
{
return m_fileName2Project.values();
return m_projects;
}
/**
......@@ -132,9 +131,9 @@ class KateProjectPlugin : public Kate::Plugin
private:
/**
* open plugins, map fileName => project
* open plugins, maps project base directory => project
*/
QMap<QString, KateProject *> m_fileName2Project;
QList<KateProject *> m_projects;
/**
* filesystem watcher to keep track of all project files
......
......@@ -39,14 +39,14 @@ KateProjectWorker::~KateProjectWorker ()
{
}
void KateProjectWorker::loadProject (QString fileName, QVariantMap projectMap)
void KateProjectWorker::loadProject (QString baseDir, QVariantMap projectMap)
{
/**
* setup project file name
* name should be FIX after initial setting
* setup project base directory
* this should be FIX after initial setting
*/
Q_ASSERT (m_fileName.isEmpty() || (m_fileName == fileName));
m_fileName = fileName;
Q_ASSERT (m_baseDir.isEmpty() || (m_baseDir == baseDir));
m_baseDir = baseDir;
/**
* Create dummy top level parent item and empty map inside shared pointers
......@@ -162,7 +162,7 @@ void KateProjectWorker::loadFilesEntry (QStandardItem *parent, const QVariantMap
/**
* get directory to open or skip
*/
QDir dir (QFileInfo (m_fileName).absoluteDir());
QDir dir (m_baseDir);
if (!dir.cd (filesEntry["directory"].toString()))
return;
......
......@@ -56,10 +56,10 @@ class KateProjectWorker : public QObject
* Load the project.
* Will be used to load project in background.
* Will inform the project after loading was done and pass over all needed data!
* @param fileName project file name, should stay the same after initial setup
* @param baseDir project file name, should stay the same after initial setup
* @param projectMap full map containing the whole project as copy to work on
*/
void loadProject (QString fileName, QVariantMap projectMap);
void loadProject (QString baseDir, QVariantMap projectMap);
private:
/**
......@@ -92,9 +92,9 @@ class KateProjectWorker : public QObject
QObject *m_project;
/**
* project file name
* project base directory name
*/
QString m_fileName;
QString m_baseDir;
};
#endif
......
Markdown is supported
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