From e6db71217a808c071a34a9939ed94841d2c8caf4 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Fri, 22 Dec 2017 22:09:38 +0800 Subject: [PATCH] add config close_before_external_editor Do not close the note when opening it with external editors if this is true. --- src/resources/vnote.ini | 3 +++ src/vconfigmanager.cpp | 3 +++ src/vconfigmanager.h | 10 ++++++++++ src/vfilelist.cpp | 5 +++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/resources/vnote.ini b/src/resources/vnote.ini index e066da74..c7415c19 100644 --- a/src/resources/vnote.ini +++ b/src/resources/vnote.ini @@ -178,6 +178,9 @@ vim_exemption_keys=cv ; Could be absolute path flash_page=flash_page.md +; Whether close note before editting with external editor +close_before_external_editor=true + [web] ; Location and configuration for Mathjax mathjax_javascript=https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML diff --git a/src/vconfigmanager.cpp b/src/vconfigmanager.cpp index b59f83ab..c5817bb8 100644 --- a/src/vconfigmanager.cpp +++ b/src/vconfigmanager.cpp @@ -279,6 +279,9 @@ void VConfigManager::initialize() m_vimExemptionKeys = getConfigFromSettings("global", "vim_exemption_keys").toString(); + + m_closeBeforeExternalEditor = getConfigFromSettings("global", + "close_before_external_editor").toBool(); } void VConfigManager::initSettings() diff --git a/src/vconfigmanager.h b/src/vconfigmanager.h index 0b3e58a2..033b9fde 100644 --- a/src/vconfigmanager.h +++ b/src/vconfigmanager.h @@ -397,6 +397,8 @@ public: QString getThemeFile() const; + bool getCloseBeforeExternalEditor() const; + private: // Look up a config from user and default settings. QVariant getConfigFromSettings(const QString §ion, const QString &key) const; @@ -769,6 +771,9 @@ private: // [name] -> [file path]. QMap m_codeBlockCssStyles; + // Whether close note before open it via external editor. + bool m_closeBeforeExternalEditor; + // The name of the config file in each directory, obsolete. // Use c_dirConfigFile instead. static const QString c_obsoleteDirConfigFile; @@ -1911,4 +1916,9 @@ inline void VConfigManager::setCodeBlockCssStyle(const QString &p_style) setConfigToSettings("global", "code_block_css_style", m_codeBlockCssStyle); } +inline bool VConfigManager::getCloseBeforeExternalEditor() const +{ + return m_closeBeforeExternalEditor; +} + #endif // VCONFIGMANAGER_H diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp index e9c0e59d..bb756f73 100644 --- a/src/vfilelist.cpp +++ b/src/vfilelist.cpp @@ -1035,13 +1035,14 @@ void VFileList::handleOpenWithActionTriggered() if (item) { VNoteFile *file = getVFile(item); if (file - && (!editArea->isFileOpened(file) || editArea->closeFile(file, false))) { + && (!g_config->getCloseBeforeExternalEditor() + || !editArea->isFileOpened(file) + || editArea->closeFile(file, false))) { cmd.replace("%0", file->fetchPath()); QProcess *process = new QProcess(this); connect(process, static_cast(&QProcess::finished), process, &QProcess::deleteLater); process->start(cmd); - qDebug() << "open with" << cmd << "process" << process->processId(); } } }