mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
support custom doc type suffixes
Add markdown_suffix config.
This commit is contained in:
parent
c2e1f14dfa
commit
586f5c0994
@ -66,6 +66,10 @@ editor_line_number=0
|
||||
; 1: minimize to system tray
|
||||
minimize_to_system_tray=-1
|
||||
|
||||
; Suffixes list of Markdown files separated by :
|
||||
; Case-insensitive
|
||||
markdown_suffix=md:markdown:mkd
|
||||
|
||||
[session]
|
||||
tools_dock_checked=true
|
||||
|
||||
|
@ -473,21 +473,7 @@ void VUtils::sleepWait(int p_milliseconds)
|
||||
|
||||
DocType VUtils::docTypeFromName(const QString &p_name)
|
||||
{
|
||||
static QMap<int, QVector<QString>> suffixes;
|
||||
|
||||
if (suffixes.isEmpty()) {
|
||||
QVector<QString> md;
|
||||
md << "md" << "markdown" << "mkd";
|
||||
suffixes[(int)DocType::Markdown] = md;
|
||||
|
||||
QVector<QString> list;
|
||||
list << "ls" << "list";
|
||||
suffixes[(int)DocType::List] = list;
|
||||
|
||||
QVector<QString> container;
|
||||
container << "co" << "container" << "con";
|
||||
suffixes[(int)DocType::Container] = container;
|
||||
}
|
||||
const QHash<int, QList<QString>> &suffixes = vconfig.getDocSuffixes();
|
||||
|
||||
QString suf = QFileInfo(p_name).suffix().toLower();
|
||||
for (auto it = suffixes.begin(); it != suffixes.end(); ++it) {
|
||||
|
@ -164,6 +164,8 @@ void VConfigManager::initialize()
|
||||
}
|
||||
|
||||
readShortcutsFromSettings();
|
||||
|
||||
initDocSuffixes();
|
||||
}
|
||||
|
||||
void VConfigManager::readPredefinedColorsFromSettings()
|
||||
@ -818,3 +820,30 @@ QString VConfigManager::getShortcutKeySequence(const QString &p_operation) const
|
||||
|
||||
return *it;
|
||||
}
|
||||
|
||||
void VConfigManager::initDocSuffixes()
|
||||
{
|
||||
m_docSuffixes.clear();
|
||||
|
||||
QString mdSuffix = getConfigFromSettings("global",
|
||||
"markdown_suffix").toString();
|
||||
if (mdSuffix.isEmpty()) {
|
||||
mdSuffix = getDefaultConfig("global",
|
||||
"markdown_suffix").toString();
|
||||
}
|
||||
|
||||
Q_ASSERT(!mdSuffix.isEmpty());
|
||||
QList<QString> md = mdSuffix.toLower().split(':', QString::SkipEmptyParts);
|
||||
md.removeDuplicates();
|
||||
m_docSuffixes[(int)DocType::Markdown] = md;
|
||||
|
||||
QList<QString> list;
|
||||
list << "ls" << "list";
|
||||
m_docSuffixes[(int)DocType::List] = list;
|
||||
|
||||
QList<QString> container;
|
||||
container << "co" << "container" << "con";
|
||||
m_docSuffixes[(int)DocType::Container] = container;
|
||||
|
||||
qDebug() << "doc suffixes" << m_docSuffixes;
|
||||
}
|
||||
|
@ -217,6 +217,9 @@ public:
|
||||
int getMinimizeToStystemTray() const;
|
||||
void setMinimizeToSystemTray(int p_val);
|
||||
|
||||
void initDocSuffixes();
|
||||
const QHash<int, QList<QString>> &getDocSuffixes() const;
|
||||
|
||||
// Return the configured key sequence of @p_operation.
|
||||
// Return empty if there is no corresponding config.
|
||||
QString getShortcutKeySequence(const QString &p_operation) const;
|
||||
@ -438,6 +441,10 @@ private:
|
||||
// 1: minimize to the tray.
|
||||
int m_minimizeToSystemTray;
|
||||
|
||||
// Suffixes of different doc type.
|
||||
// [DocType] -> { Suffixes }.
|
||||
QHash<int, QList<QString>> m_docSuffixes;
|
||||
|
||||
// The name of the config file in each directory, obsolete.
|
||||
// Use c_dirConfigFile instead.
|
||||
static const QString c_obsoleteDirConfigFile;
|
||||
@ -1126,4 +1133,8 @@ inline void VConfigManager::setMinimizeToSystemTray(int p_val)
|
||||
m_minimizeToSystemTray);
|
||||
}
|
||||
|
||||
inline const QHash<int, QList<QString>> &VConfigManager::getDocSuffixes() const
|
||||
{
|
||||
return m_docSuffixes;
|
||||
}
|
||||
#endif // VCONFIGMANAGER_H
|
||||
|
@ -5,7 +5,7 @@
|
||||
// Markdown: Markdown text file;
|
||||
// List: Infinite list file like WorkFlowy;
|
||||
// Container: a composite file containing multiple files;
|
||||
enum class DocType { Html, Markdown, List, Container, Invalid };
|
||||
enum class DocType { Html = 0, Markdown, List, Container, Invalid };
|
||||
|
||||
// Normal: note file managed by VNote;
|
||||
// Orphan: external file;
|
||||
|
@ -217,9 +217,17 @@ void VFileList::newFile()
|
||||
if (!m_directory) {
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QString> suffixes = vconfig.getDocSuffixes()[(int)DocType::Markdown];
|
||||
QString suffixStr;
|
||||
for (auto const & suf : suffixes) {
|
||||
suffixStr += (suffixStr.isEmpty() ? suf : "/" + suf);
|
||||
}
|
||||
|
||||
QString info = tr("Create a note in <span style=\"%1\">%2</span>.")
|
||||
.arg(vconfig.c_dataTextStyle).arg(m_directory->getName());
|
||||
info = info + "<br>" + tr("Note with name ending with \".md\" will be treated as Markdown type.");
|
||||
info = info + "<br>" + tr("Note with name ending with \"%1\" will be treated as Markdown type.")
|
||||
.arg(suffixStr);
|
||||
QString text(tr("Note &name:"));
|
||||
QString defaultText("new_note.md");
|
||||
do {
|
||||
|
Loading…
x
Reference in New Issue
Block a user