Commit 89111ee1 authored by Christoph Cullmann's avatar Christoph Cullmann 🍨
Browse files

introduce projectBaseDir/projectMapForDocument

allows to query the project info for a given document
if the project plugin is loaded
parent 6daa2d96
Pipeline #236756 passed with stage
in 8 minutes and 33 seconds
......@@ -710,3 +710,23 @@ void KateProjectPlugin::sendMessage(const QString &text, bool error)
genericMessage.insert(QStringLiteral("text"), text);
Utils::showMessage(genericMessage);
}
QString KateProjectPlugin::projectBaseDirForDocument(KTextEditor::Document *doc)
{
// quick lookup first, then search
auto project = projectForDocument(doc);
if (!project) {
project = projectForUrl(doc->url());
}
return project ? project->baseDir() : QString();
}
QVariantMap KateProjectPlugin::projectMapForDocument(KTextEditor::Document *doc)
{
// quick lookup first, then search
auto project = projectForDocument(doc);
if (!project) {
project = projectForUrl(doc->url());
}
return project ? project->projectMap() : QVariantMap();
}
......@@ -167,6 +167,16 @@ public:
void sendMessage(const QString &text, bool error);
/**
* Returns project base dir for provided document
*/
Q_INVOKABLE QString projectBaseDirForDocument(KTextEditor::Document *doc);
/**
* Returns project map for provided document
*/
Q_INVOKABLE QVariantMap projectMapForDocument(KTextEditor::Document *doc);
Q_SIGNALS:
/**
......
......@@ -834,20 +834,6 @@ void KateProjectPluginView::openTerminal(const QString &dirPath, KateProject *pr
}
}
QString KateProjectPluginView::projectBaseDirForUrl(const QUrl &url)
{
const auto projects = m_plugin->projects();
QString ret;
for (auto *project : projects) {
const QString dir = project->baseDir();
if (url.toLocalFile().startsWith(dir)) {
// prefer the longer base path
ret = ret.length() < dir.length() ? dir : ret;
}
}
return ret;
}
void KateProjectPluginView::updateActions()
{
const bool hasMultipleProjects = m_projectsCombo->count() > 1;
......
......@@ -118,11 +118,6 @@ public:
*/
void openTerminal(const QString &dirPath, KateProject *project);
/**
* Returns project base dir for provided url
*/
Q_INVOKABLE QString projectBaseDirForUrl(const QUrl &url);
public Q_SLOTS:
/**
* Create views for given project.
......
......@@ -6,6 +6,7 @@
#include "kateurlbar.h"
#include "kateapp.h"
#include "kateviewmanager.h"
#include "ktexteditor_utils.h"
#include <KTextEditor/Document>
#include <KTextEditor/View>
......@@ -1011,13 +1012,9 @@ public:
}
}
void setUrl(const QUrl &url)
void setUrl(KTextEditor::Document *doc)
{
QObject *project = m_urlBar->viewManager()->mainWindow()->pluginView(QStringLiteral("kateprojectplugin"));
QString baseDir;
if (project) {
QMetaObject::invokeMethod(project, "projectBaseDirForUrl", Q_RETURN_ARG(QString, baseDir), Q_ARG(QUrl, url));
}
const QString baseDir = Utils::projectBaseDirForDocument(doc);
m_currBaseDir = baseDir;
if (m_currBaseDir.isEmpty()) {
......@@ -1026,7 +1023,7 @@ public:
} else {
m_ellipses->show();
}
m_mainCrumbView->setUrl(baseDir, url);
m_mainCrumbView->setUrl(baseDir, doc->url());
}
QPixmap separatorPixmap()
......@@ -1208,7 +1205,7 @@ void KateUrlBar::updateForDocument(KTextEditor::Document *doc)
return;
}
m_urlBarView->setUrl(doc->url());
m_urlBarView->setUrl(doc);
}
#include "kateurlbar.moc"
......@@ -171,4 +171,22 @@ void addWidget(QWidget *widget, KTextEditor::MainWindow *mainWindow)
kmw->addWidget(widget);
}
}
QString projectBaseDirForDocument(KTextEditor::Document *doc)
{
QString baseDir;
if (QObject *plugin = KTextEditor::Editor::instance()->application()->plugin(QStringLiteral("kateprojectplugin"))) {
QMetaObject::invokeMethod(plugin, "projectBaseDirForDocument", Q_RETURN_ARG(QString, baseDir), Q_ARG(KTextEditor::Document *, doc));
}
return baseDir;
}
QVariantMap projectMapForDocument(KTextEditor::Document *doc)
{
QVariantMap projectMap;
if (QObject *plugin = KTextEditor::Editor::instance()->application()->plugin(QStringLiteral("kateprojectplugin"))) {
QMetaObject::invokeMethod(plugin, "projectMapForDocument", Q_RETURN_ARG(QVariantMap, projectMap), Q_ARG(KTextEditor::Document *, doc));
}
return projectMap;
}
}
......@@ -78,4 +78,14 @@ KATE_PRIVATE_EXPORT void showDiff(const QByteArray &diff, const DiffParams &para
KATE_PRIVATE_EXPORT void addWidget(QWidget *widget, KTextEditor::MainWindow *mainWindow);
/*** END KTextEditor::MainWindow extensions **/
/**
* Returns project base dir for provided document
*/
KATE_PRIVATE_EXPORT QString projectBaseDirForDocument(KTextEditor::Document *doc);
/**
* Returns project map for provided document
*/
KATE_PRIVATE_EXPORT QVariantMap projectMapForDocument(KTextEditor::Document *doc);
}
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