add config close_before_external_editor

Do not close the note when opening it with external editors if this is true.
This commit is contained in:
Le Tan 2017-12-22 22:09:38 +08:00
parent b12f738edc
commit e6db71217a
4 changed files with 19 additions and 2 deletions

View File

@ -178,6 +178,9 @@ vim_exemption_keys=cv
; Could be absolute path ; Could be absolute path
flash_page=flash_page.md flash_page=flash_page.md
; Whether close note before editting with external editor
close_before_external_editor=true
[web] [web]
; Location and configuration for Mathjax ; Location and configuration for Mathjax
mathjax_javascript=https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML mathjax_javascript=https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML

View File

@ -279,6 +279,9 @@ void VConfigManager::initialize()
m_vimExemptionKeys = getConfigFromSettings("global", m_vimExemptionKeys = getConfigFromSettings("global",
"vim_exemption_keys").toString(); "vim_exemption_keys").toString();
m_closeBeforeExternalEditor = getConfigFromSettings("global",
"close_before_external_editor").toBool();
} }
void VConfigManager::initSettings() void VConfigManager::initSettings()

View File

@ -397,6 +397,8 @@ public:
QString getThemeFile() const; QString getThemeFile() const;
bool getCloseBeforeExternalEditor() const;
private: private:
// Look up a config from user and default settings. // Look up a config from user and default settings.
QVariant getConfigFromSettings(const QString &section, const QString &key) const; QVariant getConfigFromSettings(const QString &section, const QString &key) const;
@ -769,6 +771,9 @@ private:
// [name] -> [file path]. // [name] -> [file path].
QMap<QString, QString> m_codeBlockCssStyles; QMap<QString, QString> m_codeBlockCssStyles;
// Whether close note before open it via external editor.
bool m_closeBeforeExternalEditor;
// The name of the config file in each directory, obsolete. // The name of the config file in each directory, obsolete.
// Use c_dirConfigFile instead. // Use c_dirConfigFile instead.
static const QString c_obsoleteDirConfigFile; 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); setConfigToSettings("global", "code_block_css_style", m_codeBlockCssStyle);
} }
inline bool VConfigManager::getCloseBeforeExternalEditor() const
{
return m_closeBeforeExternalEditor;
}
#endif // VCONFIGMANAGER_H #endif // VCONFIGMANAGER_H

View File

@ -1035,13 +1035,14 @@ void VFileList::handleOpenWithActionTriggered()
if (item) { if (item) {
VNoteFile *file = getVFile(item); VNoteFile *file = getVFile(item);
if (file if (file
&& (!editArea->isFileOpened(file) || editArea->closeFile(file, false))) { && (!g_config->getCloseBeforeExternalEditor()
|| !editArea->isFileOpened(file)
|| editArea->closeFile(file, false))) {
cmd.replace("%0", file->fetchPath()); cmd.replace("%0", file->fetchPath());
QProcess *process = new QProcess(this); QProcess *process = new QProcess(this);
connect(process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), connect(process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
process, &QProcess::deleteLater); process, &QProcess::deleteLater);
process->start(cmd); process->start(cmd);
qDebug() << "open with" << cmd << "process" << process->processId();
} }
} }
} }