diff --git a/src/filewidgets/knewfilemenu.cpp b/src/filewidgets/knewfilemenu.cpp --- a/src/filewidgets/knewfilemenu.cpp +++ b/src/filewidgets/knewfilemenu.cpp @@ -639,6 +639,7 @@ m_newDirAction = nullptr; QSet seenTexts; + QString lastSeenText; // these shall be put at special positions QAction *linkURL = nullptr; QAction *linkApp = nullptr; @@ -691,7 +692,11 @@ sep->setSeparator(true); menu->addAction(sep); } else { - + if (lastSeenText.startsWith(QDir::homePath()) && !templatePath.startsWith(QDir::homePath())) { + QAction *sep = new QAction(q); + sep->setSeparator(true); + menu->addAction(sep); + } if (!m_supportedMimeTypes.isEmpty()) { bool keep = false; @@ -751,6 +756,7 @@ } } } + lastSeenText = entry.templatePath; } else { // Separate system from personal templates Q_ASSERT(entry.entryType != 0); @@ -892,7 +898,28 @@ //qDebug(); const QStringList qrcTemplates = { QStringLiteral(":/kio5/newfile-templates") }; - const QStringList installedTemplates = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("templates"), QStandardPaths::LocateDirectory); + QStringList installedTemplates = { QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("templates"), QStandardPaths::LocateDirectory) }; + // Qt does not provide an easy way to recieve the xdg dir for templates so we have to find it on our own + #ifdef Q_OS_UNIX + QString xdgUserDirs = QStandardPaths::locate(QStandardPaths::ConfigLocation, QStringLiteral("user-dirs.dirs"), QStandardPaths::LocateFile); + QFile xdgUserDirsFile(xdgUserDirs); + if (xdgUserDirsFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&xdgUserDirsFile); + while (!in.atEnd()) { + QString line = in.readLine(); + if (line.startsWith("XDG_TEMPLATES_DIR=")) { + QString xdgTemplates = line.mid(19, line.size()-20); + xdgTemplates.replace(QString("$HOME"), QDir::homePath()); + QDir xdgTemplatesDir(xdgTemplates); + if (xdgTemplatesDir.exists()) { + installedTemplates << xdgTemplates; + } + break; + } + } + } + #endif + const QStringList templates = qrcTemplates + installedTemplates; // Ensure any changes in the templates dir will call this @@ -946,9 +973,11 @@ if (file.endsWith(QLatin1String("Directory.desktop"))) { key.prepend('0'); } else if (file.endsWith(QLatin1String("TextFile.desktop"))) { + key.prepend('2'); + } else if (file.startsWith(QDir::homePath())) { key.prepend('1'); } else { - key.prepend('2'); + key.prepend('3'); } EntryWithName en = { key, e }; if (ulist.contains(url)) {