Commit d317129c authored by Christoph Cullmann's avatar Christoph Cullmann 🐮 Committed by Alexander Lohnau
Browse files

ensure new loaded project is active

if you e.g. have some session with already loaded projects,
these were active after you start kate from a terminal
or via kate /project/path

now we delay the project open of such fresh stuff until
the event loop starts after session restore

=> new projects are properly activated
parent 57eec9c4
Pipeline #71087 passed with stage
in 5 minutes and 43 seconds
......@@ -24,6 +24,7 @@
#include <QMessageBox>
#include <QString>
#include <QTime>
#include <QTimer>
#include <vector>
......@@ -62,13 +63,27 @@ KateProjectPlugin::KateProjectPlugin(QObject *parent, const QList<QVariant> &)
// read configuration prior to cwd project setup below
readConfig();
QStringList args = qApp->arguments();
// register all already open documents, later we keep track of all newly created ones
for (auto document : KTextEditor::Editor::instance()->application()->documents()) {
slotDocumentCreated(document);
}
// make project plugin variables known to KTextEditor::Editor
registerVariables();
// open directories as projects
bool projectSpecified = false;
auto args = qApp->arguments();
args.removeFirst(); // The first argument is the executable name
for (const QString &arg : qAsConst(args)) {
QFileInfo info(arg);
if (info.isDir()) {
projectForDir(info.absoluteFilePath(), true);
// delay open until even loop starts, to let this win over session restored stuff
const QDir pathToOpen = info.absoluteFilePath();
QTimer::singleShot(0, this, [this, pathToOpen]() {
projectForDir(pathToOpen, true);
});
projectSpecified = true;
}
}
......@@ -78,23 +93,18 @@ KateProjectPlugin::KateProjectPlugin(QObject *parent, const QList<QVariant> &)
* open project for our current working directory, if this kate has a terminal
* https://stackoverflow.com/questions/1312922/detect-if-stdin-is-a-terminal-or-pipe-in-c-c-qt
*/
char tty[L_ctermid + 1] = {0};
ctermid(tty);
int fd = ::open(tty, O_RDONLY);
if (fd >= 0) {
if (!projectSpecified) {
projectForDir(QDir::current());
if (!projectSpecified) {
char tty[L_ctermid + 1] = {0};
ctermid(tty);
if (int fd = ::open(tty, O_RDONLY); fd >= 0) {
const QDir pathToOpen = QDir::current();
QTimer::singleShot(0, this, [this, pathToOpen]() {
projectForDir(pathToOpen);
});
::close(fd);
}
::close(fd);
}
#endif
for (auto document : KTextEditor::Editor::instance()->application()->documents()) {
slotDocumentCreated(document);
}
registerVariables();
}
KateProjectPlugin::~KateProjectPlugin()
......
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