Use full compound extension (.md.gpg, .org.age, etc.)

fileitemaction uses completeSuffix() to preserve the full extension.
fileTypeFromExtension() recurses on compound extensions to detect
frontmatter support from the inner extension.
This commit is contained in:
Levi Neely 2026-07-12 20:36:15 +02:00
parent d21cab5362
commit 06c1f17570
2 changed files with 10 additions and 1 deletions

View File

@ -68,7 +68,7 @@ void DenoteFileItemAction::renameWithDenote(const KFileItemList &items, QWidget
defaultTitle.replace(QLatin1Char('_'), QLatin1Char(' '));
// Try to extract title from frontmatter if applicable
const QString ext = QStringLiteral(".") + fi.suffix();
const QString ext = QStringLiteral(".") + fi.completeSuffix();
Denote::FileType fileType = Denote::fileTypeFromExtension(ext);
if (fileType != Denote::FileType::Unknown) {
QFile file(path);

View File

@ -8,12 +8,21 @@ namespace Denote {
FileType fileTypeFromExtension(const QString &ext)
{
const QString lower = ext.toLower();
// Check the full extension first, then the inner extension for compound types
// e.g. ".md.gpg" -> check ".md.gpg", then ".md"
if (lower == QStringLiteral(".md") || lower == QStringLiteral(".markdown"))
return FileType::MdYaml;
if (lower == QStringLiteral(".org"))
return FileType::Org;
if (lower == QStringLiteral(".txt"))
return FileType::Txt;
// For compound extensions, check if the inner part is supported
int dot = lower.indexOf(QLatin1Char('.'), 1);
if (dot > 0) {
return fileTypeFromExtension(lower.left(dot));
}
return FileType::Unknown;
}