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