move vconfig to a local variable

This commit is contained in:
Le Tan 2017-08-27 10:35:57 +08:00
parent e1befc1038
commit 73630448a6
32 changed files with 273 additions and 278 deletions

View File

@ -2,7 +2,7 @@
#include "vdeletenotebookdialog.h" #include "vdeletenotebookdialog.h"
#include "vconfigmanager.h" #include "vconfigmanager.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VDeleteNotebookDialog::VDeleteNotebookDialog(const QString &p_title, const QString &p_name, VDeleteNotebookDialog::VDeleteNotebookDialog(const QString &p_title, const QString &p_name,
const QString &p_path, QWidget *p_parent) const QString &p_path, QWidget *p_parent)
@ -14,7 +14,7 @@ VDeleteNotebookDialog::VDeleteNotebookDialog(const QString &p_title, const QStri
void VDeleteNotebookDialog::setupUI(const QString &p_title, const QString &p_name) void VDeleteNotebookDialog::setupUI(const QString &p_title, const QString &p_name)
{ {
QLabel *infoLabel = new QLabel(tr("Are you sure to delete notebook <span style=\"%1\">%2</span>?") QLabel *infoLabel = new QLabel(tr("Are you sure to delete notebook <span style=\"%1\">%2</span>?")
.arg(vconfig.c_dataTextStyle).arg(p_name)); .arg(g_config->c_dataTextStyle).arg(p_name));
m_warningLabel = new QLabel(); m_warningLabel = new QLabel();
m_warningLabel->setWordWrap(true); m_warningLabel->setWordWrap(true);
@ -109,12 +109,12 @@ void VDeleteNotebookDialog::deleteCheckChanged(int p_state)
{ {
if (!p_state) { if (!p_state) {
m_warningLabel->setText(tr("VNote won't delete files in directory <span style=\"%1\">%2</span>.") m_warningLabel->setText(tr("VNote won't delete files in directory <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(m_path)); .arg(g_config->c_dataTextStyle).arg(m_path));
} else { } else {
m_warningLabel->setText(tr("<span style=\"%1\">WARNING</span>: " m_warningLabel->setText(tr("<span style=\"%1\">WARNING</span>: "
"VNote may delete <b>ANY</b> files in directory <span style=\"%2\">%3</span>! " "VNote may delete <b>ANY</b> files in directory <span style=\"%2\">%3</span>! "
"VNote will try to delete all the root folders within this notebook one by one. " "VNote will try to delete all the root folders within this notebook one by one. "
"It may be UNRECOVERABLE!") "It may be UNRECOVERABLE!")
.arg(vconfig.c_warningTextStyle).arg(vconfig.c_dataTextStyle).arg(m_path)); .arg(g_config->c_warningTextStyle).arg(g_config->c_dataTextStyle).arg(m_path));
} }
} }

View File

@ -5,7 +5,7 @@
#include "utils/vutils.h" #include "utils/vutils.h"
#include "vnotebook.h" #include "vnotebook.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VNewNotebookDialog::VNewNotebookDialog(const QString &title, const QString &info, VNewNotebookDialog::VNewNotebookDialog(const QString &title, const QString &info,
const QString &defaultName, const QString &defaultPath, const QString &defaultName, const QString &defaultPath,
@ -44,7 +44,7 @@ void VNewNotebookDialog::setupUI()
QLabel *imageFolderLabel = new QLabel(tr("&Image folder:")); QLabel *imageFolderLabel = new QLabel(tr("&Image folder:"));
m_imageFolderEdit = new QLineEdit(); m_imageFolderEdit = new QLineEdit();
m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)") m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)")
.arg(vconfig.getImageFolder())); .arg(g_config->getImageFolder()));
imageFolderLabel->setBuddy(m_imageFolderEdit); imageFolderLabel->setBuddy(m_imageFolderEdit);
QString imageFolderTip = tr("Set the name of the folder for all the notes of this notebook to store images " QString imageFolderTip = tr("Set the name of the folder for all the notes of this notebook to store images "
"(empty to use global configuration)"); "(empty to use global configuration)");
@ -114,7 +114,7 @@ void VNewNotebookDialog::handleBrowseBtnClicked()
{ {
static QString defaultPath; static QString defaultPath;
if (defaultPath.isEmpty()) { if (defaultPath.isEmpty()) {
defaultPath = vconfig.getVnoteNotebookFolderPath(); defaultPath = g_config->getVnoteNotebookFolderPath();
if (!QFileInfo::exists(defaultPath)) { if (!QFileInfo::exists(defaultPath)) {
defaultPath = QDir::homePath(); defaultPath = QDir::homePath();
} }
@ -146,7 +146,7 @@ void VNewNotebookDialog::handleInputChanged()
{ {
QString warnText = tr("<span style=\"%1\">WARNING</span>: The folder chosen is NOT empty! " QString warnText = tr("<span style=\"%1\">WARNING</span>: The folder chosen is NOT empty! "
"It is highly recommended to use an EMPTY and EXCLUSIVE folder for a new notebook.") "It is highly recommended to use an EMPTY and EXCLUSIVE folder for a new notebook.")
.arg(vconfig.c_warningTextStyle); .arg(g_config->c_warningTextStyle);
QString infoText = tr("<span style=\"%1\">INFO</span>: The folder chosen seems to be a root " QString infoText = tr("<span style=\"%1\">INFO</span>: The folder chosen seems to be a root "
"folder of a notebook created by VNote before. " "folder of a notebook created by VNote before. "
"VNote will try to import it by reading the configuration file.") "VNote will try to import it by reading the configuration file.")
@ -199,7 +199,7 @@ void VNewNotebookDialog::handleInputChanged()
showWarnLabel = true; showWarnLabel = true;
QString tmp = tr("<span style=\"%1\">WARNING</span>: The path seems to be illegal. " QString tmp = tr("<span style=\"%1\">WARNING</span>: The path seems to be illegal. "
"Please choose another one.") "Please choose another one.")
.arg(vconfig.c_warningTextStyle); .arg(g_config->c_warningTextStyle);
m_warnLabel->setText(tmp); m_warnLabel->setText(tmp);
} }
} }
@ -218,8 +218,8 @@ void VNewNotebookDialog::handleInputChanged()
showWarnLabel = true; showWarnLabel = true;
QString existText = tr("<span style=\"%1\">WARNING</span>: The folder chosen has already been a root folder " QString existText = tr("<span style=\"%1\">WARNING</span>: The folder chosen has already been a root folder "
"of existing notebook <span style=\"%2\">%3</span> in VNote.") "of existing notebook <span style=\"%2\">%3</span> in VNote.")
.arg(vconfig.c_warningTextStyle) .arg(g_config->c_warningTextStyle)
.arg(vconfig.c_dataTextStyle) .arg(g_config->c_dataTextStyle)
.arg(m_notebooks[idx]->getName()); .arg(m_notebooks[idx]->getName());
m_warnLabel->setText(existText); m_warnLabel->setText(existText);
} }
@ -242,7 +242,7 @@ void VNewNotebookDialog::handleInputChanged()
showWarnLabel = true; showWarnLabel = true;
QString nameConflictText = tr("<span style=\"%1\">WARNING</span>: Name (case-insensitive) already exists. " QString nameConflictText = tr("<span style=\"%1\">WARNING</span>: Name (case-insensitive) already exists. "
"Please choose another name.") "Please choose another name.")
.arg(vconfig.c_warningTextStyle); .arg(g_config->c_warningTextStyle);
m_warnLabel->setText(nameConflictText); m_warnLabel->setText(nameConflictText);
} }
} }
@ -261,7 +261,7 @@ bool VNewNotebookDialog::autoComplete()
return false; return false;
} }
QString vnoteFolder = vconfig.getVnoteNotebookFolderPath(); QString vnoteFolder = g_config->getVnoteNotebookFolderPath();
QString pathText = pathEdit->text(); QString pathText = pathEdit->text();
if (!pathText.isEmpty() if (!pathText.isEmpty()
&& !VUtils::equalPath(vnoteFolder, VUtils::basePathFromPath(pathText))) { && !VUtils::equalPath(vnoteFolder, VUtils::basePathFromPath(pathText))) {

View File

@ -4,7 +4,7 @@
#include "utils/vutils.h" #include "utils/vutils.h"
#include "vconfigmanager.h" #include "vconfigmanager.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VNotebookInfoDialog::VNotebookInfoDialog(const QString &p_title, VNotebookInfoDialog::VNotebookInfoDialog(const QString &p_title,
const QString &p_info, const QString &p_info,
@ -41,7 +41,7 @@ void VNotebookInfoDialog::setupUI(const QString &p_title, const QString &p_info)
QLabel *imageFolderLabel = new QLabel(tr("&Image folder:")); QLabel *imageFolderLabel = new QLabel(tr("&Image folder:"));
m_imageFolderEdit = new QLineEdit(m_notebook->getImageFolderConfig()); m_imageFolderEdit = new QLineEdit(m_notebook->getImageFolderConfig());
m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)") m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)")
.arg(vconfig.getImageFolder())); .arg(g_config->getImageFolder()));
imageFolderLabel->setBuddy(m_imageFolderEdit); imageFolderLabel->setBuddy(m_imageFolderEdit);
QString imageFolderTip = tr("Set the name of the folder for all the notes of this notebook to store images " QString imageFolderTip = tr("Set the name of the folder for all the notes of this notebook to store images "
"(empty to use global configuration)"); "(empty to use global configuration)");
@ -103,7 +103,7 @@ void VNotebookInfoDialog::handleInputChanged()
showWarnLabel = true; showWarnLabel = true;
QString nameConflictText = tr("<span style=\"%1\">WARNING</span>: Name (case-insensitive) already exists. " QString nameConflictText = tr("<span style=\"%1\">WARNING</span>: Name (case-insensitive) already exists. "
"Please choose another name.") "Please choose another name.")
.arg(vconfig.c_warningTextStyle); .arg(g_config->c_warningTextStyle);
m_warnLabel->setText(nameConflictText); m_warnLabel->setText(nameConflictText);
} }
} }

View File

@ -5,7 +5,7 @@
#include "vconfigmanager.h" #include "vconfigmanager.h"
#include "utils/vutils.h" #include "utils/vutils.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VOrphanFileInfoDialog::VOrphanFileInfoDialog(const VOrphanFile *p_file, QWidget *p_parent) VOrphanFileInfoDialog::VOrphanFileInfoDialog(const VOrphanFile *p_file, QWidget *p_parent)
: QDialog(p_parent), m_file(p_file) : QDialog(p_parent), m_file(p_file)
@ -28,7 +28,7 @@ void VOrphanFileInfoDialog::setupUI()
QLabel *imageFolderLabel = new QLabel(tr("Image folder:")); QLabel *imageFolderLabel = new QLabel(tr("Image folder:"));
m_imageFolderEdit = new QLineEdit(m_file->getImageFolder()); m_imageFolderEdit = new QLineEdit(m_file->getImageFolder());
m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)") m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)")
.arg(vconfig.getImageFolderExt())); .arg(g_config->getImageFolderExt()));
QString imgFolderTip = tr("Set the path of the image folder to store images " QString imgFolderTip = tr("Set the path of the image folder to store images "
"of this file.\nIf absolute path is used, " "of this file.\nIf absolute path is used, "
"VNote will not manage those images." "VNote will not manage those images."

View File

@ -5,7 +5,7 @@
#include "utils/vutils.h" #include "utils/vutils.h"
#include "vconstants.h" #include "vconstants.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VSettingsDialog::VSettingsDialog(QWidget *p_parent) VSettingsDialog::VSettingsDialog(QWidget *p_parent)
: QDialog(p_parent) : QDialog(p_parent)
@ -170,7 +170,7 @@ bool VGeneralTab::saveConfiguration()
bool VGeneralTab::loadLanguage() bool VGeneralTab::loadLanguage()
{ {
QString lang = vconfig.getLanguage(); QString lang = g_config->getLanguage();
if (lang.isNull()) { if (lang.isNull()) {
return false; return false;
} else if (lang == "System") { } else if (lang == "System") {
@ -196,20 +196,20 @@ bool VGeneralTab::loadLanguage()
bool VGeneralTab::saveLanguage() bool VGeneralTab::saveLanguage()
{ {
QString curLang = m_langCombo->currentData().toString(); QString curLang = m_langCombo->currentData().toString();
vconfig.setLanguage(curLang); g_config->setLanguage(curLang);
return true; return true;
} }
bool VGeneralTab::loadSystemTray() bool VGeneralTab::loadSystemTray()
{ {
m_systemTray->setChecked(vconfig.getMinimizeToStystemTray() != 0); m_systemTray->setChecked(g_config->getMinimizeToStystemTray() != 0);
return true; return true;
} }
bool VGeneralTab::saveSystemTray() bool VGeneralTab::saveSystemTray()
{ {
if (m_systemTray->isEnabled()) { if (m_systemTray->isEnabled()) {
vconfig.setMinimizeToSystemTray(m_systemTray->isChecked() ? 1 : 0); g_config->setMinimizeToSystemTray(m_systemTray->isChecked() ? 1 : 0);
} }
return true; return true;
@ -264,8 +264,8 @@ bool VReadEditTab::saveConfiguration()
bool VReadEditTab::loadWebZoomFactor() bool VReadEditTab::loadWebZoomFactor()
{ {
qreal factor = vconfig.getWebZoomFactor(); qreal factor = g_config->getWebZoomFactor();
bool customFactor = vconfig.isCustomWebZoomFactor(); bool customFactor = g_config->isCustomWebZoomFactor();
if (customFactor) { if (customFactor) {
if (factor < c_webZoomFactorMin || factor > c_webZoomFactorMax) { if (factor < c_webZoomFactorMin || factor > c_webZoomFactorMax) {
factor = 1; factor = 1;
@ -283,9 +283,9 @@ bool VReadEditTab::loadWebZoomFactor()
bool VReadEditTab::saveWebZoomFactor() bool VReadEditTab::saveWebZoomFactor()
{ {
if (m_customWebZoom->isChecked()) { if (m_customWebZoom->isChecked()) {
vconfig.setWebZoomFactor(m_webZoomFactorSpin->value()); g_config->setWebZoomFactor(m_webZoomFactorSpin->value());
} else { } else {
vconfig.setWebZoomFactor(-1); g_config->setWebZoomFactor(-1);
} }
return true; return true;
} }
@ -381,10 +381,10 @@ bool VNoteManagementTab::saveConfiguration()
bool VNoteManagementTab::loadImageFolder() bool VNoteManagementTab::loadImageFolder()
{ {
bool isCustom = vconfig.isCustomImageFolder(); bool isCustom = g_config->isCustomImageFolder();
m_customImageFolder->setChecked(isCustom); m_customImageFolder->setChecked(isCustom);
m_imageFolderEdit->setText(vconfig.getImageFolder()); m_imageFolderEdit->setText(g_config->getImageFolder());
m_imageFolderEdit->setEnabled(isCustom); m_imageFolderEdit->setEnabled(isCustom);
return true; return true;
@ -393,9 +393,9 @@ bool VNoteManagementTab::loadImageFolder()
bool VNoteManagementTab::saveImageFolder() bool VNoteManagementTab::saveImageFolder()
{ {
if (m_customImageFolder->isChecked()) { if (m_customImageFolder->isChecked()) {
vconfig.setImageFolder(m_imageFolderEdit->text()); g_config->setImageFolder(m_imageFolderEdit->text());
} else { } else {
vconfig.setImageFolder(""); g_config->setImageFolder("");
} }
return true; return true;
@ -414,10 +414,10 @@ void VNoteManagementTab::customImageFolderChanged(int p_state)
bool VNoteManagementTab::loadImageFolderExt() bool VNoteManagementTab::loadImageFolderExt()
{ {
bool isCustom = vconfig.isCustomImageFolderExt(); bool isCustom = g_config->isCustomImageFolderExt();
m_customImageFolderExt->setChecked(isCustom); m_customImageFolderExt->setChecked(isCustom);
m_imageFolderEditExt->setText(vconfig.getImageFolderExt()); m_imageFolderEditExt->setText(g_config->getImageFolderExt());
m_imageFolderEditExt->setEnabled(isCustom); m_imageFolderEditExt->setEnabled(isCustom);
return true; return true;
@ -426,9 +426,9 @@ bool VNoteManagementTab::loadImageFolderExt()
bool VNoteManagementTab::saveImageFolderExt() bool VNoteManagementTab::saveImageFolderExt()
{ {
if (m_customImageFolderExt->isChecked()) { if (m_customImageFolderExt->isChecked()) {
vconfig.setImageFolderExt(m_imageFolderEditExt->text()); g_config->setImageFolderExt(m_imageFolderEditExt->text());
} else { } else {
vconfig.setImageFolderExt(""); g_config->setImageFolderExt("");
} }
return true; return true;

View File

@ -8,7 +8,7 @@
#include "vconfigmanager.h" #include "vconfigmanager.h"
#include "vdownloader.h" #include "vdownloader.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VUpdater::VUpdater(QWidget *p_parent) VUpdater::VUpdater(QWidget *p_parent)
: QDialog(p_parent) : QDialog(p_parent)
@ -24,7 +24,7 @@ void VUpdater::setupUI()
imgLabel->setPixmap(QPixmap::fromImage(img.scaled(imgSize))); imgLabel->setPixmap(QPixmap::fromImage(img.scaled(imgSize)));
m_versionLabel = new QLabel(tr("Current Version: v%1") m_versionLabel = new QLabel(tr("Current Version: v%1")
.arg(vconfig.c_version)); .arg(g_config->c_version));
m_proLabel = new QLabel(tr("Checking for updates...")); m_proLabel = new QLabel(tr("Checking for updates..."));
m_proLabel->setOpenExternalLinks(true); m_proLabel->setOpenExternalLinks(true);
@ -156,8 +156,8 @@ void VUpdater::parseResult(const QByteArray &p_data)
QString body = json["body"].toString(); QString body = json["body"].toString();
m_versionLabel->setText(tr("Current Version: v%1\nLatest Version: v%2") m_versionLabel->setText(tr("Current Version: v%1\nLatest Version: v%2")
.arg(vconfig.c_version).arg(tag)); .arg(g_config->c_version).arg(tag));
if (isNewerVersion(vconfig.c_version, tag)) { if (isNewerVersion(g_config->c_version, tag)) {
m_proLabel->setText(tr("<span style=\"font-weight: bold;\">Updates Available!</span><br/>" m_proLabel->setText(tr("<span style=\"font-weight: bold;\">Updates Available!</span><br/>"
"Please visit <a href=\"%1\">Github Releases</a> to download the latest version.") "Please visit <a href=\"%1\">Github Releases</a> to download the latest version.")
.arg(releaseUrl)); .arg(releaseUrl));

View File

@ -6,7 +6,7 @@
#include "vconfigmanager.h" #include "vconfigmanager.h"
#include "utils/vutils.h" #include "utils/vutils.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
const int HGMarkdownHighlighter::initCapacity = 1024; const int HGMarkdownHighlighter::initCapacity = 1024;
@ -371,7 +371,7 @@ void HGMarkdownHighlighter::updateHighlight()
bool HGMarkdownHighlighter::updateCodeBlocks() bool HGMarkdownHighlighter::updateCodeBlocks()
{ {
if (!vconfig.getEnableCodeBlockHighlight()) { if (!g_config->getEnableCodeBlockHighlight()) {
m_codeBlockHighlights.clear(); m_codeBlockHighlights.clear();
return false; return false;
} }

View File

@ -12,7 +12,7 @@
#include "vsingleinstanceguard.h" #include "vsingleinstanceguard.h"
#include "vconfigmanager.h" #include "vconfigmanager.h"
VConfigManager vconfig; VConfigManager *g_config;
#if defined(QT_NO_DEBUG) #if defined(QT_NO_DEBUG)
QFile g_logFile; QFile g_logFile;
@ -143,7 +143,9 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
VConfigManager vconfig;
vconfig.initialize(); vconfig.initialize();
g_config = &vconfig;
QString locale = VUtils::getLocale(); QString locale = VUtils::getLocale();
qDebug() << "use locale" << locale; qDebug() << "use locale" << locale;

View File

@ -24,7 +24,7 @@
#include "vfile.h" #include "vfile.h"
#include "vnote.h" #include "vnote.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
QVector<QPair<QString, QString>> VUtils::s_availableLanguages; QVector<QPair<QString, QString>> VUtils::s_availableLanguages;
@ -338,7 +338,7 @@ int VUtils::showMessage(QMessageBox::Icon p_icon, const QString &p_title, const
if (p_type == MessageBoxType::Danger) { if (p_type == MessageBoxType::Danger) {
QPushButton *okBtn = dynamic_cast<QPushButton *>(msgBox.button(QMessageBox::Ok)); QPushButton *okBtn = dynamic_cast<QPushButton *>(msgBox.button(QMessageBox::Ok));
if (okBtn) { if (okBtn) {
okBtn->setStyleSheet(vconfig.c_dangerBtnStyle); okBtn->setStyleSheet(g_config->c_dangerBtnStyle);
} }
} }
return msgBox.exec(); return msgBox.exec();
@ -451,7 +451,7 @@ QChar VUtils::keyToChar(int p_key)
QString VUtils::getLocale() QString VUtils::getLocale()
{ {
QString locale = vconfig.getLanguage(); QString locale = g_config->getLanguage();
if (locale == "System" || !isValidLanguage(locale)) { if (locale == "System" || !isValidLanguage(locale)) {
locale = QLocale::system().name(); locale = QLocale::system().name();
} }
@ -473,7 +473,7 @@ void VUtils::sleepWait(int p_milliseconds)
DocType VUtils::docTypeFromName(const QString &p_name) DocType VUtils::docTypeFromName(const QString &p_name)
{ {
const QHash<int, QList<QString>> &suffixes = vconfig.getDocSuffixes(); const QHash<int, QList<QString>> &suffixes = g_config->getDocSuffixes();
QString suf = QFileInfo(p_name).suffix().toLower(); QString suf = QFileInfo(p_name).suffix().toLower();
for (auto it = suffixes.begin(); it != suffixes.end(); ++it) { for (auto it = suffixes.begin(); it != suffixes.end(); ++it) {
@ -521,19 +521,19 @@ QString VUtils::generateHtmlTemplate(MarkdownConverterType p_conType, bool p_exp
Q_ASSERT(false); Q_ASSERT(false);
} }
if (vconfig.getEnableMermaid()) { if (g_config->getEnableMermaid()) {
extraFile += "<link rel=\"stylesheet\" type=\"text/css\" href=\"qrc" + VNote::c_mermaidCssFile + "\"/>\n" + extraFile += "<link rel=\"stylesheet\" type=\"text/css\" href=\"qrc" + VNote::c_mermaidCssFile + "\"/>\n" +
"<script src=\"qrc" + VNote::c_mermaidApiJsFile + "\"></script>\n" + "<script src=\"qrc" + VNote::c_mermaidApiJsFile + "\"></script>\n" +
"<script>var VEnableMermaid = true;</script>\n"; "<script>var VEnableMermaid = true;</script>\n";
} }
if (vconfig.getEnableFlowchart()) { if (g_config->getEnableFlowchart()) {
extraFile += "<script src=\"qrc" + VNote::c_raphaelJsFile + "\"></script>\n" + extraFile += "<script src=\"qrc" + VNote::c_raphaelJsFile + "\"></script>\n" +
"<script src=\"qrc" + VNote::c_flowchartJsFile + "\"></script>\n" + "<script src=\"qrc" + VNote::c_flowchartJsFile + "\"></script>\n" +
"<script>var VEnableFlowchart = true;</script>\n"; "<script>var VEnableFlowchart = true;</script>\n";
} }
if (vconfig.getEnableMathjax()) { if (g_config->getEnableMathjax()) {
extraFile += "<script type=\"text/x-mathjax-config\">" extraFile += "<script type=\"text/x-mathjax-config\">"
"MathJax.Hub.Config({\n" "MathJax.Hub.Config({\n"
" tex2jax: {inlineMath: [['$','$'], ['\\\\(','\\\\)']]},\n" " tex2jax: {inlineMath: [['$','$'], ['\\\\(','\\\\)']]},\n"
@ -544,7 +544,7 @@ QString VUtils::generateHtmlTemplate(MarkdownConverterType p_conType, bool p_exp
"<script>var VEnableMathjax = true;</script>\n"; "<script>var VEnableMathjax = true;</script>\n";
} }
if (vconfig.getEnableImageCaption()) { if (g_config->getEnableImageCaption()) {
extraFile += "<script>var VEnableImageCaption = true;</script>\n"; extraFile += "<script>var VEnableImageCaption = true;</script>\n";
} }

View File

@ -13,7 +13,7 @@
#include "utils/veditutils.h" #include "utils/veditutils.h"
#include "vconstants.h" #include "vconstants.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
const QChar VVim::c_unnamedRegister = QChar('"'); const QChar VVim::c_unnamedRegister = QChar('"');
const QChar VVim::c_blackHoleRegister = QChar('_'); const QChar VVim::c_blackHoleRegister = QChar('_');
@ -349,7 +349,7 @@ static void insertChangeBlockAfterDeletion(QTextCursor &p_cursor, int p_deletion
p_cursor.movePosition(QTextCursor::PreviousBlock); p_cursor.movePosition(QTextCursor::PreviousBlock);
} }
if (vconfig.getAutoIndent()) { if (g_config->getAutoIndent()) {
VEditUtils::indentBlockAsPreviousBlock(p_cursor); VEditUtils::indentBlockAsPreviousBlock(p_cursor);
} }
} }
@ -975,9 +975,9 @@ bool VVim::handleKeyPressEvent(int key, int modifiers, int *p_autoIndentPos)
} }
bool textInserted = false; bool textInserted = false;
if (vconfig.getAutoIndent()) { if (g_config->getAutoIndent()) {
textInserted = VEditUtils::indentBlockAsPreviousBlock(cursor); textInserted = VEditUtils::indentBlockAsPreviousBlock(cursor);
if (vconfig.getAutoList()) { if (g_config->getAutoList()) {
textInserted = VEditUtils::insertListMarkAsPreviousBlock(cursor) textInserted = VEditUtils::insertListMarkAsPreviousBlock(cursor)
|| textInserted; || textInserted;
} }
@ -2239,7 +2239,7 @@ void VVim::setMode(VimMode p_mode, bool p_clearSelection)
if (p_mode == VimMode::Insert) { if (p_mode == VimMode::Insert) {
m_editor->setInputMethodEnabled(true); m_editor->setInputMethodEnabled(true);
} else if (vconfig.getEnableSmartImInVimMode()) { } else if (g_config->getEnableSmartImInVimMode()) {
m_editor->setInputMethodEnabled(false); m_editor->setInputMethodEnabled(false);
} }

View File

@ -28,8 +28,8 @@ const QString VConfigManager::c_dangerBtnStyle = QString("QPushButton {color: #f
"QPushButton::hover {color: #fff; border-color: #ac2925; background-color: #c9302c;}"); "QPushButton::hover {color: #fff; border-color: #ac2925; background-color: #c9302c;}");
const QString VConfigManager::c_vnoteNotebookFolderName = QString("vnote_notebooks"); const QString VConfigManager::c_vnoteNotebookFolderName = QString("vnote_notebooks");
VConfigManager::VConfigManager() VConfigManager::VConfigManager(QObject *p_parent)
: userSettings(NULL), defaultSettings(NULL) : QObject(p_parent), userSettings(NULL), defaultSettings(NULL)
{ {
} }
@ -46,9 +46,10 @@ void VConfigManager::migrateIniFile()
void VConfigManager::initialize() void VConfigManager::initialize()
{ {
Q_ASSERT(!userSettings && !defaultSettings);
userSettings = new QSettings(QSettings::IniFormat, QSettings::UserScope, userSettings = new QSettings(QSettings::IniFormat, QSettings::UserScope,
orgName, appName); orgName, appName, this);
defaultSettings = new QSettings(defaultConfigFilePath, QSettings::IniFormat); defaultSettings = new QSettings(defaultConfigFilePath, QSettings::IniFormat, this);
migrateIniFile(); migrateIniFile();

View File

@ -1,6 +1,7 @@
#ifndef VCONFIGMANAGER_H #ifndef VCONFIGMANAGER_H
#define VCONFIGMANAGER_H #define VCONFIGMANAGER_H
#include <QObject>
#include <QFont> #include <QFont>
#include <QPalette> #include <QPalette>
#include <QVector> #include <QVector>
@ -27,15 +28,10 @@ struct VColor
QString rgb; // 'FFFFFF', without '#' QString rgb; // 'FFFFFF', without '#'
}; };
// FIXME: we do not free userSettings and defaultSettings here since there will class VConfigManager : public QObject
// be only one global instance of VConfigManager. Freeing them in the destructor
// causes crash in macOS.
// One solution is to make the global variable a pointer, which causes too many
// modifications. For now, we just choose the simple way.
class VConfigManager
{ {
public: public:
VConfigManager(); explicit VConfigManager(QObject *p_parent = NULL);
void initialize(); void initialize();

View File

@ -7,7 +7,7 @@
#include "vfile.h" #include "vfile.h"
#include "utils/vutils.h" #include "utils/vutils.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VDirectory::VDirectory(VNotebook *p_notebook, VDirectory::VDirectory(VNotebook *p_notebook,
const QString &p_name, QObject *p_parent) const QString &p_name, QObject *p_parent)
@ -551,7 +551,7 @@ VFile *VDirectory::copyFile(VDirectory *p_destDir, const QString &p_destName,
ret = VUtils::makePath(destImagePath); ret = VUtils::makePath(destImagePath);
if (!ret) { if (!ret) {
errStr = tr("Fail to create image folder <span style=\"%1\">%2</span>.") errStr = tr("Fail to create image folder <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(destImagePath); .arg(g_config->c_dataTextStyle).arg(destImagePath);
} else { } else {
destImagePath = QDir(destImagePath).filePath(VUtils::fileNameFromPath(link.m_path)); destImagePath = QDir(destImagePath).filePath(VUtils::fileNameFromPath(link.m_path));
@ -570,7 +570,7 @@ VFile *VDirectory::copyFile(VDirectory *p_destDir, const QString &p_destName,
} else { } else {
errStr = tr("Please check if there already exists a file <span style=\"%1\">%2</span> " errStr = tr("Please check if there already exists a file <span style=\"%1\">%2</span> "
"and then manually copy it and modify the note accordingly.") "and then manually copy it and modify the note accordingly.")
.arg(vconfig.c_dataTextStyle).arg(destImagePath); .arg(g_config->c_dataTextStyle).arg(destImagePath);
} }
} }
@ -578,8 +578,8 @@ VFile *VDirectory::copyFile(VDirectory *p_destDir, const QString &p_destName,
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to copy image <span style=\"%1\">%2</span> while " tr("Fail to copy image <span style=\"%1\">%2</span> while "
"%5 note <span style=\"%3\">%4</span>.") "%5 note <span style=\"%3\">%4</span>.")
.arg(vconfig.c_dataTextStyle).arg(link.m_path) .arg(g_config->c_dataTextStyle).arg(link.m_path)
.arg(vconfig.c_dataTextStyle).arg(srcPath) .arg(g_config->c_dataTextStyle).arg(srcPath)
.arg(p_cut ? tr("moving") : tr("copying")), .arg(p_cut ? tr("moving") : tr("copying")),
errStr, QMessageBox::Ok, QMessageBox::Ok, NULL); errStr, QMessageBox::Ok, QMessageBox::Ok, NULL);
} }

View File

@ -9,7 +9,7 @@
#include "veditarea.h" #include "veditarea.h"
#include "vconfigmanager.h" #include "vconfigmanager.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
extern VNote *g_vnote; extern VNote *g_vnote;
VDirectoryTree::VDirectoryTree(VNote *vnote, QWidget *parent) VDirectoryTree::VDirectoryTree(VNote *vnote, QWidget *parent)
@ -103,7 +103,7 @@ void VDirectoryTree::setNotebook(VNotebook *p_notebook)
if (!m_notebook->open()) { if (!m_notebook->open()) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to open notebook <span style=\"%1\">%2</span>.") tr("Fail to open notebook <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(m_notebook->getName()), "", .arg(g_config->c_dataTextStyle).arg(m_notebook->getName()), "",
QMessageBox::Ok, QMessageBox::Ok, this); QMessageBox::Ok, QMessageBox::Ok, this);
clear(); clear();
return; return;
@ -165,7 +165,7 @@ void VDirectoryTree::buildSubTree(QTreeWidgetItem *p_parent, int p_depth)
if (!dir->open()) { if (!dir->open()) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to open folder <span style=\"%1\">%2</span>.") tr("Fail to open folder <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(dir->getName()), "", .arg(g_config->c_dataTextStyle).arg(dir->getName()), "",
QMessageBox::Ok, QMessageBox::Ok, this); QMessageBox::Ok, QMessageBox::Ok, this);
return; return;
} }
@ -339,7 +339,7 @@ void VDirectoryTree::newSubDirectory()
VDirectory *curDir = getVDirectory(curItem); VDirectory *curDir = getVDirectory(curItem);
QString info = tr("Create a subfolder in <span style=\"%1\">%2</span>.") QString info = tr("Create a subfolder in <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(curDir->getName()); .arg(g_config->c_dataTextStyle).arg(curDir->getName());
QString text(tr("Folder &name:")); QString text(tr("Folder &name:"));
QString defaultText("new_folder"); QString defaultText("new_folder");
@ -351,7 +351,7 @@ void VDirectoryTree::newSubDirectory()
if (curDir->findSubDirectory(name, false)) { if (curDir->findSubDirectory(name, false)) {
info = tr("Name (case-insensitive) already exists in " info = tr("Name (case-insensitive) already exists in "
"<span style=\"%1\">%2</span>. Please choose another name.") "<span style=\"%1\">%2</span>. Please choose another name.")
.arg(vconfig.c_dataTextStyle).arg(curDir->getName()); .arg(g_config->c_dataTextStyle).arg(curDir->getName());
defaultText = name; defaultText = name;
continue; continue;
} }
@ -360,7 +360,7 @@ void VDirectoryTree::newSubDirectory()
if (!subDir) { if (!subDir) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to create folder <span style=\"%1\">%2</span>.") tr("Fail to create folder <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(name), "", .arg(g_config->c_dataTextStyle).arg(name), "",
QMessageBox::Ok, QMessageBox::Ok, this); QMessageBox::Ok, QMessageBox::Ok, this);
return; return;
} }
@ -377,7 +377,7 @@ void VDirectoryTree::newRootDirectory()
return; return;
} }
QString info = tr("Create a root folder in notebook <span style=\"%1\">%2</span>.") QString info = tr("Create a root folder in notebook <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(m_notebook->getName()); .arg(g_config->c_dataTextStyle).arg(m_notebook->getName());
QString text(tr("Folder &name:")); QString text(tr("Folder &name:"));
QString defaultText("new_folder"); QString defaultText("new_folder");
VDirectory *rootDir = m_notebook->getRootDir(); VDirectory *rootDir = m_notebook->getRootDir();
@ -388,7 +388,7 @@ void VDirectoryTree::newRootDirectory()
if (rootDir->findSubDirectory(name, false)) { if (rootDir->findSubDirectory(name, false)) {
info = tr("Name (case-insensitive) already exists in " info = tr("Name (case-insensitive) already exists in "
"notebook <span style=\"%1\">%2</span>. Please choose another name.") "notebook <span style=\"%1\">%2</span>. Please choose another name.")
.arg(vconfig.c_dataTextStyle).arg(m_notebook->getName()); .arg(g_config->c_dataTextStyle).arg(m_notebook->getName());
defaultText = name; defaultText = name;
continue; continue;
} }
@ -396,7 +396,7 @@ void VDirectoryTree::newRootDirectory()
if (!subDir) { if (!subDir) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to create folder <span style=\"%1\">%2</span>.") tr("Fail to create folder <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(name), "", .arg(g_config->c_dataTextStyle).arg(name), "",
QMessageBox::Ok, QMessageBox::Ok, this); QMessageBox::Ok, QMessageBox::Ok, this);
return; return;
} }
@ -416,12 +416,12 @@ void VDirectoryTree::deleteDirectory()
VDirectory *curDir = getVDirectory(curItem); VDirectory *curDir = getVDirectory(curItem);
int ret = VUtils::showMessage(QMessageBox::Warning, tr("Warning"), int ret = VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Are you sure to delete folder <span style=\"%1\">%2</span>?") tr("Are you sure to delete folder <span style=\"%1\">%2</span>?")
.arg(vconfig.c_dataTextStyle).arg(curDir->getName()), .arg(g_config->c_dataTextStyle).arg(curDir->getName()),
tr("<span style=\"%1\">WARNING</span>: " tr("<span style=\"%1\">WARNING</span>: "
"VNote will delete the whole directory (<b>ANY</b> files) " "VNote will delete the whole directory (<b>ANY</b> files) "
"<span style=\"%2\">%3</span>." "<span style=\"%2\">%3</span>."
"<br>It may be UNRECOVERABLE!") "<br>It may be UNRECOVERABLE!")
.arg(vconfig.c_warningTextStyle).arg(vconfig.c_dataTextStyle).arg(curDir->retrivePath()), .arg(g_config->c_warningTextStyle).arg(g_config->c_dataTextStyle).arg(curDir->retrivePath()),
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok | QMessageBox::Cancel,
QMessageBox::Ok, this, MessageBoxType::Danger); QMessageBox::Ok, this, MessageBoxType::Danger);
if (ret == QMessageBox::Ok) { if (ret == QMessageBox::Ok) {
@ -475,7 +475,7 @@ void VDirectoryTree::editDirectoryInfo()
if (!curDir->rename(name)) { if (!curDir->rename(name)) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to rename folder <span style=\"%1\">%2</span>.") tr("Fail to rename folder <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(curName), "", .arg(g_config->c_dataTextStyle).arg(curName), "",
QMessageBox::Ok, QMessageBox::Ok, this); QMessageBox::Ok, QMessageBox::Ok, this);
return; return;
} }
@ -679,7 +679,7 @@ bool VDirectoryTree::copyDirectory(VDirectory *p_destDir, const QString &p_destN
} else { } else {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to copy folder <span style=\"%1\">%2</span>.") tr("Fail to copy folder <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(srcName), .arg(g_config->c_dataTextStyle).arg(srcName),
tr("Please check if there already exists a folder with the same name."), tr("Please check if there already exists a folder with the same name."),
QMessageBox::Ok, QMessageBox::Ok, this); QMessageBox::Ok, QMessageBox::Ok, this);
} }

View File

@ -10,35 +10,35 @@
#include "veditoperations.h" #include "veditoperations.h"
#include "vedittab.h" #include "vedittab.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
extern VNote *g_vnote; extern VNote *g_vnote;
void VEditConfig::init(const QFontMetrics &p_metric) void VEditConfig::init(const QFontMetrics &p_metric)
{ {
update(p_metric); update(p_metric);
m_enableVimMode = vconfig.getEnableVimMode(); m_enableVimMode = g_config->getEnableVimMode();
m_highlightWholeBlock = m_enableVimMode; m_highlightWholeBlock = m_enableVimMode;
} }
void VEditConfig::update(const QFontMetrics &p_metric) void VEditConfig::update(const QFontMetrics &p_metric)
{ {
if (vconfig.getTabStopWidth() > 0) { if (g_config->getTabStopWidth() > 0) {
m_tabStopWidth = vconfig.getTabStopWidth() * p_metric.width(' '); m_tabStopWidth = g_config->getTabStopWidth() * p_metric.width(' ');
} else { } else {
m_tabStopWidth = 0; m_tabStopWidth = 0;
} }
m_expandTab = vconfig.getIsExpandTab(); m_expandTab = g_config->getIsExpandTab();
if (m_expandTab && (vconfig.getTabStopWidth() > 0)) { if (m_expandTab && (g_config->getTabStopWidth() > 0)) {
m_tabSpaces = QString(vconfig.getTabStopWidth(), ' '); m_tabSpaces = QString(g_config->getTabStopWidth(), ' ');
} else { } else {
m_tabSpaces = "\t"; m_tabSpaces = "\t";
} }
m_cursorLineBg = QColor(vconfig.getEditorCurrentLineBg()); m_cursorLineBg = QColor(g_config->getEditorCurrentLineBg());
} }
VEdit::VEdit(VFile *p_file, QWidget *p_parent) VEdit::VEdit(VFile *p_file, QWidget *p_parent)
@ -49,11 +49,11 @@ VEdit::VEdit(VFile *p_file, QWidget *p_parent)
const int extraSelectionHighlightTimer = 500; const int extraSelectionHighlightTimer = 500;
const int labelSize = 64; const int labelSize = 64;
m_selectedWordColor = QColor(vconfig.getEditorSelectedWordBg()); m_selectedWordColor = QColor(g_config->getEditorSelectedWordBg());
m_searchedWordColor = QColor(vconfig.getEditorSearchedWordBg()); m_searchedWordColor = QColor(g_config->getEditorSearchedWordBg());
m_searchedWordCursorColor = QColor(vconfig.getEditorSearchedWordCursorBg()); m_searchedWordCursorColor = QColor(g_config->getEditorSearchedWordCursorBg());
m_incrementalSearchedWordColor = QColor(vconfig.getEditorIncrementalSearchedWordBg()); m_incrementalSearchedWordColor = QColor(g_config->getEditorIncrementalSearchedWordBg());
m_trailingSpaceColor = QColor(vconfig.getEditorTrailingSpaceBg()); m_trailingSpaceColor = QColor(g_config->getEditorTrailingSpaceBg());
QPixmap wrapPixmap(":/resources/icons/search_wrap.svg"); QPixmap wrapPixmap(":/resources/icons/search_wrap.svg");
m_wrapLabel = new QLabel(this); m_wrapLabel = new QLabel(this);
@ -467,8 +467,8 @@ void VEdit::labelTimerTimeout()
void VEdit::updateFontAndPalette() void VEdit::updateFontAndPalette()
{ {
setFont(vconfig.getBaseEditFont()); setFont(g_config->getBaseEditFont());
setPalette(vconfig.getBaseEditPalette()); setPalette(g_config->getBaseEditPalette());
} }
void VEdit::highlightExtraSelections(bool p_now) void VEdit::highlightExtraSelections(bool p_now)
@ -496,7 +496,7 @@ void VEdit::doHighlightExtraSelections()
void VEdit::highlightCurrentLine() void VEdit::highlightCurrentLine()
{ {
QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::CurrentLine]; QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::CurrentLine];
if (vconfig.getHighlightCursorLine() && !isReadOnly()) { if (g_config->getHighlightCursorLine() && !isReadOnly()) {
// Need to highlight current line. // Need to highlight current line.
selects.clear(); selects.clear();
@ -545,7 +545,7 @@ void VEdit::setReadOnly(bool p_ro)
void VEdit::highlightSelectedWord() void VEdit::highlightSelectedWord()
{ {
QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::SelectedWord]; QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::SelectedWord];
if (!vconfig.getHighlightSelectedWord()) { if (!g_config->getHighlightSelectedWord()) {
if (!selects.isEmpty()) { if (!selects.isEmpty()) {
selects.clear(); selects.clear();
highlightExtraSelections(true); highlightExtraSelections(true);
@ -588,7 +588,7 @@ static void trailingSpaceFilter(VEdit *p_editor, QList<QTextEdit::ExtraSelection
void VEdit::highlightTrailingSpace() void VEdit::highlightTrailingSpace()
{ {
if (!vconfig.getEnableTrailingSpaceHighlight()) { if (!g_config->getEnableTrailingSpaceHighlight()) {
QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::TrailingSapce]; QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::TrailingSapce];
if (!selects.isEmpty()) { if (!selects.isEmpty()) {
selects.clear(); selects.clear();
@ -650,7 +650,7 @@ void VEdit::highlightTextAll(const QString &p_text, uint p_options,
void VEdit::highlightSearchedWord(const QString &p_text, uint p_options) void VEdit::highlightSearchedWord(const QString &p_text, uint p_options)
{ {
QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::SearchedKeyword]; QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::SearchedKeyword];
if (!vconfig.getHighlightSearchedWord() || p_text.isEmpty()) { if (!g_config->getHighlightSearchedWord() || p_text.isEmpty()) {
if (!selects.isEmpty()) { if (!selects.isEmpty()) {
selects.clear(); selects.clear();
highlightExtraSelections(true); highlightExtraSelections(true);
@ -688,7 +688,7 @@ void VEdit::highlightSearchedWordUnderCursor(const QTextCursor &p_cursor)
void VEdit::highlightIncrementalSearchedWord(const QTextCursor &p_cursor) void VEdit::highlightIncrementalSearchedWord(const QTextCursor &p_cursor)
{ {
QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::IncrementalSearchedKeyword]; QList<QTextEdit::ExtraSelection> &selects = m_extraSelections[(int)SelectionId::IncrementalSearchedKeyword];
if (!vconfig.getHighlightSearchedWord() || !p_cursor.hasSelection()) { if (!g_config->getHighlightSearchedWord() || !p_cursor.hasSelection()) {
if (!selects.isEmpty()) { if (!selects.isEmpty()) {
selects.clear(); selects.clear();
highlightExtraSelections(true); highlightExtraSelections(true);
@ -962,7 +962,7 @@ void VEdit::decorateText(TextDecoration p_decoration)
void VEdit::updateLineNumberAreaMargin() void VEdit::updateLineNumberAreaMargin()
{ {
int width = 0; int width = 0;
if (vconfig.getEditorLineNumber()) { if (g_config->getEditorLineNumber()) {
width = m_lineNumberArea->calculateWidth(); width = m_lineNumberArea->calculateWidth();
} }
@ -971,7 +971,7 @@ void VEdit::updateLineNumberAreaMargin()
void VEdit::updateLineNumberArea() void VEdit::updateLineNumberArea()
{ {
if (vconfig.getEditorLineNumber()) { if (g_config->getEditorLineNumber()) {
if (!m_lineNumberArea->isVisible()) { if (!m_lineNumberArea->isVisible()) {
updateLineNumberAreaMargin(); updateLineNumberAreaMargin();
m_lineNumberArea->show(); m_lineNumberArea->show();
@ -988,7 +988,7 @@ void VEdit::resizeEvent(QResizeEvent *p_event)
{ {
QTextEdit::resizeEvent(p_event); QTextEdit::resizeEvent(p_event);
if (vconfig.getEditorLineNumber()) { if (g_config->getEditorLineNumber()) {
QRect rect = contentsRect(); QRect rect = contentsRect();
m_lineNumberArea->setGeometry(QRect(rect.left(), m_lineNumberArea->setGeometry(QRect(rect.left(),
rect.top(), rect.top(),
@ -999,14 +999,14 @@ void VEdit::resizeEvent(QResizeEvent *p_event)
void VEdit::lineNumberAreaPaintEvent(QPaintEvent *p_event) void VEdit::lineNumberAreaPaintEvent(QPaintEvent *p_event)
{ {
if (!vconfig.getEditorLineNumber()) { if (!g_config->getEditorLineNumber()) {
updateLineNumberAreaMargin(); updateLineNumberAreaMargin();
m_lineNumberArea->hide(); m_lineNumberArea->hide();
return; return;
} }
QPainter painter(m_lineNumberArea); QPainter painter(m_lineNumberArea);
painter.fillRect(p_event->rect(), vconfig.getEditorLineNumberBg()); painter.fillRect(p_event->rect(), g_config->getEditorLineNumberBg());
QTextDocument *doc = document(); QTextDocument *doc = document();
QAbstractTextDocumentLayout *layout = doc->documentLayout(); QAbstractTextDocumentLayout *layout = doc->documentLayout();
@ -1021,8 +1021,8 @@ void VEdit::lineNumberAreaPaintEvent(QPaintEvent *p_event)
int eventBtm = p_event->rect().bottom(); int eventBtm = p_event->rect().bottom();
const int digitHeight = m_lineNumberArea->getDigitHeight(); const int digitHeight = m_lineNumberArea->getDigitHeight();
const int curBlockNumber = textCursor().block().blockNumber(); const int curBlockNumber = textCursor().block().blockNumber();
const bool relative = vconfig.getEditorLineNumber() == 2; const bool relative = g_config->getEditorLineNumber() == 2;
const QString &fg = vconfig.getEditorLineNumberFg(); const QString &fg = g_config->getEditorLineNumberFg();
painter.setPen(fg); painter.setPen(fg);
while (block.isValid() && top <= eventBtm) { while (block.isValid() && top <= eventBtm) {

View File

@ -8,7 +8,7 @@
#include "dialog/vfindreplacedialog.h" #include "dialog/vfindreplacedialog.h"
#include "utils/vutils.h" #include "utils/vutils.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
extern VNote *g_vnote; extern VNote *g_vnote;
VEditArea::VEditArea(VNote *vnote, QWidget *parent) VEditArea::VEditArea(VNote *vnote, QWidget *parent)
@ -26,13 +26,13 @@ void VEditArea::setupUI()
splitter = new QSplitter(this); splitter = new QSplitter(this);
m_findReplace = new VFindReplaceDialog(this); m_findReplace = new VFindReplaceDialog(this);
m_findReplace->setOption(FindOption::CaseSensitive, m_findReplace->setOption(FindOption::CaseSensitive,
vconfig.getFindCaseSensitive()); g_config->getFindCaseSensitive());
m_findReplace->setOption(FindOption::WholeWordOnly, m_findReplace->setOption(FindOption::WholeWordOnly,
vconfig.getFindWholeWordOnly()); g_config->getFindWholeWordOnly());
m_findReplace->setOption(FindOption::RegularExpression, m_findReplace->setOption(FindOption::RegularExpression,
vconfig.getFindRegularExpression()); g_config->getFindRegularExpression());
m_findReplace->setOption(FindOption::IncrementalSearch, m_findReplace->setOption(FindOption::IncrementalSearch,
vconfig.getFindIncrementalSearch()); g_config->getFindIncrementalSearch());
QVBoxLayout *mainLayout = new QVBoxLayout(); QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->addWidget(splitter); mainLayout->addWidget(splitter);
@ -513,10 +513,10 @@ void VEditArea::handleFindTextChanged(const QString &p_text, uint p_options)
void VEditArea::handleFindOptionChanged(uint p_options) void VEditArea::handleFindOptionChanged(uint p_options)
{ {
qDebug() << "find option changed" << p_options; qDebug() << "find option changed" << p_options;
vconfig.setFindCaseSensitive(p_options & FindOption::CaseSensitive); g_config->setFindCaseSensitive(p_options & FindOption::CaseSensitive);
vconfig.setFindWholeWordOnly(p_options & FindOption::WholeWordOnly); g_config->setFindWholeWordOnly(p_options & FindOption::WholeWordOnly);
vconfig.setFindRegularExpression(p_options & FindOption::RegularExpression); g_config->setFindRegularExpression(p_options & FindOption::RegularExpression);
vconfig.setFindIncrementalSearch(p_options & FindOption::IncrementalSearch); g_config->setFindIncrementalSearch(p_options & FindOption::IncrementalSearch);
} }
void VEditArea::handleFindNext(const QString &p_text, uint p_options, void VEditArea::handleFindNext(const QString &p_text, uint p_options,

View File

@ -6,7 +6,7 @@
#include "vconfigmanager.h" #include "vconfigmanager.h"
#include "utils/vutils.h" #include "utils/vutils.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VEditOperations::VEditOperations(VEdit *p_editor, VFile *p_file) VEditOperations::VEditOperations(VEdit *p_editor, VFile *p_file)
: QObject(p_editor), m_editor(p_editor), m_file(p_file), : QObject(p_editor), m_editor(p_editor), m_file(p_file),
@ -41,20 +41,20 @@ void VEditOperations::updateCursorLineBg()
if (m_editConfig->m_enableVimMode) { if (m_editConfig->m_enableVimMode) {
switch (m_vim->getMode()) { switch (m_vim->getMode()) {
case VimMode::Normal: case VimMode::Normal:
m_editConfig->m_cursorLineBg = QColor(vconfig.getEditorVimNormalBg()); m_editConfig->m_cursorLineBg = QColor(g_config->getEditorVimNormalBg());
break; break;
case VimMode::Insert: case VimMode::Insert:
m_editConfig->m_cursorLineBg = QColor(vconfig.getEditorVimInsertBg()); m_editConfig->m_cursorLineBg = QColor(g_config->getEditorVimInsertBg());
break; break;
case VimMode::Visual: case VimMode::Visual:
case VimMode::VisualLine: case VimMode::VisualLine:
m_editConfig->m_cursorLineBg = QColor(vconfig.getEditorVimVisualBg()); m_editConfig->m_cursorLineBg = QColor(g_config->getEditorVimVisualBg());
break; break;
case VimMode::Replace: case VimMode::Replace:
m_editConfig->m_cursorLineBg = QColor(vconfig.getEditorVimReplaceBg()); m_editConfig->m_cursorLineBg = QColor(g_config->getEditorVimReplaceBg());
break; break;
default: default:
@ -62,7 +62,7 @@ void VEditOperations::updateCursorLineBg()
break; break;
} }
} else { } else {
m_editConfig->m_cursorLineBg = QColor(vconfig.getEditorCurrentLineBg()); m_editConfig->m_cursorLineBg = QColor(g_config->getEditorCurrentLineBg());
} }
m_editor->highlightCurrentLine(); m_editor->highlightCurrentLine();

View File

@ -3,7 +3,6 @@
#include "veditwindow.h" #include "veditwindow.h"
#include "vedittab.h" #include "vedittab.h"
#include "vnote.h" #include "vnote.h"
#include "vconfigmanager.h"
#include "utils/vutils.h" #include "utils/vutils.h"
#include "vorphanfile.h" #include "vorphanfile.h"
#include "vmainwindow.h" #include "vmainwindow.h"
@ -13,7 +12,6 @@
#include "vhtmltab.h" #include "vhtmltab.h"
#include "vfilelist.h" #include "vfilelist.h"
extern VConfigManager vconfig;
extern VNote *g_vnote; extern VNote *g_vnote;
VEditWindow::VEditWindow(VNote *vnote, VEditArea *editArea, QWidget *parent) VEditWindow::VEditWindow(VNote *vnote, VEditArea *editArea, QWidget *parent)

View File

@ -23,7 +23,7 @@
#include "vmarkdownconverter.h" #include "vmarkdownconverter.h"
#include "vdocument.h" #include "vdocument.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
QString VExporter::s_defaultPathDir = QDir::homePath(); QString VExporter::s_defaultPathDir = QDir::homePath();
@ -183,7 +183,7 @@ void VExporter::exportNote(VFile *p_file, ExportType p_type)
} }
m_infoLabel->setText(tr("Export note <span style=\"%1\">%2</span> as %3.") m_infoLabel->setText(tr("Export note <span style=\"%1\">%2</span> as %3.")
.arg(vconfig.c_dataTextStyle) .arg(g_config->c_dataTextStyle)
.arg(m_file->getName()) .arg(m_file->getName())
.arg(exportTypeStr(p_type))); .arg(exportTypeStr(p_type)));
@ -218,7 +218,7 @@ void VExporter::initWebViewer(VFile *p_file)
VMarkdownConverter mdConverter; VMarkdownConverter mdConverter;
QString toc; QString toc;
QString html = mdConverter.generateHtml(p_file->getContent(), QString html = mdConverter.generateHtml(p_file->getContent(),
vconfig.getMarkdownExtensions(), g_config->getMarkdownExtensions(),
toc); toc);
document->setHtml(html); document->setHtml(html);
} }

View File

@ -11,7 +11,7 @@
#include "vfile.h" #include "vfile.h"
#include "vconfigmanager.h" #include "vconfigmanager.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
extern VNote *g_vnote; extern VNote *g_vnote;
VFileList::VFileList(QWidget *parent) VFileList::VFileList(QWidget *parent)
@ -161,7 +161,7 @@ void VFileList::fileInfo(VFile *p_file)
if (!p_file->rename(name)) { if (!p_file->rename(name)) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to rename note <span style=\"%1\">%2</span>.") tr("Fail to rename note <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(curName), "", .arg(g_config->c_dataTextStyle).arg(curName), "",
QMessageBox::Ok, QMessageBox::Ok, this); QMessageBox::Ok, QMessageBox::Ok, this);
return; return;
} }
@ -220,7 +220,7 @@ void VFileList::newFile()
return; return;
} }
QList<QString> suffixes = vconfig.getDocSuffixes()[(int)DocType::Markdown]; QList<QString> suffixes = g_config->getDocSuffixes()[(int)DocType::Markdown];
QString defaultSuf; QString defaultSuf;
QString suffixStr; QString suffixStr;
for (auto const & suf : suffixes) { for (auto const & suf : suffixes) {
@ -231,7 +231,7 @@ void VFileList::newFile()
} }
QString info = tr("Create a note in <span style=\"%1\">%2</span>.") QString info = tr("Create a note in <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(m_directory->getName()); .arg(g_config->c_dataTextStyle).arg(m_directory->getName());
info = info + "<br>" + tr("Note with name ending with \"%1\" will be treated as Markdown type.") info = info + "<br>" + tr("Note with name ending with \"%1\" will be treated as Markdown type.")
.arg(suffixStr); .arg(suffixStr);
QString text(tr("Note &name:")); QString text(tr("Note &name:"));
@ -251,7 +251,7 @@ void VFileList::newFile()
if (!file) { if (!file) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to create note <span style=\"%1\">%2</span>.") tr("Fail to create note <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(name), "", .arg(g_config->c_dataTextStyle).arg(name), "",
QMessageBox::Ok, QMessageBox::Ok, this); QMessageBox::Ok, QMessageBox::Ok, this);
return; return;
} }
@ -309,10 +309,10 @@ void VFileList::deleteFile(VFile *p_file)
QString fileName = p_file->getName(); QString fileName = p_file->getName();
int ret = VUtils::showMessage(QMessageBox::Warning, tr("Warning"), int ret = VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Are you sure to delete note <span style=\"%1\">%2</span>?") tr("Are you sure to delete note <span style=\"%1\">%2</span>?")
.arg(vconfig.c_dataTextStyle).arg(fileName), .arg(g_config->c_dataTextStyle).arg(fileName),
tr("<span style=\"%1\">WARNING</span>: The files (including images) " tr("<span style=\"%1\">WARNING</span>: The files (including images) "
"deleted may be UNRECOVERABLE!") "deleted may be UNRECOVERABLE!")
.arg(vconfig.c_warningTextStyle), .arg(g_config->c_warningTextStyle),
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok | QMessageBox::Cancel,
QMessageBox::Ok, this, MessageBoxType::Danger); QMessageBox::Ok, this, MessageBoxType::Danger);
if (ret == QMessageBox::Ok) { if (ret == QMessageBox::Ok) {
@ -486,7 +486,7 @@ void VFileList::pasteFiles(VDirectory *p_destDir)
} else { } else {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to copy note <span style=\"%1\">%2</span>.") tr("Fail to copy note <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(srcFile->getName()), .arg(g_config->c_dataTextStyle).arg(srcFile->getName()),
tr("Please check if there already exists a file with the same name in the target folder."), tr("Please check if there already exists a file with the same name in the target folder."),
QMessageBox::Ok, QMessageBox::Ok, this); QMessageBox::Ok, QMessageBox::Ok, this);
} }
@ -528,7 +528,7 @@ bool VFileList::promptForDocTypeChange(const VFile *p_file, const QString &p_new
int ret = VUtils::showMessage(QMessageBox::Warning, tr("Warning"), int ret = VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("The renaming will change the note type."), tr("The renaming will change the note type."),
tr("You should close the note <span style=\"%1\">%2</span> before continue.") tr("You should close the note <span style=\"%1\">%2</span> before continue.")
.arg(vconfig.c_dataTextStyle).arg(p_file->getName()), .arg(g_config->c_dataTextStyle).arg(p_file->getName()),
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok, this); QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok, this);
if (QMessageBox::Ok == ret) { if (QMessageBox::Ok == ret) {
if (!editArea->closeFile(p_file, false)) { if (!editArea->closeFile(p_file, false)) {

View File

@ -9,7 +9,7 @@
#include "veditarea.h" #include "veditarea.h"
#include "vconstants.h" #include "vconstants.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VHtmlTab::VHtmlTab(VFile *p_file, VEditArea *p_editArea, VHtmlTab::VHtmlTab(VFile *p_file, VEditArea *p_editArea,
OpenFileMode p_mode, QWidget *p_parent) OpenFileMode p_mode, QWidget *p_parent)
@ -120,7 +120,7 @@ void VHtmlTab::readFile()
// Prompt to save the changes. // Prompt to save the changes.
int ret = VUtils::showMessage(QMessageBox::Information, tr("Information"), int ret = VUtils::showMessage(QMessageBox::Information, tr("Information"),
tr("Note <span style=\"%1\">%2</span> has been modified.") tr("Note <span style=\"%1\">%2</span> has been modified.")
.arg(vconfig.c_dataTextStyle).arg(m_file->getName()), .arg(g_config->c_dataTextStyle).arg(m_file->getName()),
tr("Do you want to save your changes?"), tr("Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save, this); QMessageBox::Save, this);
@ -164,7 +164,7 @@ bool VHtmlTab::saveFile()
qWarning() << filePath << "being written has been removed"; qWarning() << filePath << "being written has been removed";
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), tr("Fail to save note."), VUtils::showMessage(QMessageBox::Warning, tr("Warning"), tr("Fail to save note."),
tr("File <span style=\"%1\">%2</span> being written has been removed.") tr("File <span style=\"%1\">%2</span> being written has been removed.")
.arg(vconfig.c_dataTextStyle).arg(filePath), .arg(g_config->c_dataTextStyle).arg(filePath),
QMessageBox::Ok, QMessageBox::Ok, this); QMessageBox::Ok, QMessageBox::Ok, this);
return false; return false;
} }

View File

@ -13,7 +13,7 @@
#include "vdownloader.h" #include "vdownloader.h"
#include "hgmarkdownhighlighter.h" #include "hgmarkdownhighlighter.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
enum ImageProperty { ImagePath = 1 }; enum ImageProperty { ImagePath = 1 };
@ -43,7 +43,7 @@ VImagePreviewer::VImagePreviewer(VMdEdit *p_edit, int p_timeToPreview)
void VImagePreviewer::timerTimeout() void VImagePreviewer::timerTimeout()
{ {
if (!vconfig.getEnablePreviewImages()) { if (!g_config->getEnablePreviewImages()) {
if (m_enablePreview) { if (m_enablePreview) {
disableImagePreview(); disableImagePreview();
} }
@ -355,7 +355,7 @@ void VImagePreviewer::enableImagePreview()
{ {
m_enablePreview = true; m_enablePreview = true;
if (vconfig.getEnablePreviewImages()) { if (g_config->getEnablePreviewImages()) {
m_timer->stop(); m_timer->stop();
m_timer->start(); m_timer->start();
} }
@ -542,7 +542,7 @@ bool VImagePreviewer::updateImageWidth(QTextImageFormat &p_format)
if (it != m_imageCache.end()) { if (it != m_imageCache.end()) {
int newWidth = it.value().m_width; int newWidth = it.value().m_width;
if (vconfig.getEnablePreviewImageConstraint()) { if (g_config->getEnablePreviewImageConstraint()) {
newWidth = qMin(m_imageWidth, it.value().m_width); newWidth = qMin(m_imageWidth, it.value().m_width);
} }

View File

@ -27,7 +27,7 @@
#include "dialog/vorphanfileinfodialog.h" #include "dialog/vorphanfileinfodialog.h"
#include "vsingleinstanceguard.h" #include "vsingleinstanceguard.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VNote *g_vnote; VNote *g_vnote;
@ -334,7 +334,7 @@ void VMainWindow::initFileToolBar(QSize p_iconSize)
newNoteAct = new QAction(QIcon(":/resources/icons/create_note_tb.svg"), newNoteAct = new QAction(QIcon(":/resources/icons/create_note_tb.svg"),
tr("New &Note"), this); tr("New &Note"), this);
newNoteAct->setStatusTip(tr("Create a note in current folder")); newNoteAct->setStatusTip(tr("Create a note in current folder"));
QString keySeq = vconfig.getShortcutKeySequence("NewNote"); QString keySeq = g_config->getShortcutKeySequence("NewNote");
qDebug() << "set NewNote shortcut to" << keySeq; qDebug() << "set NewNote shortcut to" << keySeq;
newNoteAct->setShortcut(QKeySequence(keySeq)); newNoteAct->setShortcut(QKeySequence(keySeq));
connect(newNoteAct, &QAction::triggered, connect(newNoteAct, &QAction::triggered,
@ -355,7 +355,7 @@ void VMainWindow::initFileToolBar(QSize p_iconSize)
m_closeNoteAct = new QAction(QIcon(":/resources/icons/close_note_tb.svg"), m_closeNoteAct = new QAction(QIcon(":/resources/icons/close_note_tb.svg"),
tr("&Close Note"), this); tr("&Close Note"), this);
m_closeNoteAct->setStatusTip(tr("Close current note")); m_closeNoteAct->setStatusTip(tr("Close current note"));
keySeq = vconfig.getShortcutKeySequence("CloseNote"); keySeq = g_config->getShortcutKeySequence("CloseNote");
qDebug() << "set CloseNote shortcut to" << keySeq; qDebug() << "set CloseNote shortcut to" << keySeq;
m_closeNoteAct->setShortcut(QKeySequence(keySeq)); m_closeNoteAct->setShortcut(QKeySequence(keySeq));
connect(m_closeNoteAct, &QAction::triggered, connect(m_closeNoteAct, &QAction::triggered,
@ -368,7 +368,7 @@ void VMainWindow::initFileToolBar(QSize p_iconSize)
editNoteAct = new QAction(QIcon(":/resources/icons/edit_note.svg"), editNoteAct = new QAction(QIcon(":/resources/icons/edit_note.svg"),
tr("&Edit"), this); tr("&Edit"), this);
editNoteAct->setStatusTip(tr("Edit current note")); editNoteAct->setStatusTip(tr("Edit current note"));
keySeq = vconfig.getShortcutKeySequence("EditNote"); keySeq = g_config->getShortcutKeySequence("EditNote");
qDebug() << "set EditNote shortcut to" << keySeq; qDebug() << "set EditNote shortcut to" << keySeq;
editNoteAct->setShortcut(QKeySequence(keySeq)); editNoteAct->setShortcut(QKeySequence(keySeq));
connect(editNoteAct, &QAction::triggered, connect(editNoteAct, &QAction::triggered,
@ -389,7 +389,7 @@ void VMainWindow::initFileToolBar(QSize p_iconSize)
tr("Save Changes And Read (Ctrl+T)"), this); tr("Save Changes And Read (Ctrl+T)"), this);
saveExitAct->setStatusTip(tr("Save changes and exit edit mode")); saveExitAct->setStatusTip(tr("Save changes and exit edit mode"));
saveExitAct->setMenu(exitEditMenu); saveExitAct->setMenu(exitEditMenu);
keySeq = vconfig.getShortcutKeySequence("SaveAndRead"); keySeq = g_config->getShortcutKeySequence("SaveAndRead");
qDebug() << "set SaveAndRead shortcut to" << keySeq; qDebug() << "set SaveAndRead shortcut to" << keySeq;
saveExitAct->setShortcut(QKeySequence(keySeq)); saveExitAct->setShortcut(QKeySequence(keySeq));
connect(saveExitAct, &QAction::triggered, connect(saveExitAct, &QAction::triggered,
@ -398,7 +398,7 @@ void VMainWindow::initFileToolBar(QSize p_iconSize)
saveNoteAct = new QAction(QIcon(":/resources/icons/save_note.svg"), saveNoteAct = new QAction(QIcon(":/resources/icons/save_note.svg"),
tr("Save"), this); tr("Save"), this);
saveNoteAct->setStatusTip(tr("Save changes to current note")); saveNoteAct->setStatusTip(tr("Save changes to current note"));
keySeq = vconfig.getShortcutKeySequence("SaveNote"); keySeq = g_config->getShortcutKeySequence("SaveNote");
qDebug() << "set SaveNote shortcut to" << keySeq; qDebug() << "set SaveNote shortcut to" << keySeq;
saveNoteAct->setShortcut(QKeySequence(keySeq)); saveNoteAct->setShortcut(QKeySequence(keySeq));
connect(saveNoteAct, &QAction::triggered, connect(saveNoteAct, &QAction::triggered,
@ -442,10 +442,10 @@ void VMainWindow::initHelpMenu()
#if defined(QT_NO_DEBUG) #if defined(QT_NO_DEBUG)
QAction *logAct = new QAction(tr("View &Log"), this); QAction *logAct = new QAction(tr("View &Log"), this);
logAct->setToolTip(tr("View VNote's debug log (%1)").arg(vconfig.getLogFilePath())); logAct->setToolTip(tr("View VNote's debug log (%1)").arg(g_config->getLogFilePath()));
connect(logAct, &QAction::triggered, connect(logAct, &QAction::triggered,
this, [](){ this, [](){
QUrl url = QUrl::fromLocalFile(vconfig.getLogFilePath()); QUrl url = QUrl::fromLocalFile(g_config->getLogFilePath());
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
}); });
#endif #endif
@ -555,7 +555,7 @@ void VMainWindow::initMarkdownMenu()
converterMenu->addAction(markdownitAct); converterMenu->addAction(markdownitAct);
converterMenu->addAction(showdownAct); converterMenu->addAction(showdownAct);
MarkdownConverterType converterType = vconfig.getMdConverterType(); MarkdownConverterType converterType = g_config->getMdConverterType();
switch (converterType) { switch (converterType) {
case MarkdownConverterType::Marked: case MarkdownConverterType::Marked:
markedAct->setChecked(true); markedAct->setChecked(true);
@ -587,7 +587,7 @@ void VMainWindow::initMarkdownMenu()
connect(constrainImageAct, &QAction::triggered, connect(constrainImageAct, &QAction::triggered,
this, &VMainWindow::enableImageConstraint); this, &VMainWindow::enableImageConstraint);
markdownMenu->addAction(constrainImageAct); markdownMenu->addAction(constrainImageAct);
constrainImageAct->setChecked(vconfig.getEnableImageConstraint()); constrainImageAct->setChecked(g_config->getEnableImageConstraint());
QAction *imageCaptionAct = new QAction(tr("Enable Image Caption"), this); QAction *imageCaptionAct = new QAction(tr("Enable Image Caption"), this);
imageCaptionAct->setToolTip(tr("Center the images and display the alt text as caption (re-open current tabs to make it work)")); imageCaptionAct->setToolTip(tr("Center the images and display the alt text as caption (re-open current tabs to make it work)"));
@ -595,7 +595,7 @@ void VMainWindow::initMarkdownMenu()
connect(imageCaptionAct, &QAction::triggered, connect(imageCaptionAct, &QAction::triggered,
this, &VMainWindow::enableImageCaption); this, &VMainWindow::enableImageCaption);
markdownMenu->addAction(imageCaptionAct); markdownMenu->addAction(imageCaptionAct);
imageCaptionAct->setChecked(vconfig.getEnableImageCaption()); imageCaptionAct->setChecked(g_config->getEnableImageCaption());
markdownMenu->addSeparator(); markdownMenu->addSeparator();
@ -606,17 +606,17 @@ void VMainWindow::initMarkdownMenu()
this, &VMainWindow::enableMermaid); this, &VMainWindow::enableMermaid);
markdownMenu->addAction(mermaidAct); markdownMenu->addAction(mermaidAct);
mermaidAct->setChecked(vconfig.getEnableMermaid()); mermaidAct->setChecked(g_config->getEnableMermaid());
QAction *flowchartAct = new QAction(tr("&Flowchart.js"), this); QAction *flowchartAct = new QAction(tr("&Flowchart.js"), this);
flowchartAct->setToolTip(tr("Enable Flowchart.js for flowchart diagram")); flowchartAct->setToolTip(tr("Enable Flowchart.js for flowchart diagram"));
flowchartAct->setCheckable(true); flowchartAct->setCheckable(true);
connect(flowchartAct, &QAction::triggered, connect(flowchartAct, &QAction::triggered,
this, [this](bool p_enabled){ this, [this](bool p_enabled){
vconfig.setEnableFlowchart(p_enabled); g_config->setEnableFlowchart(p_enabled);
}); });
markdownMenu->addAction(flowchartAct); markdownMenu->addAction(flowchartAct);
flowchartAct->setChecked(vconfig.getEnableFlowchart()); flowchartAct->setChecked(g_config->getEnableFlowchart());
QAction *mathjaxAct = new QAction(tr("Math&Jax"), this); QAction *mathjaxAct = new QAction(tr("Math&Jax"), this);
mathjaxAct->setToolTip(tr("Enable MathJax for math support in Markdown")); mathjaxAct->setToolTip(tr("Enable MathJax for math support in Markdown"));
@ -625,7 +625,7 @@ void VMainWindow::initMarkdownMenu()
this, &VMainWindow::enableMathjax); this, &VMainWindow::enableMathjax);
markdownMenu->addAction(mathjaxAct); markdownMenu->addAction(mathjaxAct);
mathjaxAct->setChecked(vconfig.getEnableMathjax()); mathjaxAct->setChecked(g_config->getEnableMathjax());
markdownMenu->addSeparator(); markdownMenu->addSeparator();
@ -635,7 +635,7 @@ void VMainWindow::initMarkdownMenu()
connect(codeBlockAct, &QAction::triggered, connect(codeBlockAct, &QAction::triggered,
this, &VMainWindow::enableCodeBlockHighlight); this, &VMainWindow::enableCodeBlockHighlight);
markdownMenu->addAction(codeBlockAct); markdownMenu->addAction(codeBlockAct);
codeBlockAct->setChecked(vconfig.getEnableCodeBlockHighlight()); codeBlockAct->setChecked(g_config->getEnableCodeBlockHighlight());
QAction *previewImageAct = new QAction(tr("Preview Images In Edit Mode"), this); QAction *previewImageAct = new QAction(tr("Preview Images In Edit Mode"), this);
previewImageAct->setToolTip(tr("Enable image preview in edit mode")); previewImageAct->setToolTip(tr("Enable image preview in edit mode"));
@ -644,7 +644,7 @@ void VMainWindow::initMarkdownMenu()
this, &VMainWindow::enableImagePreview); this, &VMainWindow::enableImagePreview);
// TODO: add the action to the menu after handling the UNDO history well. // TODO: add the action to the menu after handling the UNDO history well.
// markdownMenu->addAction(previewImageAct); // markdownMenu->addAction(previewImageAct);
previewImageAct->setChecked(vconfig.getEnablePreviewImages()); previewImageAct->setChecked(g_config->getEnablePreviewImages());
QAction *previewWidthAct = new QAction(tr("Constrain The Width Of Previewed Images"), this); QAction *previewWidthAct = new QAction(tr("Constrain The Width Of Previewed Images"), this);
previewWidthAct->setToolTip(tr("Constrain the width of previewed images to the edit window in edit mode")); previewWidthAct->setToolTip(tr("Constrain the width of previewed images to the edit window in edit mode"));
@ -652,7 +652,7 @@ void VMainWindow::initMarkdownMenu()
connect(previewWidthAct, &QAction::triggered, connect(previewWidthAct, &QAction::triggered,
this, &VMainWindow::enableImagePreviewConstraint); this, &VMainWindow::enableImagePreviewConstraint);
markdownMenu->addAction(previewWidthAct); markdownMenu->addAction(previewWidthAct);
previewWidthAct->setChecked(vconfig.getEnablePreviewImageConstraint()); previewWidthAct->setChecked(g_config->getEnablePreviewImageConstraint());
} }
void VMainWindow::initViewMenu() void VMainWindow::initViewMenu()
@ -747,9 +747,9 @@ void VMainWindow::initFileMenu()
if (ret == QMessageBox::Ok) { if (ret == QMessageBox::Ok) {
#if defined(Q_OS_MACOS) || defined(Q_OS_MAC) #if defined(Q_OS_MACOS) || defined(Q_OS_MAC)
// On macOS, it seems that we could not open that ini file directly. // On macOS, it seems that we could not open that ini file directly.
QUrl url = QUrl::fromLocalFile(vconfig.getConfigFolder()); QUrl url = QUrl::fromLocalFile(g_config->getConfigFolder());
#else #else
QUrl url = QUrl::fromLocalFile(vconfig.getConfigFilePath()); QUrl url = QUrl::fromLocalFile(g_config->getConfigFilePath());
#endif #endif
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
} }
@ -792,7 +792,7 @@ void VMainWindow::initEditMenu()
m_findReplaceAct = newAction(QIcon(":/resources/icons/find_replace.svg"), m_findReplaceAct = newAction(QIcon(":/resources/icons/find_replace.svg"),
tr("Find/Replace"), this); tr("Find/Replace"), this);
m_findReplaceAct->setToolTip(tr("Open Find/Replace dialog to search in current note")); m_findReplaceAct->setToolTip(tr("Open Find/Replace dialog to search in current note"));
QString keySeq = vconfig.getShortcutKeySequence("Find"); QString keySeq = g_config->getShortcutKeySequence("Find");
qDebug() << "set Find shortcut to" << keySeq; qDebug() << "set Find shortcut to" << keySeq;
m_findReplaceAct->setShortcut(QKeySequence(keySeq)); m_findReplaceAct->setShortcut(QKeySequence(keySeq));
connect(m_findReplaceAct, &QAction::triggered, connect(m_findReplaceAct, &QAction::triggered,
@ -800,7 +800,7 @@ void VMainWindow::initEditMenu()
m_findNextAct = new QAction(tr("Find Next"), this); m_findNextAct = new QAction(tr("Find Next"), this);
m_findNextAct->setToolTip(tr("Find next occurence")); m_findNextAct->setToolTip(tr("Find next occurence"));
keySeq = vconfig.getShortcutKeySequence("FindNext"); keySeq = g_config->getShortcutKeySequence("FindNext");
qDebug() << "set FindNext shortcut to" << keySeq; qDebug() << "set FindNext shortcut to" << keySeq;
m_findNextAct->setShortcut(QKeySequence(keySeq)); m_findNextAct->setShortcut(QKeySequence(keySeq));
connect(m_findNextAct, SIGNAL(triggered(bool)), connect(m_findNextAct, SIGNAL(triggered(bool)),
@ -808,7 +808,7 @@ void VMainWindow::initEditMenu()
m_findPreviousAct = new QAction(tr("Find Previous"), this); m_findPreviousAct = new QAction(tr("Find Previous"), this);
m_findPreviousAct->setToolTip(tr("Find previous occurence")); m_findPreviousAct->setToolTip(tr("Find previous occurence"));
keySeq = vconfig.getShortcutKeySequence("FindPrevious"); keySeq = g_config->getShortcutKeySequence("FindPrevious");
qDebug() << "set FindPrevious shortcut to" << keySeq; qDebug() << "set FindPrevious shortcut to" << keySeq;
m_findPreviousAct->setShortcut(QKeySequence(keySeq)); m_findPreviousAct->setShortcut(QKeySequence(keySeq));
connect(m_findPreviousAct, SIGNAL(triggered(bool)), connect(m_findPreviousAct, SIGNAL(triggered(bool)),
@ -886,7 +886,7 @@ void VMainWindow::initEditMenu()
smartImAct->setCheckable(true); smartImAct->setCheckable(true);
connect(smartImAct, &QAction::triggered, connect(smartImAct, &QAction::triggered,
this, [this](bool p_checked){ this, [this](bool p_checked){
vconfig.setEnableSmartImInVimMode(p_checked); g_config->setEnableSmartImInVimMode(p_checked);
}); });
// Highlight current cursor line. // Highlight current cursor line.
@ -924,7 +924,7 @@ void VMainWindow::initEditMenu()
findReplaceMenu->addAction(m_replaceAllAct); findReplaceMenu->addAction(m_replaceAllAct);
findReplaceMenu->addSeparator(); findReplaceMenu->addSeparator();
findReplaceMenu->addAction(searchedWordAct); findReplaceMenu->addAction(searchedWordAct);
searchedWordAct->setChecked(vconfig.getHighlightSearchedWord()); searchedWordAct->setChecked(g_config->getHighlightSearchedWord());
m_findReplaceAct->setEnabled(false); m_findReplaceAct->setEnabled(false);
m_findNextAct->setEnabled(false); m_findNextAct->setEnabled(false);
@ -935,7 +935,7 @@ void VMainWindow::initEditMenu()
editMenu->addSeparator(); editMenu->addSeparator();
editMenu->addAction(expandTabAct); editMenu->addAction(expandTabAct);
if (vconfig.getIsExpandTab()) { if (g_config->getIsExpandTab()) {
expandTabAct->setChecked(true); expandTabAct->setChecked(true);
} else { } else {
expandTabAct->setChecked(false); expandTabAct->setChecked(false);
@ -946,7 +946,7 @@ void VMainWindow::initEditMenu()
tabStopWidthMenu->addAction(twoSpaceTabAct); tabStopWidthMenu->addAction(twoSpaceTabAct);
tabStopWidthMenu->addAction(fourSpaceTabAct); tabStopWidthMenu->addAction(fourSpaceTabAct);
tabStopWidthMenu->addAction(eightSpaceTabAct); tabStopWidthMenu->addAction(eightSpaceTabAct);
int tabStopWidth = vconfig.getTabStopWidth(); int tabStopWidth = g_config->getTabStopWidth();
switch (tabStopWidth) { switch (tabStopWidth) {
case 2: case 2:
twoSpaceTabAct->setChecked(true); twoSpaceTabAct->setChecked(true);
@ -962,20 +962,20 @@ void VMainWindow::initEditMenu()
} }
editMenu->addAction(m_autoIndentAct); editMenu->addAction(m_autoIndentAct);
m_autoIndentAct->setChecked(vconfig.getAutoIndent()); m_autoIndentAct->setChecked(g_config->getAutoIndent());
editMenu->addAction(autoListAct); editMenu->addAction(autoListAct);
if (vconfig.getAutoList()) { if (g_config->getAutoList()) {
// Let the trigger handler to trigger m_autoIndentAct, too. // Let the trigger handler to trigger m_autoIndentAct, too.
autoListAct->trigger(); autoListAct->trigger();
} }
Q_ASSERT(!(autoListAct->isChecked() && !m_autoIndentAct->isChecked())); Q_ASSERT(!(autoListAct->isChecked() && !m_autoIndentAct->isChecked()));
editMenu->addAction(vimAct); editMenu->addAction(vimAct);
vimAct->setChecked(vconfig.getEnableVimMode()); vimAct->setChecked(g_config->getEnableVimMode());
editMenu->addAction(smartImAct); editMenu->addAction(smartImAct);
smartImAct->setChecked(vconfig.getEnableSmartImInVimMode()); smartImAct->setChecked(g_config->getEnableSmartImInVimMode());
editMenu->addSeparator(); editMenu->addSeparator();
@ -986,13 +986,13 @@ void VMainWindow::initEditMenu()
initEditorLineNumberMenu(editMenu); initEditorLineNumberMenu(editMenu);
editMenu->addAction(cursorLineAct); editMenu->addAction(cursorLineAct);
cursorLineAct->setChecked(vconfig.getHighlightCursorLine()); cursorLineAct->setChecked(g_config->getHighlightCursorLine());
editMenu->addAction(selectedWordAct); editMenu->addAction(selectedWordAct);
selectedWordAct->setChecked(vconfig.getHighlightSelectedWord()); selectedWordAct->setChecked(g_config->getHighlightSelectedWord());
editMenu->addAction(trailingSapceAct); editMenu->addAction(trailingSapceAct);
trailingSapceAct->setChecked(vconfig.getEnableTrailingSpaceHighlight()); trailingSapceAct->setChecked(g_config->getEnableTrailingSpaceHighlight());
} }
void VMainWindow::initDockWindows() void VMainWindow::initDockWindows()
@ -1068,7 +1068,7 @@ void VMainWindow::changeMarkdownConverter(QAction *action)
qDebug() << "switch to converter" << type; qDebug() << "switch to converter" << type;
vconfig.setMarkdownConverterType(type); g_config->setMarkdownConverterType(type);
} }
void VMainWindow::aboutMessage() void VMainWindow::aboutMessage()
@ -1083,37 +1083,37 @@ void VMainWindow::aboutMessage()
void VMainWindow::changeExpandTab(bool checked) void VMainWindow::changeExpandTab(bool checked)
{ {
vconfig.setIsExpandTab(checked); g_config->setIsExpandTab(checked);
} }
void VMainWindow::enableMermaid(bool p_checked) void VMainWindow::enableMermaid(bool p_checked)
{ {
vconfig.setEnableMermaid(p_checked); g_config->setEnableMermaid(p_checked);
} }
void VMainWindow::enableMathjax(bool p_checked) void VMainWindow::enableMathjax(bool p_checked)
{ {
vconfig.setEnableMathjax(p_checked); g_config->setEnableMathjax(p_checked);
} }
void VMainWindow::changeHighlightCursorLine(bool p_checked) void VMainWindow::changeHighlightCursorLine(bool p_checked)
{ {
vconfig.setHighlightCursorLine(p_checked); g_config->setHighlightCursorLine(p_checked);
} }
void VMainWindow::changeHighlightSelectedWord(bool p_checked) void VMainWindow::changeHighlightSelectedWord(bool p_checked)
{ {
vconfig.setHighlightSelectedWord(p_checked); g_config->setHighlightSelectedWord(p_checked);
} }
void VMainWindow::changeHighlightSearchedWord(bool p_checked) void VMainWindow::changeHighlightSearchedWord(bool p_checked)
{ {
vconfig.setHighlightSearchedWord(p_checked); g_config->setHighlightSearchedWord(p_checked);
} }
void VMainWindow::changeHighlightTrailingSapce(bool p_checked) void VMainWindow::changeHighlightTrailingSapce(bool p_checked)
{ {
vconfig.setEnableTrailingSapceHighlight(p_checked); g_config->setEnableTrailingSapceHighlight(p_checked);
} }
void VMainWindow::setTabStopWidth(QAction *action) void VMainWindow::setTabStopWidth(QAction *action)
@ -1121,7 +1121,7 @@ void VMainWindow::setTabStopWidth(QAction *action)
if (!action) { if (!action) {
return; return;
} }
vconfig.setTabStopWidth(action->data().toInt()); g_config->setTabStopWidth(action->data().toInt());
} }
void VMainWindow::setEditorBackgroundColor(QAction *action) void VMainWindow::setEditorBackgroundColor(QAction *action)
@ -1130,12 +1130,12 @@ void VMainWindow::setEditorBackgroundColor(QAction *action)
return; return;
} }
vconfig.setCurBackgroundColor(action->data().toString()); g_config->setCurBackgroundColor(action->data().toString());
} }
void VMainWindow::initPredefinedColorPixmaps() void VMainWindow::initPredefinedColorPixmaps()
{ {
const QVector<VColor> &bgColors = vconfig.getPredefinedColors(); const QVector<VColor> &bgColors = g_config->getPredefinedColors();
predefinedColorPixmaps.clear(); predefinedColorPixmaps.clear();
int size = 256; int size = 256;
for (int i = 0; i < bgColors.size(); ++i) { for (int i = 0; i < bgColors.size(); ++i) {
@ -1155,7 +1155,7 @@ void VMainWindow::initRenderBackgroundMenu(QMenu *menu)
QMenu *renderBgMenu = menu->addMenu(tr("&Rendering Background")); QMenu *renderBgMenu = menu->addMenu(tr("&Rendering Background"));
renderBgMenu->setToolTipsVisible(true); renderBgMenu->setToolTipsVisible(true);
const QString &curBgColor = vconfig.getCurRenderBackgroundColor(); const QString &curBgColor = g_config->getCurRenderBackgroundColor();
QAction *tmpAct = new QAction(tr("System"), renderBackgroundAct); QAction *tmpAct = new QAction(tr("System"), renderBackgroundAct);
tmpAct->setToolTip(tr("Use system's background color configuration for Markdown rendering")); tmpAct->setToolTip(tr("Use system's background color configuration for Markdown rendering"));
tmpAct->setCheckable(true); tmpAct->setCheckable(true);
@ -1165,7 +1165,7 @@ void VMainWindow::initRenderBackgroundMenu(QMenu *menu)
} }
renderBgMenu->addAction(tmpAct); renderBgMenu->addAction(tmpAct);
const QVector<VColor> &bgColors = vconfig.getPredefinedColors(); const QVector<VColor> &bgColors = g_config->getPredefinedColors();
for (int i = 0; i < bgColors.size(); ++i) { for (int i = 0; i < bgColors.size(); ++i) {
tmpAct = new QAction(bgColors[i].name, renderBackgroundAct); tmpAct = new QAction(bgColors[i].name, renderBackgroundAct);
tmpAct->setToolTip(tr("Set as the background color for Markdown rendering")); tmpAct->setToolTip(tr("Set as the background color for Markdown rendering"));
@ -1198,7 +1198,7 @@ void VMainWindow::updateRenderStyleMenu()
} }
// Update the menu actions with styles. // Update the menu actions with styles.
QVector<QString> styles = vconfig.getCssStyles(); QVector<QString> styles = g_config->getCssStyles();
for (auto const &style : styles) { for (auto const &style : styles) {
QAction *act = new QAction(style, m_renderStyleActs); QAction *act = new QAction(style, m_renderStyleActs);
act->setToolTip(tr("Set as the CSS style for Markdown rendering")); act->setToolTip(tr("Set as the CSS style for Markdown rendering"));
@ -1208,7 +1208,7 @@ void VMainWindow::updateRenderStyleMenu()
// Add it to the menu. // Add it to the menu.
menu->addAction(act); menu->addAction(act);
if (vconfig.getTemplateCss() == style) { if (g_config->getTemplateCss() == style) {
act->setChecked(true); act->setChecked(true);
} }
} }
@ -1244,7 +1244,7 @@ void VMainWindow::initEditorBackgroundMenu(QMenu *menu)
this, &VMainWindow::setEditorBackgroundColor); this, &VMainWindow::setEditorBackgroundColor);
// System background color // System background color
const QString &curBgColor = vconfig.getCurBackgroundColor(); const QString &curBgColor = g_config->getCurBackgroundColor();
QAction *tmpAct = new QAction(tr("System"), backgroundColorAct); QAction *tmpAct = new QAction(tr("System"), backgroundColorAct);
tmpAct->setToolTip(tr("Use system's background color configuration for editor")); tmpAct->setToolTip(tr("Use system's background color configuration for editor"));
tmpAct->setCheckable(true); tmpAct->setCheckable(true);
@ -1253,7 +1253,7 @@ void VMainWindow::initEditorBackgroundMenu(QMenu *menu)
tmpAct->setChecked(true); tmpAct->setChecked(true);
} }
backgroundColorMenu->addAction(tmpAct); backgroundColorMenu->addAction(tmpAct);
const QVector<VColor> &bgColors = vconfig.getPredefinedColors(); const QVector<VColor> &bgColors = g_config->getPredefinedColors();
for (int i = 0; i < bgColors.size(); ++i) { for (int i = 0; i < bgColors.size(); ++i) {
tmpAct = new QAction(bgColors[i].name, backgroundColorAct); tmpAct = new QAction(bgColors[i].name, backgroundColorAct);
tmpAct->setToolTip(tr("Set as the background color for editor")); tmpAct->setToolTip(tr("Set as the background color for editor"));
@ -1282,10 +1282,10 @@ void VMainWindow::initEditorLineNumberMenu(QMenu *p_menu)
return; return;
} }
vconfig.setEditorLineNumber(p_action->data().toInt()); g_config->setEditorLineNumber(p_action->data().toInt());
}); });
int lineNumberMode = vconfig.getEditorLineNumber(); int lineNumberMode = g_config->getEditorLineNumber();
QAction *act = lineNumAct->addAction(tr("None")); QAction *act = lineNumAct->addAction(tr("None"));
act->setToolTip(tr("Do not display line number in edit mode")); act->setToolTip(tr("Do not display line number in edit mode"));
@ -1329,7 +1329,7 @@ void VMainWindow::updateEditorStyleMenu()
} }
// Update the menu actions with styles. // Update the menu actions with styles.
QVector<QString> styles = vconfig.getEditorStyles(); QVector<QString> styles = g_config->getEditorStyles();
for (auto const &style : styles) { for (auto const &style : styles) {
QAction *act = new QAction(style, m_editorStyleActs); QAction *act = new QAction(style, m_editorStyleActs);
act->setToolTip(tr("Set as the editor style")); act->setToolTip(tr("Set as the editor style"));
@ -1339,7 +1339,7 @@ void VMainWindow::updateEditorStyleMenu()
// Add it to the menu. // Add it to the menu.
menu->addAction(act); menu->addAction(act);
if (vconfig.getEditorStyle() == style) { if (g_config->getEditorStyle() == style) {
act->setChecked(true); act->setChecked(true);
} }
} }
@ -1370,7 +1370,7 @@ void VMainWindow::setRenderBackgroundColor(QAction *action)
if (!action) { if (!action) {
return; return;
} }
vconfig.setCurRenderBackgroundColor(action->data().toString()); g_config->setCurRenderBackgroundColor(action->data().toString());
vnote->updateTemplate(); vnote->updateTemplate();
} }
@ -1383,10 +1383,10 @@ void VMainWindow::setRenderStyle(QAction *p_action)
QString data = p_action->data().toString(); QString data = p_action->data().toString();
if (data == "AddStyle") { if (data == "AddStyle") {
// Add custom style. // Add custom style.
QUrl url = QUrl::fromLocalFile(vconfig.getStyleConfigFolder()); QUrl url = QUrl::fromLocalFile(g_config->getStyleConfigFolder());
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
} else { } else {
vconfig.setTemplateCss(data); g_config->setTemplateCss(data);
vnote->updateTemplate(); vnote->updateTemplate();
} }
} }
@ -1400,10 +1400,10 @@ void VMainWindow::setEditorStyle(QAction *p_action)
QString data = p_action->data().toString(); QString data = p_action->data().toString();
if (data == "AddStyle") { if (data == "AddStyle") {
// Add custom style. // Add custom style.
QUrl url = QUrl::fromLocalFile(vconfig.getStyleConfigFolder()); QUrl url = QUrl::fromLocalFile(g_config->getStyleConfigFolder());
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
} else { } else {
vconfig.setEditorStyle(data); g_config->setEditorStyle(data);
} }
} }
@ -1573,7 +1573,7 @@ void VMainWindow::deleteCurNote()
void VMainWindow::closeEvent(QCloseEvent *event) void VMainWindow::closeEvent(QCloseEvent *event)
{ {
bool isExit = m_requestQuit || !vconfig.getMinimizeToStystemTray(); bool isExit = m_requestQuit || !g_config->getMinimizeToStystemTray();
m_requestQuit = false; m_requestQuit = false;
#if defined(Q_OS_MACOS) || defined(Q_OS_MAC) #if defined(Q_OS_MACOS) || defined(Q_OS_MAC)
@ -1581,7 +1581,7 @@ void VMainWindow::closeEvent(QCloseEvent *event)
isExit = true; isExit = true;
#endif #endif
if (!isExit && vconfig.getMinimizeToStystemTray() == -1) { if (!isExit && g_config->getMinimizeToStystemTray() == -1) {
// Not initialized yet. Prompt for user. // Not initialized yet. Prompt for user.
int ret = VUtils::showMessage(QMessageBox::Information, int ret = VUtils::showMessage(QMessageBox::Information,
tr("Close VNote"), tr("Close VNote"),
@ -1592,9 +1592,9 @@ void VMainWindow::closeEvent(QCloseEvent *event)
QMessageBox::Ok, QMessageBox::Ok,
this); this);
if (ret == QMessageBox::Ok) { if (ret == QMessageBox::Ok) {
vconfig.setMinimizeToSystemTray(1); g_config->setMinimizeToSystemTray(1);
} else if (ret == QMessageBox::No) { } else if (ret == QMessageBox::No) {
vconfig.setMinimizeToSystemTray(0); g_config->setMinimizeToSystemTray(0);
isExit = true; isExit = true;
} else { } else {
event->ignore(); event->ignore();
@ -1626,24 +1626,24 @@ void VMainWindow::saveStateAndGeometry()
// panel has a width of zero. // panel has a width of zero.
twoPanelView(); twoPanelView();
vconfig.setMainWindowGeometry(saveGeometry()); g_config->setMainWindowGeometry(saveGeometry());
vconfig.setMainWindowState(saveState()); g_config->setMainWindowState(saveState());
vconfig.setToolsDockChecked(toolDock->isVisible()); g_config->setToolsDockChecked(toolDock->isVisible());
vconfig.setMainSplitterState(mainSplitter->saveState()); g_config->setMainSplitterState(mainSplitter->saveState());
} }
void VMainWindow::restoreStateAndGeometry() void VMainWindow::restoreStateAndGeometry()
{ {
const QByteArray &geometry = vconfig.getMainWindowGeometry(); const QByteArray &geometry = g_config->getMainWindowGeometry();
if (!geometry.isEmpty()) { if (!geometry.isEmpty()) {
restoreGeometry(geometry); restoreGeometry(geometry);
} }
const QByteArray &state = vconfig.getMainWindowState(); const QByteArray &state = g_config->getMainWindowState();
if (!state.isEmpty()) { if (!state.isEmpty()) {
restoreState(state); restoreState(state);
} }
toolDock->setVisible(vconfig.getToolsDockChecked()); toolDock->setVisible(g_config->getToolsDockChecked());
const QByteArray &splitterState = vconfig.getMainSplitterState(); const QByteArray &splitterState = g_config->getMainSplitterState();
if (!splitterState.isEmpty()) { if (!splitterState.isEmpty()) {
mainSplitter->restoreState(splitterState); mainSplitter->restoreState(splitterState);
} }
@ -1781,12 +1781,12 @@ void VMainWindow::closeCurrentFile()
void VMainWindow::changeAutoIndent(bool p_checked) void VMainWindow::changeAutoIndent(bool p_checked)
{ {
vconfig.setAutoIndent(p_checked); g_config->setAutoIndent(p_checked);
} }
void VMainWindow::changeAutoList(bool p_checked) void VMainWindow::changeAutoList(bool p_checked)
{ {
vconfig.setAutoList(p_checked); g_config->setAutoList(p_checked);
if (p_checked) { if (p_checked) {
if (!m_autoIndentAct->isChecked()) { if (!m_autoIndentAct->isChecked()) {
m_autoIndentAct->trigger(); m_autoIndentAct->trigger();
@ -1799,34 +1799,34 @@ void VMainWindow::changeAutoList(bool p_checked)
void VMainWindow::changeVimMode(bool p_checked) void VMainWindow::changeVimMode(bool p_checked)
{ {
vconfig.setEnableVimMode(p_checked); g_config->setEnableVimMode(p_checked);
} }
void VMainWindow::enableCodeBlockHighlight(bool p_checked) void VMainWindow::enableCodeBlockHighlight(bool p_checked)
{ {
vconfig.setEnableCodeBlockHighlight(p_checked); g_config->setEnableCodeBlockHighlight(p_checked);
} }
void VMainWindow::enableImagePreview(bool p_checked) void VMainWindow::enableImagePreview(bool p_checked)
{ {
vconfig.setEnablePreviewImages(p_checked); g_config->setEnablePreviewImages(p_checked);
} }
void VMainWindow::enableImagePreviewConstraint(bool p_checked) void VMainWindow::enableImagePreviewConstraint(bool p_checked)
{ {
vconfig.setEnablePreviewImageConstraint(p_checked); g_config->setEnablePreviewImageConstraint(p_checked);
} }
void VMainWindow::enableImageConstraint(bool p_checked) void VMainWindow::enableImageConstraint(bool p_checked)
{ {
vconfig.setEnableImageConstraint(p_checked); g_config->setEnableImageConstraint(p_checked);
vnote->updateTemplate(); vnote->updateTemplate();
} }
void VMainWindow::enableImageCaption(bool p_checked) void VMainWindow::enableImageCaption(bool p_checked)
{ {
vconfig.setEnableImageCaption(p_checked); g_config->setEnableImageCaption(p_checked);
} }
void VMainWindow::shortcutHelp() void VMainWindow::shortcutHelp()

View File

@ -10,7 +10,7 @@
#include "dialog/vselectdialog.h" #include "dialog/vselectdialog.h"
#include "vimagepreviewer.h" #include "vimagepreviewer.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
extern VNote *g_vnote; extern VNote *g_vnote;
VMdEdit::VMdEdit(VFile *p_file, VDocument *p_vdoc, MarkdownConverterType p_type, VMdEdit::VMdEdit(VFile *p_file, VDocument *p_vdoc, MarkdownConverterType p_type,
@ -20,8 +20,8 @@ VMdEdit::VMdEdit(VFile *p_file, VDocument *p_vdoc, MarkdownConverterType p_type,
V_ASSERT(p_file->getDocType() == DocType::Markdown); V_ASSERT(p_file->getDocType() == DocType::Markdown);
setAcceptRichText(false); setAcceptRichText(false);
m_mdHighlighter = new HGMarkdownHighlighter(vconfig.getMdHighlightingStyles(), m_mdHighlighter = new HGMarkdownHighlighter(g_config->getMdHighlightingStyles(),
vconfig.getCodeBlockStyles(), g_config->getCodeBlockStyles(),
700, document()); 700, document());
connect(m_mdHighlighter, &HGMarkdownHighlighter::highlightCompleted, connect(m_mdHighlighter, &HGMarkdownHighlighter::highlightCompleted,
this, &VMdEdit::generateEditOutline); this, &VMdEdit::generateEditOutline);
@ -60,8 +60,8 @@ VMdEdit::VMdEdit(VFile *p_file, VDocument *p_vdoc, MarkdownConverterType p_type,
void VMdEdit::updateFontAndPalette() void VMdEdit::updateFontAndPalette()
{ {
setFont(vconfig.getMdEditFont()); setFont(g_config->getMdEditFont());
setPalette(vconfig.getMdEditPalette()); setPalette(g_config->getMdEditPalette());
} }
void VMdEdit::beginEdit() void VMdEdit::beginEdit()
@ -392,7 +392,7 @@ int VMdEdit::removeObjectReplacementLine(QString &p_text, int p_index) const
void VMdEdit::handleSelectionChanged() void VMdEdit::handleSelectionChanged()
{ {
if (!vconfig.getEnablePreviewImages()) { if (!g_config->getEnablePreviewImages()) {
return; return;
} }

View File

@ -24,7 +24,7 @@
#include "utils/vvim.h" #include "utils/vvim.h"
#include "utils/veditutils.h" #include "utils/veditutils.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
const QString VMdEditOperations::c_defaultImageTitle = "image"; const QString VMdEditOperations::c_defaultImageTitle = "image";
@ -63,18 +63,18 @@ void VMdEditOperations::insertImageFromQImage(const QString &title, const QStrin
bool ret = VUtils::makePath(path); bool ret = VUtils::makePath(path);
if (!ret) { if (!ret) {
errStr = tr("Fail to create image folder <span style=\"%1\">%2</span>.") errStr = tr("Fail to create image folder <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(path); .arg(g_config->c_dataTextStyle).arg(path);
} else { } else {
ret = image.save(filePath); ret = image.save(filePath);
if (!ret) { if (!ret) {
errStr = tr("Fail to save image <span style=\"%1\">%2</span>.") errStr = tr("Fail to save image <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(filePath); .arg(g_config->c_dataTextStyle).arg(filePath);
} }
} }
if (!ret) { if (!ret) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to insert image <span style=\"%1\">%2</span>.").arg(vconfig.c_dataTextStyle).arg(title), tr("Fail to insert image <span style=\"%1\">%2</span>.").arg(g_config->c_dataTextStyle).arg(title),
errStr, errStr,
QMessageBox::Ok, QMessageBox::Ok,
QMessageBox::Ok, QMessageBox::Ok,
@ -103,18 +103,18 @@ void VMdEditOperations::insertImageFromPath(const QString &title, const QString
bool ret = VUtils::makePath(path); bool ret = VUtils::makePath(path);
if (!ret) { if (!ret) {
errStr = tr("Fail to create image folder <span style=\"%1\">%2</span>.") errStr = tr("Fail to create image folder <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(path); .arg(g_config->c_dataTextStyle).arg(path);
} else { } else {
ret = QFile::copy(oriImagePath, filePath); ret = QFile::copy(oriImagePath, filePath);
if (!ret) { if (!ret) {
errStr = tr("Fail to copy image <span style=\"%1\">%2</span>.") errStr = tr("Fail to copy image <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(filePath); .arg(g_config->c_dataTextStyle).arg(filePath);
} }
} }
if (!ret) { if (!ret) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to insert image <span style=\"%1\">%2</span>.").arg(vconfig.c_dataTextStyle).arg(title), tr("Fail to insert image <span style=\"%1\">%2</span>.").arg(g_config->c_dataTextStyle).arg(title),
errStr, errStr,
QMessageBox::Ok, QMessageBox::Ok,
QMessageBox::Ok, QMessageBox::Ok,
@ -576,7 +576,7 @@ bool VMdEditOperations::handleKeyReturn(QKeyEvent *p_event)
bool handled = false; bool handled = false;
m_autoIndentPos = -1; m_autoIndentPos = -1;
if (vconfig.getAutoIndent()) { if (g_config->getAutoIndent()) {
handled = true; handled = true;
QTextCursor cursor = m_editor->textCursor(); QTextCursor cursor = m_editor->textCursor();
@ -588,7 +588,7 @@ bool VMdEditOperations::handleKeyReturn(QKeyEvent *p_event)
textInserted = VEditUtils::insertBlockWithIndent(cursor); textInserted = VEditUtils::insertBlockWithIndent(cursor);
// Continue the list from previous line. // Continue the list from previous line.
if (vconfig.getAutoList() && autolist) { if (g_config->getAutoList() && autolist) {
textInserted = VEditUtils::insertListMarkAsPreviousBlock(cursor) || textInserted; textInserted = VEditUtils::insertListMarkAsPreviousBlock(cursor) || textInserted;
} }

View File

@ -18,12 +18,12 @@
#include "vconstants.h" #include "vconstants.h"
#include "vwebview.h" #include "vwebview.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VMdTab::VMdTab(VFile *p_file, VEditArea *p_editArea, VMdTab::VMdTab(VFile *p_file, VEditArea *p_editArea,
OpenFileMode p_mode, QWidget *p_parent) OpenFileMode p_mode, QWidget *p_parent)
: VEditTab(p_file, p_editArea, p_parent), m_editor(NULL), m_webViewer(NULL), : VEditTab(p_file, p_editArea, p_parent), m_editor(NULL), m_webViewer(NULL),
m_document(NULL), m_mdConType(vconfig.getMdConverterType()) m_document(NULL), m_mdConType(g_config->getMdConverterType())
{ {
V_ASSERT(m_file->getDocType() == DocType::Markdown); V_ASSERT(m_file->getDocType() == DocType::Markdown);
@ -105,7 +105,7 @@ void VMdTab::viewWebByConverter()
VMarkdownConverter mdConverter; VMarkdownConverter mdConverter;
QString toc; QString toc;
QString html = mdConverter.generateHtml(m_file->getContent(), QString html = mdConverter.generateHtml(m_file->getContent(),
vconfig.getMarkdownExtensions(), g_config->getMarkdownExtensions(),
toc); toc);
m_document->setHtml(html); m_document->setHtml(html);
updateTocFromHtml(toc); updateTocFromHtml(toc);
@ -190,7 +190,7 @@ void VMdTab::readFile()
// Prompt to save the changes. // Prompt to save the changes.
int ret = VUtils::showMessage(QMessageBox::Information, tr("Information"), int ret = VUtils::showMessage(QMessageBox::Information, tr("Information"),
tr("Note <span style=\"%1\">%2</span> has been modified.") tr("Note <span style=\"%1\">%2</span> has been modified.")
.arg(vconfig.c_dataTextStyle).arg(m_file->getName()), .arg(g_config->c_dataTextStyle).arg(m_file->getName()),
tr("Do you want to save your changes?"), tr("Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save, this); QMessageBox::Save, this);
@ -240,7 +240,7 @@ bool VMdTab::saveFile()
qWarning() << filePath << "being written has been removed"; qWarning() << filePath << "being written has been removed";
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), tr("Fail to save note."), VUtils::showMessage(QMessageBox::Warning, tr("Warning"), tr("Fail to save note."),
tr("File <span style=\"%1\">%2</span> being written has been removed.") tr("File <span style=\"%1\">%2</span> being written has been removed.")
.arg(vconfig.c_dataTextStyle).arg(filePath), .arg(g_config->c_dataTextStyle).arg(filePath),
QMessageBox::Ok, QMessageBox::Ok, this); QMessageBox::Ok, QMessageBox::Ok, this);
return false; return false;
} }
@ -278,7 +278,7 @@ void VMdTab::setupMarkdownViewer()
VPreviewPage *page = new VPreviewPage(m_webViewer); VPreviewPage *page = new VPreviewPage(m_webViewer);
m_webViewer->setPage(page); m_webViewer->setPage(page);
m_webViewer->setZoomFactor(vconfig.getWebZoomFactor()); m_webViewer->setZoomFactor(g_config->getWebZoomFactor());
m_document = new VDocument(m_file, m_webViewer); m_document = new VDocument(m_file, m_webViewer);

View File

@ -13,7 +13,7 @@
#include "vmainwindow.h" #include "vmainwindow.h"
#include "vorphanfile.h" #include "vorphanfile.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
QString VNote::s_markdownTemplate; QString VNote::s_markdownTemplate;
QString VNote::s_markdownTemplatePDF; QString VNote::s_markdownTemplatePDF;
@ -55,7 +55,7 @@ VNote::VNote(QObject *parent)
: QObject(parent), m_mainWindow(dynamic_cast<VMainWindow *>(parent)) : QObject(parent), m_mainWindow(dynamic_cast<VMainWindow *>(parent))
{ {
initTemplate(); initTemplate();
vconfig.getNotebooks(m_notebooks, this); g_config->getNotebooks(m_notebooks, this);
} }
void VNote::initPalette(QPalette palette) void VNote::initPalette(QPalette palette)
@ -169,8 +169,8 @@ void VNote::updateTemplate()
// Get background color // Get background color
QString rgb; QString rgb;
const QString &curRenderBg = vconfig.getCurRenderBackgroundColor(); const QString &curRenderBg = g_config->getCurRenderBackgroundColor();
const QVector<VColor> &predefinedColors = vconfig.getPredefinedColors(); const QVector<VColor> &predefinedColors = g_config->getPredefinedColors();
if (curRenderBg != "System") { if (curRenderBg != "System") {
for (int i = 0; i < predefinedColors.size(); ++i) { for (int i = 0; i < predefinedColors.size(); ++i) {
if (predefinedColors[i].name == curRenderBg) { if (predefinedColors[i].name == curRenderBg) {
@ -184,7 +184,7 @@ void VNote::updateTemplate()
cssStyle += "body { background-color: #" + rgb + " !important; }\n"; cssStyle += "body { background-color: #" + rgb + " !important; }\n";
} }
if (vconfig.getEnableImageConstraint()) { if (g_config->getEnableImageConstraint()) {
// Constain the image width. // Constain the image width.
cssStyle += "img { max-width: 100% !important; height: auto !important; }\n"; cssStyle += "img { max-width: 100% !important; height: auto !important; }\n";
} }
@ -193,7 +193,7 @@ void VNote::updateTemplate()
const QString cssHolder("CSS_PLACE_HOLDER"); const QString cssHolder("CSS_PLACE_HOLDER");
s_markdownTemplate = VUtils::readFileFromDisk(c_markdownTemplatePath); s_markdownTemplate = VUtils::readFileFromDisk(c_markdownTemplatePath);
s_markdownTemplate.replace(cssHolder, vconfig.getTemplateCssUrl()); s_markdownTemplate.replace(cssHolder, g_config->getTemplateCssUrl());
s_markdownTemplatePDF = s_markdownTemplate; s_markdownTemplatePDF = s_markdownTemplate;
@ -204,7 +204,7 @@ void VNote::updateTemplate()
// Shoudl not display scrollbar in PDF. // Shoudl not display scrollbar in PDF.
cssStyle += "pre code { white-space: pre-wrap !important; " cssStyle += "pre code { white-space: pre-wrap !important; "
"word-break: break-all !important; }\n"; "word-break: break-all !important; }\n";
if (!vconfig.getEnableImageConstraint()) { if (!g_config->getEnableImageConstraint()) {
// Constain the image width by force in PDF, otherwise, the PDF will // Constain the image width by force in PDF, otherwise, the PDF will
// be cut off. // be cut off.
cssStyle += "img { max-width: 100% !important; height: auto !important; }\n"; cssStyle += "img { max-width: 100% !important; height: auto !important; }\n";

View File

@ -6,7 +6,7 @@
#include "vconfigmanager.h" #include "vconfigmanager.h"
#include "vfile.h" #include "vfile.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VNotebook::VNotebook(const QString &name, const QString &path, QObject *parent) VNotebook::VNotebook(const QString &name, const QString &path, QObject *parent)
: QObject(parent), m_name(name) : QObject(parent), m_name(name)
@ -221,7 +221,7 @@ VFile *VNotebook::tryLoadFile(const QString &p_path)
const QString &VNotebook::getImageFolder() const const QString &VNotebook::getImageFolder() const
{ {
if (m_imageFolder.isEmpty()) { if (m_imageFolder.isEmpty()) {
return vconfig.getImageFolder(); return g_config->getImageFolder();
} else { } else {
return m_imageFolder; return m_imageFolder;
} }

View File

@ -21,7 +21,7 @@
#include "veditarea.h" #include "veditarea.h"
#include "vnofocusitemdelegate.h" #include "vnofocusitemdelegate.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
extern VNote *g_vnote; extern VNote *g_vnote;
const int VNotebookSelector::c_notebookStartIdx = 1; const int VNotebookSelector::c_notebookStartIdx = 1;
@ -68,7 +68,7 @@ void VNotebookSelector::initActions()
void VNotebookSelector::updateComboBox() void VNotebookSelector::updateComboBox()
{ {
int index = vconfig.getCurNotebookIndex(); int index = g_config->getCurNotebookIndex();
disconnect(this, SIGNAL(currentIndexChanged(int)), disconnect(this, SIGNAL(currentIndexChanged(int)),
this, SLOT(handleCurIndexChanged(int))); this, SLOT(handleCurIndexChanged(int)));
@ -85,7 +85,7 @@ void VNotebookSelector::updateComboBox()
this, SLOT(handleCurIndexChanged(int))); this, SLOT(handleCurIndexChanged(int)));
if (m_notebooks.isEmpty()) { if (m_notebooks.isEmpty()) {
vconfig.setCurNotebookIndex(-1); g_config->setCurNotebookIndex(-1);
setCurrentIndex(0); setCurrentIndex(0);
} else { } else {
setCurrentIndexNotebook(index); setCurrentIndexNotebook(index);
@ -140,7 +140,7 @@ void VNotebookSelector::handleCurIndexChanged(int p_index)
tooltip = nb->getName(); tooltip = nb->getName();
} }
setToolTip(tooltip); setToolTip(tooltip);
vconfig.setCurNotebookIndex(p_index); g_config->setCurNotebookIndex(p_index);
emit curNotebookChanged(nb); emit curNotebookChanged(nb);
} }
@ -200,13 +200,13 @@ void VNotebookSelector::createNotebook(const QString &p_name,
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to create notebook " tr("Fail to create notebook "
"<span style=\"%1\">%2</span> in <span style=\"%1\">%3</span>.") "<span style=\"%1\">%2</span> in <span style=\"%1\">%3</span>.")
.arg(vconfig.c_dataTextStyle).arg(p_name).arg(p_path), "", .arg(g_config->c_dataTextStyle).arg(p_name).arg(p_path), "",
QMessageBox::Ok, QMessageBox::Ok, this); QMessageBox::Ok, QMessageBox::Ok, this);
return; return;
} }
m_notebooks.append(nb); m_notebooks.append(nb);
vconfig.setNotebooks(m_notebooks); g_config->setNotebooks(m_notebooks);
addNotebookItem(nb->getName()); addNotebookItem(nb->getName());
setCurrentIndexNotebook(m_notebooks.size() - 1); setCurrentIndexNotebook(m_notebooks.size() - 1);
@ -240,7 +240,7 @@ void VNotebookSelector::deleteNotebook(VNotebook *p_notebook, bool p_deleteFiles
int idx = indexOfNotebook(p_notebook); int idx = indexOfNotebook(p_notebook);
m_notebooks.remove(idx); m_notebooks.remove(idx);
vconfig.setNotebooks(m_notebooks); g_config->setNotebooks(m_notebooks);
removeNotebookItem(idx); removeNotebookItem(idx);
@ -253,7 +253,7 @@ void VNotebookSelector::deleteNotebook(VNotebook *p_notebook, bool p_deleteFiles
tr("Fail to delete the root folder of notebook " tr("Fail to delete the root folder of notebook "
"<span style=\"%1\">%2</span> from disk. You may open " "<span style=\"%1\">%2</span> from disk. You may open "
"the folder and check it manually.") "the folder and check it manually.")
.arg(vconfig.c_dataTextStyle).arg(name), "", .arg(g_config->c_dataTextStyle).arg(name), "",
QMessageBox::Open | QMessageBox::Ok, QMessageBox::Open | QMessageBox::Ok,
QMessageBox::Ok, this); QMessageBox::Ok, this);
if (cho == QMessageBox::Open) { if (cho == QMessageBox::Open) {
@ -297,7 +297,7 @@ void VNotebookSelector::editNotebookInfo()
updated = true; updated = true;
notebook->rename(name); notebook->rename(name);
updateComboBoxItem(index, name); updateComboBoxItem(index, name);
vconfig.setNotebooks(m_notebooks); g_config->setNotebooks(m_notebooks);
} }
QString imageFolder = dialog.getImageFolder(); QString imageFolder = dialog.getImageFolder();

View File

@ -6,7 +6,7 @@
#include "utils/vutils.h" #include "utils/vutils.h"
#include "vconfigmanager.h" #include "vconfigmanager.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VOrphanFile::VOrphanFile(const QString &p_path, QObject *p_parent, VOrphanFile::VOrphanFile(const QString &p_path, QObject *p_parent,
bool p_modifiable, bool p_systemFile) bool p_modifiable, bool p_systemFile)
@ -51,7 +51,7 @@ QString VOrphanFile::retriveImagePath() const
{ {
QString folder = m_imageFolder; QString folder = m_imageFolder;
if (m_imageFolder.isEmpty()) { if (m_imageFolder.isEmpty()) {
folder = vconfig.getImageFolderExt(); folder = g_config->getImageFolderExt();
} }
QFileInfo fi(folder); QFileInfo fi(folder);
@ -140,7 +140,7 @@ bool VOrphanFile::isRelativeImageFolder() const
{ {
QString folder = m_imageFolder; QString folder = m_imageFolder;
if (m_imageFolder.isEmpty()) { if (m_imageFolder.isEmpty()) {
folder = vconfig.getImageFolderExt(); folder = g_config->getImageFolderExt();
} }
return !QFileInfo(folder).isAbsolute(); return !QFileInfo(folder).isAbsolute();
@ -150,7 +150,7 @@ QString VOrphanFile::getImageFolderInLink() const
{ {
QString folder = m_imageFolder; QString folder = m_imageFolder;
if (m_imageFolder.isEmpty()) { if (m_imageFolder.isEmpty()) {
folder = vconfig.getImageFolderExt(); folder = g_config->getImageFolderExt();
} }
return folder; return folder;

View File

@ -8,10 +8,8 @@
#include "vtoc.h" #include "vtoc.h"
#include "utils/vutils.h" #include "utils/vutils.h"
#include "vnote.h" #include "vnote.h"
#include "vconfigmanager.h"
extern VNote *g_vnote; extern VNote *g_vnote;
extern VConfigManager vconfig;
VOutline::VOutline(QWidget *parent) VOutline::VOutline(QWidget *parent)
: QTreeWidget(parent), VNavigationMode() : QTreeWidget(parent), VNavigationMode()

View File

@ -14,7 +14,7 @@
#include "vbuttonwithwidget.h" #include "vbuttonwithwidget.h"
#include "vedittab.h" #include "vedittab.h"
extern VConfigManager vconfig; extern VConfigManager *g_config;
VVimIndicator::VVimIndicator(QWidget *p_parent) VVimIndicator::VVimIndicator(QWidget *p_parent)
: QWidget(p_parent), m_vim(NULL) : QWidget(p_parent), m_vim(NULL)
@ -187,23 +187,23 @@ static QString modeBackgroundColor(VimMode p_mode)
switch (p_mode) { switch (p_mode) {
case VimMode::Normal: case VimMode::Normal:
color = vconfig.getEditorVimNormalBg(); color = g_config->getEditorVimNormalBg();
break; break;
case VimMode::Insert: case VimMode::Insert:
color = vconfig.getEditorVimInsertBg(); color = g_config->getEditorVimInsertBg();
break; break;
case VimMode::Visual: case VimMode::Visual:
color = vconfig.getEditorVimVisualBg(); color = g_config->getEditorVimVisualBg();
break; break;
case VimMode::VisualLine: case VimMode::VisualLine:
color = vconfig.getEditorVimVisualBg(); color = g_config->getEditorVimVisualBg();
break; break;
case VimMode::Replace: case VimMode::Replace:
color = vconfig.getEditorVimReplaceBg(); color = g_config->getEditorVimReplaceBg();
break; break;
default: default: