From 377c00c25dc66b062c983990453f3d8d176a6f7f Mon Sep 17 00:00:00 2001 From: Le Tan Date: Thu, 6 Sep 2018 21:12:06 +0800 Subject: [PATCH] MagicWord: add %att% as the relative path of the attachment folder --- src/utils/vmetawordmanager.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/utils/vmetawordmanager.cpp b/src/utils/vmetawordmanager.cpp index 6d1a9703..cccf781e 100644 --- a/src/utils/vmetawordmanager.cpp +++ b/src/utils/vmetawordmanager.cpp @@ -8,6 +8,8 @@ #include "vconfigmanager.h" #include "vmainwindow.h" +#include "vnotefile.h" +#include "vnotebook.h" extern VConfigManager *g_config; @@ -280,6 +282,25 @@ void VMetaWordManager::init() return QString(); }); + // %att%. + addMetaWord(MetaWordType::FunctionBased, + "att", + tr("relative path of current note's attachment folder"), + [](const VMetaWord *) { + const VFile *file = g_mainWin->getCurrentFile(); + if (file && file->getType() == FileType::Note) { + const VNoteFile *nfile = static_cast(file); + const QString &folder = nfile->getAttachmentFolder(); + if (!folder.isEmpty()) { + return nfile->getNotebook()->getAttachmentFolder() + + "/" + + folder; + } + } + + return QString(); + }); + // Custom meta words. initCustomMetaWords();