Verified Commit 617480c3 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Allow to open a project using a command line parameter

This commit allows the projects plugin to parse the command line parameters
and open the specified projects.

Testplan:
kate ~/kde/src/knewstuff
kate ~/kde/src/knewstuff ~/kde/src/ktexteditor

If the plugin is disabled an error message should show up.
parent e3934f46
......@@ -18,6 +18,7 @@
#include <KLocalizedString>
#include <KSharedConfig>
#include <QCoreApplication>
#include <QFileInfo>
#include <QTime>
......@@ -64,6 +65,16 @@ KateProjectPlugin::KateProjectPlugin(QObject *parent, const QList<QVariant> &)
// read configuration prior to cwd project setup below
readConfig();
QStringList args = qApp->arguments();
bool projectSpecified = false;
args.removeFirst(); // The first argument is the executable name
for (const QString &arg : qAsConst(args)) {
QFileInfo info(arg);
if (info.isDir()) {
projectForDir(info.absoluteFilePath());
projectSpecified = true;
}
}
#ifdef HAVE_CTERMID
/**
......@@ -75,7 +86,9 @@ KateProjectPlugin::KateProjectPlugin(QObject *parent, const QList<QVariant> &)
int fd = ::open(tty, O_RDONLY);
if (fd >= 0) {
projectForDir(QDir::current());
if (!projectSpecified) {
projectForDir(QDir::current());
}
::close(fd);
}
#endif
......
......@@ -234,9 +234,8 @@ bool KateApp::startupKate()
setCursor(line, column);
}
} else {
KMessageBox::sorry(activeKateMainWindow(),
i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.", info.url.toString()));
} else if (!KateApp::self()->pluginManager()->plugin(QStringLiteral("kateprojectplugin"))) {
KMessageBox::sorry(activeKateMainWindow(), i18n("Folders can only be opened when the projects plugin is enabled"));
}
}
......
......@@ -19,6 +19,7 @@
#include <KSharedConfig>
#include <KStartupInfo>
#include <KWindowSystem>
#include <algorithm>
#include <QApplication>
#include <QByteArray>
......@@ -287,6 +288,10 @@ int main(int argc, char **argv)
|| parser.isSet(gotoLineOption) || parser.isSet(gotoColumnOption) || parser.isSet(readStdInOption))
&& (urls.isEmpty())) {
force_new = true;
} else {
force_new = std::any_of(urls.begin(), urls.end(), [](const QString &url) {
return QFileInfo(url).isDir();
});
}
}
......
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