Commit 9c59bafa authored by Christoph Cullmann's avatar Christoph Cullmann

more functional splits

parent 1b807317
......@@ -91,32 +91,18 @@ KateProject *KateProjectPlugin::projectForFileName (const QString &fileName)
return project;
}
void KateProjectPlugin::slotDocumentCreated (KTextEditor::Document *document)
{
/**
* connect to url changed, for auto load
*/
connect (document, SIGNAL(documentUrlChanged ( KTextEditor::Document *)), this, SLOT(slotDocumentUrlChanged (KTextEditor::Document *)));
/**
* trigger slot once, for existing docs
*/
slotDocumentUrlChanged (document);
}
void KateProjectPlugin::slotDocumentUrlChanged (KTextEditor::Document *document)
KateProject *KateProjectPlugin::projectForUrl (const KUrl &url)
{
/**
* abort if empty url or no local path
*/
if (document->url().isEmpty() || !document->url().isLocalFile())
return;
if (url.isEmpty() || !url.isLocalFile())
return 0;
/**
* else get local filename and then the dir for it
*/
QString filePath = document->url().toLocalFile ();
QDir fileDirectory = QFileInfo(filePath).absoluteDir ();
QDir fileDirectory = QFileInfo(url.toLocalFile ()).absoluteDir ();
/**
* now, search projects upwards
......@@ -130,29 +116,43 @@ void KateProjectPlugin::slotDocumentUrlChanged (KTextEditor::Document *document)
seenDirectories.insert (fileDirectory.absolutePath ());
/**
* check for project
* check for project and load it if found
*/
if (fileDirectory.exists (".kateproject")) {
//QTime lala;
//lala.start ();
/**
* load project, if needed, and be done
*/
projectForFileName (fileDirectory.absolutePath () + "/.kateproject");
//printf ("TIME: %d\n", lala.elapsed());
return;
}
if (fileDirectory.exists (".kateproject"))
return projectForFileName (fileDirectory.absolutePath () + "/.kateproject");
/**
* else: cd up, if possible or abort
*/
if (!fileDirectory.cdUp())
return;
break;
}
/**
* nothing there
*/
return 0;
}
void KateProjectPlugin::slotDocumentCreated (KTextEditor::Document *document)
{
/**
* connect to url changed, for auto load
*/
connect (document, SIGNAL(documentUrlChanged ( KTextEditor::Document *)), this, SLOT(slotDocumentUrlChanged (KTextEditor::Document *)));
/**
* trigger slot once, for existing docs
*/
slotDocumentUrlChanged (document);
}
void KateProjectPlugin::slotDocumentUrlChanged (KTextEditor::Document *document)
{
/**
* search matching project
*/
projectForUrl (document->url());
}
// kate: space-indent on; indent-width 2; replace-tabs on;
......@@ -38,7 +38,7 @@ class KateProjectPlugin : public Kate::Plugin
Kate::PluginView *createView( Kate::MainWindow *mainWindow );
/**
* Get project for given filename.
* Get 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.
* File name will be canonicalized!
......@@ -47,6 +47,15 @@ class KateProjectPlugin : public Kate::Plugin
*/
KateProject *projectForFileName (const QString &fileName);
/**
* Search and open project that contains given url, if possible.
* Will search upwards for .kateproject file, if the url is a local file.
* Will use internally projectForFileName if a .kateproject file is found.
* @param url url to search matching project for
* @return project or null if not openable
*/
KateProject *projectForUrl (const KUrl &url);
signals:
/**
* Signal that a new project got created.
......
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