diff --git a/src/dialog/vdeletenotebookdialog.cpp b/src/dialog/vdeletenotebookdialog.cpp
index 808a1b9d..555ff4b7 100644
--- a/src/dialog/vdeletenotebookdialog.cpp
+++ b/src/dialog/vdeletenotebookdialog.cpp
@@ -2,7 +2,7 @@
#include "vdeletenotebookdialog.h"
#include "vconfigmanager.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VDeleteNotebookDialog::VDeleteNotebookDialog(const QString &p_title, const QString &p_name,
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)
{
QLabel *infoLabel = new QLabel(tr("Are you sure to delete notebook %2?")
- .arg(vconfig.c_dataTextStyle).arg(p_name));
+ .arg(g_config->c_dataTextStyle).arg(p_name));
m_warningLabel = new QLabel();
m_warningLabel->setWordWrap(true);
@@ -109,12 +109,12 @@ void VDeleteNotebookDialog::deleteCheckChanged(int p_state)
{
if (!p_state) {
m_warningLabel->setText(tr("VNote won't delete files in directory %2.")
- .arg(vconfig.c_dataTextStyle).arg(m_path));
+ .arg(g_config->c_dataTextStyle).arg(m_path));
} else {
m_warningLabel->setText(tr("WARNING: "
"VNote may delete ANY files in directory %3! "
"VNote will try to delete all the root folders within this notebook one by one. "
"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));
}
}
diff --git a/src/dialog/vnewnotebookdialog.cpp b/src/dialog/vnewnotebookdialog.cpp
index 94281084..c1f0a9dd 100644
--- a/src/dialog/vnewnotebookdialog.cpp
+++ b/src/dialog/vnewnotebookdialog.cpp
@@ -5,7 +5,7 @@
#include "utils/vutils.h"
#include "vnotebook.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VNewNotebookDialog::VNewNotebookDialog(const QString &title, const QString &info,
const QString &defaultName, const QString &defaultPath,
@@ -44,7 +44,7 @@ void VNewNotebookDialog::setupUI()
QLabel *imageFolderLabel = new QLabel(tr("&Image folder:"));
m_imageFolderEdit = new QLineEdit();
m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)")
- .arg(vconfig.getImageFolder()));
+ .arg(g_config->getImageFolder()));
imageFolderLabel->setBuddy(m_imageFolderEdit);
QString imageFolderTip = tr("Set the name of the folder for all the notes of this notebook to store images "
"(empty to use global configuration)");
@@ -114,7 +114,7 @@ void VNewNotebookDialog::handleBrowseBtnClicked()
{
static QString defaultPath;
if (defaultPath.isEmpty()) {
- defaultPath = vconfig.getVnoteNotebookFolderPath();
+ defaultPath = g_config->getVnoteNotebookFolderPath();
if (!QFileInfo::exists(defaultPath)) {
defaultPath = QDir::homePath();
}
@@ -146,7 +146,7 @@ void VNewNotebookDialog::handleInputChanged()
{
QString warnText = tr("WARNING: The folder chosen is NOT empty! "
"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("INFO: The folder chosen seems to be a root "
"folder of a notebook created by VNote before. "
"VNote will try to import it by reading the configuration file.")
@@ -199,7 +199,7 @@ void VNewNotebookDialog::handleInputChanged()
showWarnLabel = true;
QString tmp = tr("WARNING: The path seems to be illegal. "
"Please choose another one.")
- .arg(vconfig.c_warningTextStyle);
+ .arg(g_config->c_warningTextStyle);
m_warnLabel->setText(tmp);
}
}
@@ -218,8 +218,8 @@ void VNewNotebookDialog::handleInputChanged()
showWarnLabel = true;
QString existText = tr("WARNING: The folder chosen has already been a root folder "
"of existing notebook %3 in VNote.")
- .arg(vconfig.c_warningTextStyle)
- .arg(vconfig.c_dataTextStyle)
+ .arg(g_config->c_warningTextStyle)
+ .arg(g_config->c_dataTextStyle)
.arg(m_notebooks[idx]->getName());
m_warnLabel->setText(existText);
}
@@ -242,7 +242,7 @@ void VNewNotebookDialog::handleInputChanged()
showWarnLabel = true;
QString nameConflictText = tr("WARNING: Name (case-insensitive) already exists. "
"Please choose another name.")
- .arg(vconfig.c_warningTextStyle);
+ .arg(g_config->c_warningTextStyle);
m_warnLabel->setText(nameConflictText);
}
}
@@ -261,7 +261,7 @@ bool VNewNotebookDialog::autoComplete()
return false;
}
- QString vnoteFolder = vconfig.getVnoteNotebookFolderPath();
+ QString vnoteFolder = g_config->getVnoteNotebookFolderPath();
QString pathText = pathEdit->text();
if (!pathText.isEmpty()
&& !VUtils::equalPath(vnoteFolder, VUtils::basePathFromPath(pathText))) {
diff --git a/src/dialog/vnotebookinfodialog.cpp b/src/dialog/vnotebookinfodialog.cpp
index 8cbd0b66..897abd61 100644
--- a/src/dialog/vnotebookinfodialog.cpp
+++ b/src/dialog/vnotebookinfodialog.cpp
@@ -4,7 +4,7 @@
#include "utils/vutils.h"
#include "vconfigmanager.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VNotebookInfoDialog::VNotebookInfoDialog(const QString &p_title,
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:"));
m_imageFolderEdit = new QLineEdit(m_notebook->getImageFolderConfig());
m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)")
- .arg(vconfig.getImageFolder()));
+ .arg(g_config->getImageFolder()));
imageFolderLabel->setBuddy(m_imageFolderEdit);
QString imageFolderTip = tr("Set the name of the folder for all the notes of this notebook to store images "
"(empty to use global configuration)");
@@ -103,7 +103,7 @@ void VNotebookInfoDialog::handleInputChanged()
showWarnLabel = true;
QString nameConflictText = tr("WARNING: Name (case-insensitive) already exists. "
"Please choose another name.")
- .arg(vconfig.c_warningTextStyle);
+ .arg(g_config->c_warningTextStyle);
m_warnLabel->setText(nameConflictText);
}
}
diff --git a/src/dialog/vorphanfileinfodialog.cpp b/src/dialog/vorphanfileinfodialog.cpp
index bb3f0063..38dbe5aa 100644
--- a/src/dialog/vorphanfileinfodialog.cpp
+++ b/src/dialog/vorphanfileinfodialog.cpp
@@ -5,7 +5,7 @@
#include "vconfigmanager.h"
#include "utils/vutils.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VOrphanFileInfoDialog::VOrphanFileInfoDialog(const VOrphanFile *p_file, QWidget *p_parent)
: QDialog(p_parent), m_file(p_file)
@@ -28,7 +28,7 @@ void VOrphanFileInfoDialog::setupUI()
QLabel *imageFolderLabel = new QLabel(tr("Image folder:"));
m_imageFolderEdit = new QLineEdit(m_file->getImageFolder());
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 "
"of this file.\nIf absolute path is used, "
"VNote will not manage those images."
diff --git a/src/dialog/vsettingsdialog.cpp b/src/dialog/vsettingsdialog.cpp
index 29498061..11b37a7f 100644
--- a/src/dialog/vsettingsdialog.cpp
+++ b/src/dialog/vsettingsdialog.cpp
@@ -5,7 +5,7 @@
#include "utils/vutils.h"
#include "vconstants.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VSettingsDialog::VSettingsDialog(QWidget *p_parent)
: QDialog(p_parent)
@@ -170,7 +170,7 @@ bool VGeneralTab::saveConfiguration()
bool VGeneralTab::loadLanguage()
{
- QString lang = vconfig.getLanguage();
+ QString lang = g_config->getLanguage();
if (lang.isNull()) {
return false;
} else if (lang == "System") {
@@ -196,20 +196,20 @@ bool VGeneralTab::loadLanguage()
bool VGeneralTab::saveLanguage()
{
QString curLang = m_langCombo->currentData().toString();
- vconfig.setLanguage(curLang);
+ g_config->setLanguage(curLang);
return true;
}
bool VGeneralTab::loadSystemTray()
{
- m_systemTray->setChecked(vconfig.getMinimizeToStystemTray() != 0);
+ m_systemTray->setChecked(g_config->getMinimizeToStystemTray() != 0);
return true;
}
bool VGeneralTab::saveSystemTray()
{
if (m_systemTray->isEnabled()) {
- vconfig.setMinimizeToSystemTray(m_systemTray->isChecked() ? 1 : 0);
+ g_config->setMinimizeToSystemTray(m_systemTray->isChecked() ? 1 : 0);
}
return true;
@@ -264,8 +264,8 @@ bool VReadEditTab::saveConfiguration()
bool VReadEditTab::loadWebZoomFactor()
{
- qreal factor = vconfig.getWebZoomFactor();
- bool customFactor = vconfig.isCustomWebZoomFactor();
+ qreal factor = g_config->getWebZoomFactor();
+ bool customFactor = g_config->isCustomWebZoomFactor();
if (customFactor) {
if (factor < c_webZoomFactorMin || factor > c_webZoomFactorMax) {
factor = 1;
@@ -283,9 +283,9 @@ bool VReadEditTab::loadWebZoomFactor()
bool VReadEditTab::saveWebZoomFactor()
{
if (m_customWebZoom->isChecked()) {
- vconfig.setWebZoomFactor(m_webZoomFactorSpin->value());
+ g_config->setWebZoomFactor(m_webZoomFactorSpin->value());
} else {
- vconfig.setWebZoomFactor(-1);
+ g_config->setWebZoomFactor(-1);
}
return true;
}
@@ -381,10 +381,10 @@ bool VNoteManagementTab::saveConfiguration()
bool VNoteManagementTab::loadImageFolder()
{
- bool isCustom = vconfig.isCustomImageFolder();
+ bool isCustom = g_config->isCustomImageFolder();
m_customImageFolder->setChecked(isCustom);
- m_imageFolderEdit->setText(vconfig.getImageFolder());
+ m_imageFolderEdit->setText(g_config->getImageFolder());
m_imageFolderEdit->setEnabled(isCustom);
return true;
@@ -393,9 +393,9 @@ bool VNoteManagementTab::loadImageFolder()
bool VNoteManagementTab::saveImageFolder()
{
if (m_customImageFolder->isChecked()) {
- vconfig.setImageFolder(m_imageFolderEdit->text());
+ g_config->setImageFolder(m_imageFolderEdit->text());
} else {
- vconfig.setImageFolder("");
+ g_config->setImageFolder("");
}
return true;
@@ -414,10 +414,10 @@ void VNoteManagementTab::customImageFolderChanged(int p_state)
bool VNoteManagementTab::loadImageFolderExt()
{
- bool isCustom = vconfig.isCustomImageFolderExt();
+ bool isCustom = g_config->isCustomImageFolderExt();
m_customImageFolderExt->setChecked(isCustom);
- m_imageFolderEditExt->setText(vconfig.getImageFolderExt());
+ m_imageFolderEditExt->setText(g_config->getImageFolderExt());
m_imageFolderEditExt->setEnabled(isCustom);
return true;
@@ -426,9 +426,9 @@ bool VNoteManagementTab::loadImageFolderExt()
bool VNoteManagementTab::saveImageFolderExt()
{
if (m_customImageFolderExt->isChecked()) {
- vconfig.setImageFolderExt(m_imageFolderEditExt->text());
+ g_config->setImageFolderExt(m_imageFolderEditExt->text());
} else {
- vconfig.setImageFolderExt("");
+ g_config->setImageFolderExt("");
}
return true;
diff --git a/src/dialog/vupdater.cpp b/src/dialog/vupdater.cpp
index 715763c1..fb3f2862 100644
--- a/src/dialog/vupdater.cpp
+++ b/src/dialog/vupdater.cpp
@@ -8,7 +8,7 @@
#include "vconfigmanager.h"
#include "vdownloader.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VUpdater::VUpdater(QWidget *p_parent)
: QDialog(p_parent)
@@ -24,7 +24,7 @@ void VUpdater::setupUI()
imgLabel->setPixmap(QPixmap::fromImage(img.scaled(imgSize)));
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->setOpenExternalLinks(true);
@@ -156,8 +156,8 @@ void VUpdater::parseResult(const QByteArray &p_data)
QString body = json["body"].toString();
m_versionLabel->setText(tr("Current Version: v%1\nLatest Version: v%2")
- .arg(vconfig.c_version).arg(tag));
- if (isNewerVersion(vconfig.c_version, tag)) {
+ .arg(g_config->c_version).arg(tag));
+ if (isNewerVersion(g_config->c_version, tag)) {
m_proLabel->setText(tr("Updates Available!
"
"Please visit Github Releases to download the latest version.")
.arg(releaseUrl));
diff --git a/src/hgmarkdownhighlighter.cpp b/src/hgmarkdownhighlighter.cpp
index 447f7482..d1f12d51 100644
--- a/src/hgmarkdownhighlighter.cpp
+++ b/src/hgmarkdownhighlighter.cpp
@@ -6,7 +6,7 @@
#include "vconfigmanager.h"
#include "utils/vutils.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
const int HGMarkdownHighlighter::initCapacity = 1024;
@@ -371,7 +371,7 @@ void HGMarkdownHighlighter::updateHighlight()
bool HGMarkdownHighlighter::updateCodeBlocks()
{
- if (!vconfig.getEnableCodeBlockHighlight()) {
+ if (!g_config->getEnableCodeBlockHighlight()) {
m_codeBlockHighlights.clear();
return false;
}
diff --git a/src/main.cpp b/src/main.cpp
index 41ad539c..69799c7f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -12,7 +12,7 @@
#include "vsingleinstanceguard.h"
#include "vconfigmanager.h"
-VConfigManager vconfig;
+VConfigManager *g_config;
#if defined(QT_NO_DEBUG)
QFile g_logFile;
@@ -143,7 +143,9 @@ int main(int argc, char *argv[])
return 0;
}
+ VConfigManager vconfig;
vconfig.initialize();
+ g_config = &vconfig;
QString locale = VUtils::getLocale();
qDebug() << "use locale" << locale;
diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp
index a3f27f30..3e126482 100644
--- a/src/utils/vutils.cpp
+++ b/src/utils/vutils.cpp
@@ -24,7 +24,7 @@
#include "vfile.h"
#include "vnote.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
QVector> VUtils::s_availableLanguages;
@@ -338,7 +338,7 @@ int VUtils::showMessage(QMessageBox::Icon p_icon, const QString &p_title, const
if (p_type == MessageBoxType::Danger) {
QPushButton *okBtn = dynamic_cast(msgBox.button(QMessageBox::Ok));
if (okBtn) {
- okBtn->setStyleSheet(vconfig.c_dangerBtnStyle);
+ okBtn->setStyleSheet(g_config->c_dangerBtnStyle);
}
}
return msgBox.exec();
@@ -451,7 +451,7 @@ QChar VUtils::keyToChar(int p_key)
QString VUtils::getLocale()
{
- QString locale = vconfig.getLanguage();
+ QString locale = g_config->getLanguage();
if (locale == "System" || !isValidLanguage(locale)) {
locale = QLocale::system().name();
}
@@ -473,7 +473,7 @@ void VUtils::sleepWait(int p_milliseconds)
DocType VUtils::docTypeFromName(const QString &p_name)
{
- const QHash> &suffixes = vconfig.getDocSuffixes();
+ const QHash> &suffixes = g_config->getDocSuffixes();
QString suf = QFileInfo(p_name).suffix().toLower();
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);
}
- if (vconfig.getEnableMermaid()) {
+ if (g_config->getEnableMermaid()) {
extraFile += "\n" +
"\n" +
"\n";
}
- if (vconfig.getEnableFlowchart()) {
+ if (g_config->getEnableFlowchart()) {
extraFile += "\n" +
"\n" +
"\n";
}
- if (vconfig.getEnableMathjax()) {
+ if (g_config->getEnableMathjax()) {
extraFile += "\n";
}
- if (vconfig.getEnableImageCaption()) {
+ if (g_config->getEnableImageCaption()) {
extraFile += "\n";
}
diff --git a/src/utils/vvim.cpp b/src/utils/vvim.cpp
index 16a793eb..3b95cfe7 100644
--- a/src/utils/vvim.cpp
+++ b/src/utils/vvim.cpp
@@ -13,7 +13,7 @@
#include "utils/veditutils.h"
#include "vconstants.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
const QChar VVim::c_unnamedRegister = 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);
}
- if (vconfig.getAutoIndent()) {
+ if (g_config->getAutoIndent()) {
VEditUtils::indentBlockAsPreviousBlock(p_cursor);
}
}
@@ -975,9 +975,9 @@ bool VVim::handleKeyPressEvent(int key, int modifiers, int *p_autoIndentPos)
}
bool textInserted = false;
- if (vconfig.getAutoIndent()) {
+ if (g_config->getAutoIndent()) {
textInserted = VEditUtils::indentBlockAsPreviousBlock(cursor);
- if (vconfig.getAutoList()) {
+ if (g_config->getAutoList()) {
textInserted = VEditUtils::insertListMarkAsPreviousBlock(cursor)
|| textInserted;
}
@@ -2239,7 +2239,7 @@ void VVim::setMode(VimMode p_mode, bool p_clearSelection)
if (p_mode == VimMode::Insert) {
m_editor->setInputMethodEnabled(true);
- } else if (vconfig.getEnableSmartImInVimMode()) {
+ } else if (g_config->getEnableSmartImInVimMode()) {
m_editor->setInputMethodEnabled(false);
}
diff --git a/src/vconfigmanager.cpp b/src/vconfigmanager.cpp
index 91d0c8c2..afb9bae2 100644
--- a/src/vconfigmanager.cpp
+++ b/src/vconfigmanager.cpp
@@ -28,8 +28,8 @@ const QString VConfigManager::c_dangerBtnStyle = QString("QPushButton {color: #f
"QPushButton::hover {color: #fff; border-color: #ac2925; background-color: #c9302c;}");
const QString VConfigManager::c_vnoteNotebookFolderName = QString("vnote_notebooks");
-VConfigManager::VConfigManager()
- : userSettings(NULL), defaultSettings(NULL)
+VConfigManager::VConfigManager(QObject *p_parent)
+ : QObject(p_parent), userSettings(NULL), defaultSettings(NULL)
{
}
@@ -46,9 +46,10 @@ void VConfigManager::migrateIniFile()
void VConfigManager::initialize()
{
+ Q_ASSERT(!userSettings && !defaultSettings);
userSettings = new QSettings(QSettings::IniFormat, QSettings::UserScope,
- orgName, appName);
- defaultSettings = new QSettings(defaultConfigFilePath, QSettings::IniFormat);
+ orgName, appName, this);
+ defaultSettings = new QSettings(defaultConfigFilePath, QSettings::IniFormat, this);
migrateIniFile();
diff --git a/src/vconfigmanager.h b/src/vconfigmanager.h
index 4f3f5180..85c74261 100644
--- a/src/vconfigmanager.h
+++ b/src/vconfigmanager.h
@@ -1,6 +1,7 @@
#ifndef VCONFIGMANAGER_H
#define VCONFIGMANAGER_H
+#include
#include
#include
#include
@@ -27,15 +28,10 @@ struct VColor
QString rgb; // 'FFFFFF', without '#'
};
-// FIXME: we do not free userSettings and defaultSettings here since there will
-// 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
+class VConfigManager : public QObject
{
public:
- VConfigManager();
+ explicit VConfigManager(QObject *p_parent = NULL);
void initialize();
diff --git a/src/vdirectory.cpp b/src/vdirectory.cpp
index ec069397..e5637da4 100644
--- a/src/vdirectory.cpp
+++ b/src/vdirectory.cpp
@@ -7,7 +7,7 @@
#include "vfile.h"
#include "utils/vutils.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VDirectory::VDirectory(VNotebook *p_notebook,
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);
if (!ret) {
errStr = tr("Fail to create image folder %2.")
- .arg(vconfig.c_dataTextStyle).arg(destImagePath);
+ .arg(g_config->c_dataTextStyle).arg(destImagePath);
} else {
destImagePath = QDir(destImagePath).filePath(VUtils::fileNameFromPath(link.m_path));
@@ -570,7 +570,7 @@ VFile *VDirectory::copyFile(VDirectory *p_destDir, const QString &p_destName,
} else {
errStr = tr("Please check if there already exists a file %2 "
"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"),
tr("Fail to copy image %2 while "
"%5 note %4.")
- .arg(vconfig.c_dataTextStyle).arg(link.m_path)
- .arg(vconfig.c_dataTextStyle).arg(srcPath)
+ .arg(g_config->c_dataTextStyle).arg(link.m_path)
+ .arg(g_config->c_dataTextStyle).arg(srcPath)
.arg(p_cut ? tr("moving") : tr("copying")),
errStr, QMessageBox::Ok, QMessageBox::Ok, NULL);
}
diff --git a/src/vdirectorytree.cpp b/src/vdirectorytree.cpp
index f601d3d1..b4aaf5b6 100644
--- a/src/vdirectorytree.cpp
+++ b/src/vdirectorytree.cpp
@@ -9,7 +9,7 @@
#include "veditarea.h"
#include "vconfigmanager.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
extern VNote *g_vnote;
VDirectoryTree::VDirectoryTree(VNote *vnote, QWidget *parent)
@@ -103,7 +103,7 @@ void VDirectoryTree::setNotebook(VNotebook *p_notebook)
if (!m_notebook->open()) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to open notebook %2.")
- .arg(vconfig.c_dataTextStyle).arg(m_notebook->getName()), "",
+ .arg(g_config->c_dataTextStyle).arg(m_notebook->getName()), "",
QMessageBox::Ok, QMessageBox::Ok, this);
clear();
return;
@@ -165,7 +165,7 @@ void VDirectoryTree::buildSubTree(QTreeWidgetItem *p_parent, int p_depth)
if (!dir->open()) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to open folder %2.")
- .arg(vconfig.c_dataTextStyle).arg(dir->getName()), "",
+ .arg(g_config->c_dataTextStyle).arg(dir->getName()), "",
QMessageBox::Ok, QMessageBox::Ok, this);
return;
}
@@ -339,7 +339,7 @@ void VDirectoryTree::newSubDirectory()
VDirectory *curDir = getVDirectory(curItem);
QString info = tr("Create a subfolder in %2.")
- .arg(vconfig.c_dataTextStyle).arg(curDir->getName());
+ .arg(g_config->c_dataTextStyle).arg(curDir->getName());
QString text(tr("Folder &name:"));
QString defaultText("new_folder");
@@ -351,7 +351,7 @@ void VDirectoryTree::newSubDirectory()
if (curDir->findSubDirectory(name, false)) {
info = tr("Name (case-insensitive) already exists in "
"%2. Please choose another name.")
- .arg(vconfig.c_dataTextStyle).arg(curDir->getName());
+ .arg(g_config->c_dataTextStyle).arg(curDir->getName());
defaultText = name;
continue;
}
@@ -360,7 +360,7 @@ void VDirectoryTree::newSubDirectory()
if (!subDir) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to create folder %2.")
- .arg(vconfig.c_dataTextStyle).arg(name), "",
+ .arg(g_config->c_dataTextStyle).arg(name), "",
QMessageBox::Ok, QMessageBox::Ok, this);
return;
}
@@ -377,7 +377,7 @@ void VDirectoryTree::newRootDirectory()
return;
}
QString info = tr("Create a root folder in notebook %2.")
- .arg(vconfig.c_dataTextStyle).arg(m_notebook->getName());
+ .arg(g_config->c_dataTextStyle).arg(m_notebook->getName());
QString text(tr("Folder &name:"));
QString defaultText("new_folder");
VDirectory *rootDir = m_notebook->getRootDir();
@@ -388,7 +388,7 @@ void VDirectoryTree::newRootDirectory()
if (rootDir->findSubDirectory(name, false)) {
info = tr("Name (case-insensitive) already exists in "
"notebook %2. Please choose another name.")
- .arg(vconfig.c_dataTextStyle).arg(m_notebook->getName());
+ .arg(g_config->c_dataTextStyle).arg(m_notebook->getName());
defaultText = name;
continue;
}
@@ -396,7 +396,7 @@ void VDirectoryTree::newRootDirectory()
if (!subDir) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to create folder %2.")
- .arg(vconfig.c_dataTextStyle).arg(name), "",
+ .arg(g_config->c_dataTextStyle).arg(name), "",
QMessageBox::Ok, QMessageBox::Ok, this);
return;
}
@@ -416,12 +416,12 @@ void VDirectoryTree::deleteDirectory()
VDirectory *curDir = getVDirectory(curItem);
int ret = VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Are you sure to delete folder %2?")
- .arg(vconfig.c_dataTextStyle).arg(curDir->getName()),
+ .arg(g_config->c_dataTextStyle).arg(curDir->getName()),
tr("WARNING: "
"VNote will delete the whole directory (ANY files) "
"%3."
"
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, this, MessageBoxType::Danger);
if (ret == QMessageBox::Ok) {
@@ -475,7 +475,7 @@ void VDirectoryTree::editDirectoryInfo()
if (!curDir->rename(name)) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to rename folder %2.")
- .arg(vconfig.c_dataTextStyle).arg(curName), "",
+ .arg(g_config->c_dataTextStyle).arg(curName), "",
QMessageBox::Ok, QMessageBox::Ok, this);
return;
}
@@ -679,7 +679,7 @@ bool VDirectoryTree::copyDirectory(VDirectory *p_destDir, const QString &p_destN
} else {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to copy folder %2.")
- .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."),
QMessageBox::Ok, QMessageBox::Ok, this);
}
diff --git a/src/vedit.cpp b/src/vedit.cpp
index 06b64e8e..797fe90f 100644
--- a/src/vedit.cpp
+++ b/src/vedit.cpp
@@ -10,35 +10,35 @@
#include "veditoperations.h"
#include "vedittab.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
extern VNote *g_vnote;
void VEditConfig::init(const QFontMetrics &p_metric)
{
update(p_metric);
- m_enableVimMode = vconfig.getEnableVimMode();
+ m_enableVimMode = g_config->getEnableVimMode();
m_highlightWholeBlock = m_enableVimMode;
}
void VEditConfig::update(const QFontMetrics &p_metric)
{
- if (vconfig.getTabStopWidth() > 0) {
- m_tabStopWidth = vconfig.getTabStopWidth() * p_metric.width(' ');
+ if (g_config->getTabStopWidth() > 0) {
+ m_tabStopWidth = g_config->getTabStopWidth() * p_metric.width(' ');
} else {
m_tabStopWidth = 0;
}
- m_expandTab = vconfig.getIsExpandTab();
+ m_expandTab = g_config->getIsExpandTab();
- if (m_expandTab && (vconfig.getTabStopWidth() > 0)) {
- m_tabSpaces = QString(vconfig.getTabStopWidth(), ' ');
+ if (m_expandTab && (g_config->getTabStopWidth() > 0)) {
+ m_tabSpaces = QString(g_config->getTabStopWidth(), ' ');
} else {
m_tabSpaces = "\t";
}
- m_cursorLineBg = QColor(vconfig.getEditorCurrentLineBg());
+ m_cursorLineBg = QColor(g_config->getEditorCurrentLineBg());
}
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 labelSize = 64;
- m_selectedWordColor = QColor(vconfig.getEditorSelectedWordBg());
- m_searchedWordColor = QColor(vconfig.getEditorSearchedWordBg());
- m_searchedWordCursorColor = QColor(vconfig.getEditorSearchedWordCursorBg());
- m_incrementalSearchedWordColor = QColor(vconfig.getEditorIncrementalSearchedWordBg());
- m_trailingSpaceColor = QColor(vconfig.getEditorTrailingSpaceBg());
+ m_selectedWordColor = QColor(g_config->getEditorSelectedWordBg());
+ m_searchedWordColor = QColor(g_config->getEditorSearchedWordBg());
+ m_searchedWordCursorColor = QColor(g_config->getEditorSearchedWordCursorBg());
+ m_incrementalSearchedWordColor = QColor(g_config->getEditorIncrementalSearchedWordBg());
+ m_trailingSpaceColor = QColor(g_config->getEditorTrailingSpaceBg());
QPixmap wrapPixmap(":/resources/icons/search_wrap.svg");
m_wrapLabel = new QLabel(this);
@@ -467,8 +467,8 @@ void VEdit::labelTimerTimeout()
void VEdit::updateFontAndPalette()
{
- setFont(vconfig.getBaseEditFont());
- setPalette(vconfig.getBaseEditPalette());
+ setFont(g_config->getBaseEditFont());
+ setPalette(g_config->getBaseEditPalette());
}
void VEdit::highlightExtraSelections(bool p_now)
@@ -496,7 +496,7 @@ void VEdit::doHighlightExtraSelections()
void VEdit::highlightCurrentLine()
{
QList &selects = m_extraSelections[(int)SelectionId::CurrentLine];
- if (vconfig.getHighlightCursorLine() && !isReadOnly()) {
+ if (g_config->getHighlightCursorLine() && !isReadOnly()) {
// Need to highlight current line.
selects.clear();
@@ -545,7 +545,7 @@ void VEdit::setReadOnly(bool p_ro)
void VEdit::highlightSelectedWord()
{
QList &selects = m_extraSelections[(int)SelectionId::SelectedWord];
- if (!vconfig.getHighlightSelectedWord()) {
+ if (!g_config->getHighlightSelectedWord()) {
if (!selects.isEmpty()) {
selects.clear();
highlightExtraSelections(true);
@@ -588,7 +588,7 @@ static void trailingSpaceFilter(VEdit *p_editor, QListgetEnableTrailingSpaceHighlight()) {
QList &selects = m_extraSelections[(int)SelectionId::TrailingSapce];
if (!selects.isEmpty()) {
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)
{
QList &selects = m_extraSelections[(int)SelectionId::SearchedKeyword];
- if (!vconfig.getHighlightSearchedWord() || p_text.isEmpty()) {
+ if (!g_config->getHighlightSearchedWord() || p_text.isEmpty()) {
if (!selects.isEmpty()) {
selects.clear();
highlightExtraSelections(true);
@@ -688,7 +688,7 @@ void VEdit::highlightSearchedWordUnderCursor(const QTextCursor &p_cursor)
void VEdit::highlightIncrementalSearchedWord(const QTextCursor &p_cursor)
{
QList &selects = m_extraSelections[(int)SelectionId::IncrementalSearchedKeyword];
- if (!vconfig.getHighlightSearchedWord() || !p_cursor.hasSelection()) {
+ if (!g_config->getHighlightSearchedWord() || !p_cursor.hasSelection()) {
if (!selects.isEmpty()) {
selects.clear();
highlightExtraSelections(true);
@@ -962,7 +962,7 @@ void VEdit::decorateText(TextDecoration p_decoration)
void VEdit::updateLineNumberAreaMargin()
{
int width = 0;
- if (vconfig.getEditorLineNumber()) {
+ if (g_config->getEditorLineNumber()) {
width = m_lineNumberArea->calculateWidth();
}
@@ -971,7 +971,7 @@ void VEdit::updateLineNumberAreaMargin()
void VEdit::updateLineNumberArea()
{
- if (vconfig.getEditorLineNumber()) {
+ if (g_config->getEditorLineNumber()) {
if (!m_lineNumberArea->isVisible()) {
updateLineNumberAreaMargin();
m_lineNumberArea->show();
@@ -988,7 +988,7 @@ void VEdit::resizeEvent(QResizeEvent *p_event)
{
QTextEdit::resizeEvent(p_event);
- if (vconfig.getEditorLineNumber()) {
+ if (g_config->getEditorLineNumber()) {
QRect rect = contentsRect();
m_lineNumberArea->setGeometry(QRect(rect.left(),
rect.top(),
@@ -999,14 +999,14 @@ void VEdit::resizeEvent(QResizeEvent *p_event)
void VEdit::lineNumberAreaPaintEvent(QPaintEvent *p_event)
{
- if (!vconfig.getEditorLineNumber()) {
+ if (!g_config->getEditorLineNumber()) {
updateLineNumberAreaMargin();
m_lineNumberArea->hide();
return;
}
QPainter painter(m_lineNumberArea);
- painter.fillRect(p_event->rect(), vconfig.getEditorLineNumberBg());
+ painter.fillRect(p_event->rect(), g_config->getEditorLineNumberBg());
QTextDocument *doc = document();
QAbstractTextDocumentLayout *layout = doc->documentLayout();
@@ -1021,8 +1021,8 @@ void VEdit::lineNumberAreaPaintEvent(QPaintEvent *p_event)
int eventBtm = p_event->rect().bottom();
const int digitHeight = m_lineNumberArea->getDigitHeight();
const int curBlockNumber = textCursor().block().blockNumber();
- const bool relative = vconfig.getEditorLineNumber() == 2;
- const QString &fg = vconfig.getEditorLineNumberFg();
+ const bool relative = g_config->getEditorLineNumber() == 2;
+ const QString &fg = g_config->getEditorLineNumberFg();
painter.setPen(fg);
while (block.isValid() && top <= eventBtm) {
diff --git a/src/veditarea.cpp b/src/veditarea.cpp
index f1badd3b..301d2497 100644
--- a/src/veditarea.cpp
+++ b/src/veditarea.cpp
@@ -8,7 +8,7 @@
#include "dialog/vfindreplacedialog.h"
#include "utils/vutils.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
extern VNote *g_vnote;
VEditArea::VEditArea(VNote *vnote, QWidget *parent)
@@ -26,13 +26,13 @@ void VEditArea::setupUI()
splitter = new QSplitter(this);
m_findReplace = new VFindReplaceDialog(this);
m_findReplace->setOption(FindOption::CaseSensitive,
- vconfig.getFindCaseSensitive());
+ g_config->getFindCaseSensitive());
m_findReplace->setOption(FindOption::WholeWordOnly,
- vconfig.getFindWholeWordOnly());
+ g_config->getFindWholeWordOnly());
m_findReplace->setOption(FindOption::RegularExpression,
- vconfig.getFindRegularExpression());
+ g_config->getFindRegularExpression());
m_findReplace->setOption(FindOption::IncrementalSearch,
- vconfig.getFindIncrementalSearch());
+ g_config->getFindIncrementalSearch());
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->addWidget(splitter);
@@ -513,10 +513,10 @@ void VEditArea::handleFindTextChanged(const QString &p_text, uint p_options)
void VEditArea::handleFindOptionChanged(uint p_options)
{
qDebug() << "find option changed" << p_options;
- vconfig.setFindCaseSensitive(p_options & FindOption::CaseSensitive);
- vconfig.setFindWholeWordOnly(p_options & FindOption::WholeWordOnly);
- vconfig.setFindRegularExpression(p_options & FindOption::RegularExpression);
- vconfig.setFindIncrementalSearch(p_options & FindOption::IncrementalSearch);
+ g_config->setFindCaseSensitive(p_options & FindOption::CaseSensitive);
+ g_config->setFindWholeWordOnly(p_options & FindOption::WholeWordOnly);
+ g_config->setFindRegularExpression(p_options & FindOption::RegularExpression);
+ g_config->setFindIncrementalSearch(p_options & FindOption::IncrementalSearch);
}
void VEditArea::handleFindNext(const QString &p_text, uint p_options,
diff --git a/src/veditoperations.cpp b/src/veditoperations.cpp
index e856c790..18c87bb3 100644
--- a/src/veditoperations.cpp
+++ b/src/veditoperations.cpp
@@ -6,7 +6,7 @@
#include "vconfigmanager.h"
#include "utils/vutils.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VEditOperations::VEditOperations(VEdit *p_editor, VFile *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) {
switch (m_vim->getMode()) {
case VimMode::Normal:
- m_editConfig->m_cursorLineBg = QColor(vconfig.getEditorVimNormalBg());
+ m_editConfig->m_cursorLineBg = QColor(g_config->getEditorVimNormalBg());
break;
case VimMode::Insert:
- m_editConfig->m_cursorLineBg = QColor(vconfig.getEditorVimInsertBg());
+ m_editConfig->m_cursorLineBg = QColor(g_config->getEditorVimInsertBg());
break;
case VimMode::Visual:
case VimMode::VisualLine:
- m_editConfig->m_cursorLineBg = QColor(vconfig.getEditorVimVisualBg());
+ m_editConfig->m_cursorLineBg = QColor(g_config->getEditorVimVisualBg());
break;
case VimMode::Replace:
- m_editConfig->m_cursorLineBg = QColor(vconfig.getEditorVimReplaceBg());
+ m_editConfig->m_cursorLineBg = QColor(g_config->getEditorVimReplaceBg());
break;
default:
@@ -62,7 +62,7 @@ void VEditOperations::updateCursorLineBg()
break;
}
} else {
- m_editConfig->m_cursorLineBg = QColor(vconfig.getEditorCurrentLineBg());
+ m_editConfig->m_cursorLineBg = QColor(g_config->getEditorCurrentLineBg());
}
m_editor->highlightCurrentLine();
diff --git a/src/veditwindow.cpp b/src/veditwindow.cpp
index 3d92abaf..9622309a 100644
--- a/src/veditwindow.cpp
+++ b/src/veditwindow.cpp
@@ -3,7 +3,6 @@
#include "veditwindow.h"
#include "vedittab.h"
#include "vnote.h"
-#include "vconfigmanager.h"
#include "utils/vutils.h"
#include "vorphanfile.h"
#include "vmainwindow.h"
@@ -13,7 +12,6 @@
#include "vhtmltab.h"
#include "vfilelist.h"
-extern VConfigManager vconfig;
extern VNote *g_vnote;
VEditWindow::VEditWindow(VNote *vnote, VEditArea *editArea, QWidget *parent)
diff --git a/src/vexporter.cpp b/src/vexporter.cpp
index dd24c3ec..d19e5e9a 100644
--- a/src/vexporter.cpp
+++ b/src/vexporter.cpp
@@ -23,7 +23,7 @@
#include "vmarkdownconverter.h"
#include "vdocument.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
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 %2 as %3.")
- .arg(vconfig.c_dataTextStyle)
+ .arg(g_config->c_dataTextStyle)
.arg(m_file->getName())
.arg(exportTypeStr(p_type)));
@@ -218,7 +218,7 @@ void VExporter::initWebViewer(VFile *p_file)
VMarkdownConverter mdConverter;
QString toc;
QString html = mdConverter.generateHtml(p_file->getContent(),
- vconfig.getMarkdownExtensions(),
+ g_config->getMarkdownExtensions(),
toc);
document->setHtml(html);
}
diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp
index 740ca9e2..9be7b205 100644
--- a/src/vfilelist.cpp
+++ b/src/vfilelist.cpp
@@ -11,7 +11,7 @@
#include "vfile.h"
#include "vconfigmanager.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
extern VNote *g_vnote;
VFileList::VFileList(QWidget *parent)
@@ -161,7 +161,7 @@ void VFileList::fileInfo(VFile *p_file)
if (!p_file->rename(name)) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to rename note %2.")
- .arg(vconfig.c_dataTextStyle).arg(curName), "",
+ .arg(g_config->c_dataTextStyle).arg(curName), "",
QMessageBox::Ok, QMessageBox::Ok, this);
return;
}
@@ -220,7 +220,7 @@ void VFileList::newFile()
return;
}
- QList suffixes = vconfig.getDocSuffixes()[(int)DocType::Markdown];
+ QList suffixes = g_config->getDocSuffixes()[(int)DocType::Markdown];
QString defaultSuf;
QString suffixStr;
for (auto const & suf : suffixes) {
@@ -231,7 +231,7 @@ void VFileList::newFile()
}
QString info = tr("Create a note in %2.")
- .arg(vconfig.c_dataTextStyle).arg(m_directory->getName());
+ .arg(g_config->c_dataTextStyle).arg(m_directory->getName());
info = info + "
" + tr("Note with name ending with \"%1\" will be treated as Markdown type.")
.arg(suffixStr);
QString text(tr("Note &name:"));
@@ -251,7 +251,7 @@ void VFileList::newFile()
if (!file) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to create note %2.")
- .arg(vconfig.c_dataTextStyle).arg(name), "",
+ .arg(g_config->c_dataTextStyle).arg(name), "",
QMessageBox::Ok, QMessageBox::Ok, this);
return;
}
@@ -309,10 +309,10 @@ void VFileList::deleteFile(VFile *p_file)
QString fileName = p_file->getName();
int ret = VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Are you sure to delete note %2?")
- .arg(vconfig.c_dataTextStyle).arg(fileName),
+ .arg(g_config->c_dataTextStyle).arg(fileName),
tr("WARNING: The files (including images) "
"deleted may be UNRECOVERABLE!")
- .arg(vconfig.c_warningTextStyle),
+ .arg(g_config->c_warningTextStyle),
QMessageBox::Ok | QMessageBox::Cancel,
QMessageBox::Ok, this, MessageBoxType::Danger);
if (ret == QMessageBox::Ok) {
@@ -486,7 +486,7 @@ void VFileList::pasteFiles(VDirectory *p_destDir)
} else {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to copy note %2.")
- .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."),
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"),
tr("The renaming will change the note type."),
tr("You should close the note %2 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);
if (QMessageBox::Ok == ret) {
if (!editArea->closeFile(p_file, false)) {
diff --git a/src/vhtmltab.cpp b/src/vhtmltab.cpp
index 4fd90950..211cba8c 100644
--- a/src/vhtmltab.cpp
+++ b/src/vhtmltab.cpp
@@ -9,7 +9,7 @@
#include "veditarea.h"
#include "vconstants.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VHtmlTab::VHtmlTab(VFile *p_file, VEditArea *p_editArea,
OpenFileMode p_mode, QWidget *p_parent)
@@ -120,7 +120,7 @@ void VHtmlTab::readFile()
// Prompt to save the changes.
int ret = VUtils::showMessage(QMessageBox::Information, tr("Information"),
tr("Note %2 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?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save, this);
@@ -164,7 +164,7 @@ bool VHtmlTab::saveFile()
qWarning() << filePath << "being written has been removed";
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), tr("Fail to save note."),
tr("File %2 being written has been removed.")
- .arg(vconfig.c_dataTextStyle).arg(filePath),
+ .arg(g_config->c_dataTextStyle).arg(filePath),
QMessageBox::Ok, QMessageBox::Ok, this);
return false;
}
diff --git a/src/vimagepreviewer.cpp b/src/vimagepreviewer.cpp
index 31666acf..af623e7d 100644
--- a/src/vimagepreviewer.cpp
+++ b/src/vimagepreviewer.cpp
@@ -13,7 +13,7 @@
#include "vdownloader.h"
#include "hgmarkdownhighlighter.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
enum ImageProperty { ImagePath = 1 };
@@ -43,7 +43,7 @@ VImagePreviewer::VImagePreviewer(VMdEdit *p_edit, int p_timeToPreview)
void VImagePreviewer::timerTimeout()
{
- if (!vconfig.getEnablePreviewImages()) {
+ if (!g_config->getEnablePreviewImages()) {
if (m_enablePreview) {
disableImagePreview();
}
@@ -355,7 +355,7 @@ void VImagePreviewer::enableImagePreview()
{
m_enablePreview = true;
- if (vconfig.getEnablePreviewImages()) {
+ if (g_config->getEnablePreviewImages()) {
m_timer->stop();
m_timer->start();
}
@@ -542,7 +542,7 @@ bool VImagePreviewer::updateImageWidth(QTextImageFormat &p_format)
if (it != m_imageCache.end()) {
int newWidth = it.value().m_width;
- if (vconfig.getEnablePreviewImageConstraint()) {
+ if (g_config->getEnablePreviewImageConstraint()) {
newWidth = qMin(m_imageWidth, it.value().m_width);
}
diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp
index ce31e733..f0579310 100644
--- a/src/vmainwindow.cpp
+++ b/src/vmainwindow.cpp
@@ -27,7 +27,7 @@
#include "dialog/vorphanfileinfodialog.h"
#include "vsingleinstanceguard.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VNote *g_vnote;
@@ -334,7 +334,7 @@ void VMainWindow::initFileToolBar(QSize p_iconSize)
newNoteAct = new QAction(QIcon(":/resources/icons/create_note_tb.svg"),
tr("New &Note"), this);
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;
newNoteAct->setShortcut(QKeySequence(keySeq));
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"),
tr("&Close Note"), this);
m_closeNoteAct->setStatusTip(tr("Close current note"));
- keySeq = vconfig.getShortcutKeySequence("CloseNote");
+ keySeq = g_config->getShortcutKeySequence("CloseNote");
qDebug() << "set CloseNote shortcut to" << keySeq;
m_closeNoteAct->setShortcut(QKeySequence(keySeq));
connect(m_closeNoteAct, &QAction::triggered,
@@ -368,7 +368,7 @@ void VMainWindow::initFileToolBar(QSize p_iconSize)
editNoteAct = new QAction(QIcon(":/resources/icons/edit_note.svg"),
tr("&Edit"), this);
editNoteAct->setStatusTip(tr("Edit current note"));
- keySeq = vconfig.getShortcutKeySequence("EditNote");
+ keySeq = g_config->getShortcutKeySequence("EditNote");
qDebug() << "set EditNote shortcut to" << keySeq;
editNoteAct->setShortcut(QKeySequence(keySeq));
connect(editNoteAct, &QAction::triggered,
@@ -389,7 +389,7 @@ void VMainWindow::initFileToolBar(QSize p_iconSize)
tr("Save Changes And Read (Ctrl+T)"), this);
saveExitAct->setStatusTip(tr("Save changes and exit edit mode"));
saveExitAct->setMenu(exitEditMenu);
- keySeq = vconfig.getShortcutKeySequence("SaveAndRead");
+ keySeq = g_config->getShortcutKeySequence("SaveAndRead");
qDebug() << "set SaveAndRead shortcut to" << keySeq;
saveExitAct->setShortcut(QKeySequence(keySeq));
connect(saveExitAct, &QAction::triggered,
@@ -398,7 +398,7 @@ void VMainWindow::initFileToolBar(QSize p_iconSize)
saveNoteAct = new QAction(QIcon(":/resources/icons/save_note.svg"),
tr("Save"), this);
saveNoteAct->setStatusTip(tr("Save changes to current note"));
- keySeq = vconfig.getShortcutKeySequence("SaveNote");
+ keySeq = g_config->getShortcutKeySequence("SaveNote");
qDebug() << "set SaveNote shortcut to" << keySeq;
saveNoteAct->setShortcut(QKeySequence(keySeq));
connect(saveNoteAct, &QAction::triggered,
@@ -442,10 +442,10 @@ void VMainWindow::initHelpMenu()
#if defined(QT_NO_DEBUG)
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,
this, [](){
- QUrl url = QUrl::fromLocalFile(vconfig.getLogFilePath());
+ QUrl url = QUrl::fromLocalFile(g_config->getLogFilePath());
QDesktopServices::openUrl(url);
});
#endif
@@ -555,7 +555,7 @@ void VMainWindow::initMarkdownMenu()
converterMenu->addAction(markdownitAct);
converterMenu->addAction(showdownAct);
- MarkdownConverterType converterType = vconfig.getMdConverterType();
+ MarkdownConverterType converterType = g_config->getMdConverterType();
switch (converterType) {
case MarkdownConverterType::Marked:
markedAct->setChecked(true);
@@ -587,7 +587,7 @@ void VMainWindow::initMarkdownMenu()
connect(constrainImageAct, &QAction::triggered,
this, &VMainWindow::enableImageConstraint);
markdownMenu->addAction(constrainImageAct);
- constrainImageAct->setChecked(vconfig.getEnableImageConstraint());
+ constrainImageAct->setChecked(g_config->getEnableImageConstraint());
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)"));
@@ -595,7 +595,7 @@ void VMainWindow::initMarkdownMenu()
connect(imageCaptionAct, &QAction::triggered,
this, &VMainWindow::enableImageCaption);
markdownMenu->addAction(imageCaptionAct);
- imageCaptionAct->setChecked(vconfig.getEnableImageCaption());
+ imageCaptionAct->setChecked(g_config->getEnableImageCaption());
markdownMenu->addSeparator();
@@ -606,17 +606,17 @@ void VMainWindow::initMarkdownMenu()
this, &VMainWindow::enableMermaid);
markdownMenu->addAction(mermaidAct);
- mermaidAct->setChecked(vconfig.getEnableMermaid());
+ mermaidAct->setChecked(g_config->getEnableMermaid());
QAction *flowchartAct = new QAction(tr("&Flowchart.js"), this);
flowchartAct->setToolTip(tr("Enable Flowchart.js for flowchart diagram"));
flowchartAct->setCheckable(true);
connect(flowchartAct, &QAction::triggered,
this, [this](bool p_enabled){
- vconfig.setEnableFlowchart(p_enabled);
+ g_config->setEnableFlowchart(p_enabled);
});
markdownMenu->addAction(flowchartAct);
- flowchartAct->setChecked(vconfig.getEnableFlowchart());
+ flowchartAct->setChecked(g_config->getEnableFlowchart());
QAction *mathjaxAct = new QAction(tr("Math&Jax"), this);
mathjaxAct->setToolTip(tr("Enable MathJax for math support in Markdown"));
@@ -625,7 +625,7 @@ void VMainWindow::initMarkdownMenu()
this, &VMainWindow::enableMathjax);
markdownMenu->addAction(mathjaxAct);
- mathjaxAct->setChecked(vconfig.getEnableMathjax());
+ mathjaxAct->setChecked(g_config->getEnableMathjax());
markdownMenu->addSeparator();
@@ -635,7 +635,7 @@ void VMainWindow::initMarkdownMenu()
connect(codeBlockAct, &QAction::triggered,
this, &VMainWindow::enableCodeBlockHighlight);
markdownMenu->addAction(codeBlockAct);
- codeBlockAct->setChecked(vconfig.getEnableCodeBlockHighlight());
+ codeBlockAct->setChecked(g_config->getEnableCodeBlockHighlight());
QAction *previewImageAct = new QAction(tr("Preview Images In Edit Mode"), this);
previewImageAct->setToolTip(tr("Enable image preview in edit mode"));
@@ -644,7 +644,7 @@ void VMainWindow::initMarkdownMenu()
this, &VMainWindow::enableImagePreview);
// TODO: add the action to the menu after handling the UNDO history well.
// markdownMenu->addAction(previewImageAct);
- previewImageAct->setChecked(vconfig.getEnablePreviewImages());
+ previewImageAct->setChecked(g_config->getEnablePreviewImages());
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"));
@@ -652,7 +652,7 @@ void VMainWindow::initMarkdownMenu()
connect(previewWidthAct, &QAction::triggered,
this, &VMainWindow::enableImagePreviewConstraint);
markdownMenu->addAction(previewWidthAct);
- previewWidthAct->setChecked(vconfig.getEnablePreviewImageConstraint());
+ previewWidthAct->setChecked(g_config->getEnablePreviewImageConstraint());
}
void VMainWindow::initViewMenu()
@@ -747,9 +747,9 @@ void VMainWindow::initFileMenu()
if (ret == QMessageBox::Ok) {
#if defined(Q_OS_MACOS) || defined(Q_OS_MAC)
// 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
- QUrl url = QUrl::fromLocalFile(vconfig.getConfigFilePath());
+ QUrl url = QUrl::fromLocalFile(g_config->getConfigFilePath());
#endif
QDesktopServices::openUrl(url);
}
@@ -792,7 +792,7 @@ void VMainWindow::initEditMenu()
m_findReplaceAct = newAction(QIcon(":/resources/icons/find_replace.svg"),
tr("Find/Replace"), this);
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;
m_findReplaceAct->setShortcut(QKeySequence(keySeq));
connect(m_findReplaceAct, &QAction::triggered,
@@ -800,7 +800,7 @@ void VMainWindow::initEditMenu()
m_findNextAct = new QAction(tr("Find Next"), this);
m_findNextAct->setToolTip(tr("Find next occurence"));
- keySeq = vconfig.getShortcutKeySequence("FindNext");
+ keySeq = g_config->getShortcutKeySequence("FindNext");
qDebug() << "set FindNext shortcut to" << keySeq;
m_findNextAct->setShortcut(QKeySequence(keySeq));
connect(m_findNextAct, SIGNAL(triggered(bool)),
@@ -808,7 +808,7 @@ void VMainWindow::initEditMenu()
m_findPreviousAct = new QAction(tr("Find Previous"), this);
m_findPreviousAct->setToolTip(tr("Find previous occurence"));
- keySeq = vconfig.getShortcutKeySequence("FindPrevious");
+ keySeq = g_config->getShortcutKeySequence("FindPrevious");
qDebug() << "set FindPrevious shortcut to" << keySeq;
m_findPreviousAct->setShortcut(QKeySequence(keySeq));
connect(m_findPreviousAct, SIGNAL(triggered(bool)),
@@ -886,7 +886,7 @@ void VMainWindow::initEditMenu()
smartImAct->setCheckable(true);
connect(smartImAct, &QAction::triggered,
this, [this](bool p_checked){
- vconfig.setEnableSmartImInVimMode(p_checked);
+ g_config->setEnableSmartImInVimMode(p_checked);
});
// Highlight current cursor line.
@@ -924,7 +924,7 @@ void VMainWindow::initEditMenu()
findReplaceMenu->addAction(m_replaceAllAct);
findReplaceMenu->addSeparator();
findReplaceMenu->addAction(searchedWordAct);
- searchedWordAct->setChecked(vconfig.getHighlightSearchedWord());
+ searchedWordAct->setChecked(g_config->getHighlightSearchedWord());
m_findReplaceAct->setEnabled(false);
m_findNextAct->setEnabled(false);
@@ -935,7 +935,7 @@ void VMainWindow::initEditMenu()
editMenu->addSeparator();
editMenu->addAction(expandTabAct);
- if (vconfig.getIsExpandTab()) {
+ if (g_config->getIsExpandTab()) {
expandTabAct->setChecked(true);
} else {
expandTabAct->setChecked(false);
@@ -946,7 +946,7 @@ void VMainWindow::initEditMenu()
tabStopWidthMenu->addAction(twoSpaceTabAct);
tabStopWidthMenu->addAction(fourSpaceTabAct);
tabStopWidthMenu->addAction(eightSpaceTabAct);
- int tabStopWidth = vconfig.getTabStopWidth();
+ int tabStopWidth = g_config->getTabStopWidth();
switch (tabStopWidth) {
case 2:
twoSpaceTabAct->setChecked(true);
@@ -962,20 +962,20 @@ void VMainWindow::initEditMenu()
}
editMenu->addAction(m_autoIndentAct);
- m_autoIndentAct->setChecked(vconfig.getAutoIndent());
+ m_autoIndentAct->setChecked(g_config->getAutoIndent());
editMenu->addAction(autoListAct);
- if (vconfig.getAutoList()) {
+ if (g_config->getAutoList()) {
// Let the trigger handler to trigger m_autoIndentAct, too.
autoListAct->trigger();
}
Q_ASSERT(!(autoListAct->isChecked() && !m_autoIndentAct->isChecked()));
editMenu->addAction(vimAct);
- vimAct->setChecked(vconfig.getEnableVimMode());
+ vimAct->setChecked(g_config->getEnableVimMode());
editMenu->addAction(smartImAct);
- smartImAct->setChecked(vconfig.getEnableSmartImInVimMode());
+ smartImAct->setChecked(g_config->getEnableSmartImInVimMode());
editMenu->addSeparator();
@@ -986,13 +986,13 @@ void VMainWindow::initEditMenu()
initEditorLineNumberMenu(editMenu);
editMenu->addAction(cursorLineAct);
- cursorLineAct->setChecked(vconfig.getHighlightCursorLine());
+ cursorLineAct->setChecked(g_config->getHighlightCursorLine());
editMenu->addAction(selectedWordAct);
- selectedWordAct->setChecked(vconfig.getHighlightSelectedWord());
+ selectedWordAct->setChecked(g_config->getHighlightSelectedWord());
editMenu->addAction(trailingSapceAct);
- trailingSapceAct->setChecked(vconfig.getEnableTrailingSpaceHighlight());
+ trailingSapceAct->setChecked(g_config->getEnableTrailingSpaceHighlight());
}
void VMainWindow::initDockWindows()
@@ -1068,7 +1068,7 @@ void VMainWindow::changeMarkdownConverter(QAction *action)
qDebug() << "switch to converter" << type;
- vconfig.setMarkdownConverterType(type);
+ g_config->setMarkdownConverterType(type);
}
void VMainWindow::aboutMessage()
@@ -1083,37 +1083,37 @@ void VMainWindow::aboutMessage()
void VMainWindow::changeExpandTab(bool checked)
{
- vconfig.setIsExpandTab(checked);
+ g_config->setIsExpandTab(checked);
}
void VMainWindow::enableMermaid(bool p_checked)
{
- vconfig.setEnableMermaid(p_checked);
+ g_config->setEnableMermaid(p_checked);
}
void VMainWindow::enableMathjax(bool p_checked)
{
- vconfig.setEnableMathjax(p_checked);
+ g_config->setEnableMathjax(p_checked);
}
void VMainWindow::changeHighlightCursorLine(bool p_checked)
{
- vconfig.setHighlightCursorLine(p_checked);
+ g_config->setHighlightCursorLine(p_checked);
}
void VMainWindow::changeHighlightSelectedWord(bool p_checked)
{
- vconfig.setHighlightSelectedWord(p_checked);
+ g_config->setHighlightSelectedWord(p_checked);
}
void VMainWindow::changeHighlightSearchedWord(bool p_checked)
{
- vconfig.setHighlightSearchedWord(p_checked);
+ g_config->setHighlightSearchedWord(p_checked);
}
void VMainWindow::changeHighlightTrailingSapce(bool p_checked)
{
- vconfig.setEnableTrailingSapceHighlight(p_checked);
+ g_config->setEnableTrailingSapceHighlight(p_checked);
}
void VMainWindow::setTabStopWidth(QAction *action)
@@ -1121,7 +1121,7 @@ void VMainWindow::setTabStopWidth(QAction *action)
if (!action) {
return;
}
- vconfig.setTabStopWidth(action->data().toInt());
+ g_config->setTabStopWidth(action->data().toInt());
}
void VMainWindow::setEditorBackgroundColor(QAction *action)
@@ -1130,12 +1130,12 @@ void VMainWindow::setEditorBackgroundColor(QAction *action)
return;
}
- vconfig.setCurBackgroundColor(action->data().toString());
+ g_config->setCurBackgroundColor(action->data().toString());
}
void VMainWindow::initPredefinedColorPixmaps()
{
- const QVector &bgColors = vconfig.getPredefinedColors();
+ const QVector &bgColors = g_config->getPredefinedColors();
predefinedColorPixmaps.clear();
int size = 256;
for (int i = 0; i < bgColors.size(); ++i) {
@@ -1155,7 +1155,7 @@ void VMainWindow::initRenderBackgroundMenu(QMenu *menu)
QMenu *renderBgMenu = menu->addMenu(tr("&Rendering Background"));
renderBgMenu->setToolTipsVisible(true);
- const QString &curBgColor = vconfig.getCurRenderBackgroundColor();
+ const QString &curBgColor = g_config->getCurRenderBackgroundColor();
QAction *tmpAct = new QAction(tr("System"), renderBackgroundAct);
tmpAct->setToolTip(tr("Use system's background color configuration for Markdown rendering"));
tmpAct->setCheckable(true);
@@ -1165,7 +1165,7 @@ void VMainWindow::initRenderBackgroundMenu(QMenu *menu)
}
renderBgMenu->addAction(tmpAct);
- const QVector &bgColors = vconfig.getPredefinedColors();
+ const QVector &bgColors = g_config->getPredefinedColors();
for (int i = 0; i < bgColors.size(); ++i) {
tmpAct = new QAction(bgColors[i].name, renderBackgroundAct);
tmpAct->setToolTip(tr("Set as the background color for Markdown rendering"));
@@ -1198,7 +1198,7 @@ void VMainWindow::updateRenderStyleMenu()
}
// Update the menu actions with styles.
- QVector styles = vconfig.getCssStyles();
+ QVector styles = g_config->getCssStyles();
for (auto const &style : styles) {
QAction *act = new QAction(style, m_renderStyleActs);
act->setToolTip(tr("Set as the CSS style for Markdown rendering"));
@@ -1208,7 +1208,7 @@ void VMainWindow::updateRenderStyleMenu()
// Add it to the menu.
menu->addAction(act);
- if (vconfig.getTemplateCss() == style) {
+ if (g_config->getTemplateCss() == style) {
act->setChecked(true);
}
}
@@ -1244,7 +1244,7 @@ void VMainWindow::initEditorBackgroundMenu(QMenu *menu)
this, &VMainWindow::setEditorBackgroundColor);
// System background color
- const QString &curBgColor = vconfig.getCurBackgroundColor();
+ const QString &curBgColor = g_config->getCurBackgroundColor();
QAction *tmpAct = new QAction(tr("System"), backgroundColorAct);
tmpAct->setToolTip(tr("Use system's background color configuration for editor"));
tmpAct->setCheckable(true);
@@ -1253,7 +1253,7 @@ void VMainWindow::initEditorBackgroundMenu(QMenu *menu)
tmpAct->setChecked(true);
}
backgroundColorMenu->addAction(tmpAct);
- const QVector &bgColors = vconfig.getPredefinedColors();
+ const QVector &bgColors = g_config->getPredefinedColors();
for (int i = 0; i < bgColors.size(); ++i) {
tmpAct = new QAction(bgColors[i].name, backgroundColorAct);
tmpAct->setToolTip(tr("Set as the background color for editor"));
@@ -1282,10 +1282,10 @@ void VMainWindow::initEditorLineNumberMenu(QMenu *p_menu)
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"));
act->setToolTip(tr("Do not display line number in edit mode"));
@@ -1329,7 +1329,7 @@ void VMainWindow::updateEditorStyleMenu()
}
// Update the menu actions with styles.
- QVector styles = vconfig.getEditorStyles();
+ QVector styles = g_config->getEditorStyles();
for (auto const &style : styles) {
QAction *act = new QAction(style, m_editorStyleActs);
act->setToolTip(tr("Set as the editor style"));
@@ -1339,7 +1339,7 @@ void VMainWindow::updateEditorStyleMenu()
// Add it to the menu.
menu->addAction(act);
- if (vconfig.getEditorStyle() == style) {
+ if (g_config->getEditorStyle() == style) {
act->setChecked(true);
}
}
@@ -1370,7 +1370,7 @@ void VMainWindow::setRenderBackgroundColor(QAction *action)
if (!action) {
return;
}
- vconfig.setCurRenderBackgroundColor(action->data().toString());
+ g_config->setCurRenderBackgroundColor(action->data().toString());
vnote->updateTemplate();
}
@@ -1383,10 +1383,10 @@ void VMainWindow::setRenderStyle(QAction *p_action)
QString data = p_action->data().toString();
if (data == "AddStyle") {
// Add custom style.
- QUrl url = QUrl::fromLocalFile(vconfig.getStyleConfigFolder());
+ QUrl url = QUrl::fromLocalFile(g_config->getStyleConfigFolder());
QDesktopServices::openUrl(url);
} else {
- vconfig.setTemplateCss(data);
+ g_config->setTemplateCss(data);
vnote->updateTemplate();
}
}
@@ -1400,10 +1400,10 @@ void VMainWindow::setEditorStyle(QAction *p_action)
QString data = p_action->data().toString();
if (data == "AddStyle") {
// Add custom style.
- QUrl url = QUrl::fromLocalFile(vconfig.getStyleConfigFolder());
+ QUrl url = QUrl::fromLocalFile(g_config->getStyleConfigFolder());
QDesktopServices::openUrl(url);
} else {
- vconfig.setEditorStyle(data);
+ g_config->setEditorStyle(data);
}
}
@@ -1573,7 +1573,7 @@ void VMainWindow::deleteCurNote()
void VMainWindow::closeEvent(QCloseEvent *event)
{
- bool isExit = m_requestQuit || !vconfig.getMinimizeToStystemTray();
+ bool isExit = m_requestQuit || !g_config->getMinimizeToStystemTray();
m_requestQuit = false;
#if defined(Q_OS_MACOS) || defined(Q_OS_MAC)
@@ -1581,7 +1581,7 @@ void VMainWindow::closeEvent(QCloseEvent *event)
isExit = true;
#endif
- if (!isExit && vconfig.getMinimizeToStystemTray() == -1) {
+ if (!isExit && g_config->getMinimizeToStystemTray() == -1) {
// Not initialized yet. Prompt for user.
int ret = VUtils::showMessage(QMessageBox::Information,
tr("Close VNote"),
@@ -1592,9 +1592,9 @@ void VMainWindow::closeEvent(QCloseEvent *event)
QMessageBox::Ok,
this);
if (ret == QMessageBox::Ok) {
- vconfig.setMinimizeToSystemTray(1);
+ g_config->setMinimizeToSystemTray(1);
} else if (ret == QMessageBox::No) {
- vconfig.setMinimizeToSystemTray(0);
+ g_config->setMinimizeToSystemTray(0);
isExit = true;
} else {
event->ignore();
@@ -1626,24 +1626,24 @@ void VMainWindow::saveStateAndGeometry()
// panel has a width of zero.
twoPanelView();
- vconfig.setMainWindowGeometry(saveGeometry());
- vconfig.setMainWindowState(saveState());
- vconfig.setToolsDockChecked(toolDock->isVisible());
- vconfig.setMainSplitterState(mainSplitter->saveState());
+ g_config->setMainWindowGeometry(saveGeometry());
+ g_config->setMainWindowState(saveState());
+ g_config->setToolsDockChecked(toolDock->isVisible());
+ g_config->setMainSplitterState(mainSplitter->saveState());
}
void VMainWindow::restoreStateAndGeometry()
{
- const QByteArray &geometry = vconfig.getMainWindowGeometry();
+ const QByteArray &geometry = g_config->getMainWindowGeometry();
if (!geometry.isEmpty()) {
restoreGeometry(geometry);
}
- const QByteArray &state = vconfig.getMainWindowState();
+ const QByteArray &state = g_config->getMainWindowState();
if (!state.isEmpty()) {
restoreState(state);
}
- toolDock->setVisible(vconfig.getToolsDockChecked());
- const QByteArray &splitterState = vconfig.getMainSplitterState();
+ toolDock->setVisible(g_config->getToolsDockChecked());
+ const QByteArray &splitterState = g_config->getMainSplitterState();
if (!splitterState.isEmpty()) {
mainSplitter->restoreState(splitterState);
}
@@ -1781,12 +1781,12 @@ void VMainWindow::closeCurrentFile()
void VMainWindow::changeAutoIndent(bool p_checked)
{
- vconfig.setAutoIndent(p_checked);
+ g_config->setAutoIndent(p_checked);
}
void VMainWindow::changeAutoList(bool p_checked)
{
- vconfig.setAutoList(p_checked);
+ g_config->setAutoList(p_checked);
if (p_checked) {
if (!m_autoIndentAct->isChecked()) {
m_autoIndentAct->trigger();
@@ -1799,34 +1799,34 @@ void VMainWindow::changeAutoList(bool p_checked)
void VMainWindow::changeVimMode(bool p_checked)
{
- vconfig.setEnableVimMode(p_checked);
+ g_config->setEnableVimMode(p_checked);
}
void VMainWindow::enableCodeBlockHighlight(bool p_checked)
{
- vconfig.setEnableCodeBlockHighlight(p_checked);
+ g_config->setEnableCodeBlockHighlight(p_checked);
}
void VMainWindow::enableImagePreview(bool p_checked)
{
- vconfig.setEnablePreviewImages(p_checked);
+ g_config->setEnablePreviewImages(p_checked);
}
void VMainWindow::enableImagePreviewConstraint(bool p_checked)
{
- vconfig.setEnablePreviewImageConstraint(p_checked);
+ g_config->setEnablePreviewImageConstraint(p_checked);
}
void VMainWindow::enableImageConstraint(bool p_checked)
{
- vconfig.setEnableImageConstraint(p_checked);
+ g_config->setEnableImageConstraint(p_checked);
vnote->updateTemplate();
}
void VMainWindow::enableImageCaption(bool p_checked)
{
- vconfig.setEnableImageCaption(p_checked);
+ g_config->setEnableImageCaption(p_checked);
}
void VMainWindow::shortcutHelp()
diff --git a/src/vmdedit.cpp b/src/vmdedit.cpp
index c0979949..9d08ac32 100644
--- a/src/vmdedit.cpp
+++ b/src/vmdedit.cpp
@@ -10,7 +10,7 @@
#include "dialog/vselectdialog.h"
#include "vimagepreviewer.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
extern VNote *g_vnote;
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);
setAcceptRichText(false);
- m_mdHighlighter = new HGMarkdownHighlighter(vconfig.getMdHighlightingStyles(),
- vconfig.getCodeBlockStyles(),
+ m_mdHighlighter = new HGMarkdownHighlighter(g_config->getMdHighlightingStyles(),
+ g_config->getCodeBlockStyles(),
700, document());
connect(m_mdHighlighter, &HGMarkdownHighlighter::highlightCompleted,
this, &VMdEdit::generateEditOutline);
@@ -60,8 +60,8 @@ VMdEdit::VMdEdit(VFile *p_file, VDocument *p_vdoc, MarkdownConverterType p_type,
void VMdEdit::updateFontAndPalette()
{
- setFont(vconfig.getMdEditFont());
- setPalette(vconfig.getMdEditPalette());
+ setFont(g_config->getMdEditFont());
+ setPalette(g_config->getMdEditPalette());
}
void VMdEdit::beginEdit()
@@ -392,7 +392,7 @@ int VMdEdit::removeObjectReplacementLine(QString &p_text, int p_index) const
void VMdEdit::handleSelectionChanged()
{
- if (!vconfig.getEnablePreviewImages()) {
+ if (!g_config->getEnablePreviewImages()) {
return;
}
diff --git a/src/vmdeditoperations.cpp b/src/vmdeditoperations.cpp
index 28c6b673..e407ced8 100644
--- a/src/vmdeditoperations.cpp
+++ b/src/vmdeditoperations.cpp
@@ -24,7 +24,7 @@
#include "utils/vvim.h"
#include "utils/veditutils.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
const QString VMdEditOperations::c_defaultImageTitle = "image";
@@ -63,18 +63,18 @@ void VMdEditOperations::insertImageFromQImage(const QString &title, const QStrin
bool ret = VUtils::makePath(path);
if (!ret) {
errStr = tr("Fail to create image folder %2.")
- .arg(vconfig.c_dataTextStyle).arg(path);
+ .arg(g_config->c_dataTextStyle).arg(path);
} else {
ret = image.save(filePath);
if (!ret) {
errStr = tr("Fail to save image %2.")
- .arg(vconfig.c_dataTextStyle).arg(filePath);
+ .arg(g_config->c_dataTextStyle).arg(filePath);
}
}
if (!ret) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
- tr("Fail to insert image %2.").arg(vconfig.c_dataTextStyle).arg(title),
+ tr("Fail to insert image %2.").arg(g_config->c_dataTextStyle).arg(title),
errStr,
QMessageBox::Ok,
QMessageBox::Ok,
@@ -103,18 +103,18 @@ void VMdEditOperations::insertImageFromPath(const QString &title, const QString
bool ret = VUtils::makePath(path);
if (!ret) {
errStr = tr("Fail to create image folder %2.")
- .arg(vconfig.c_dataTextStyle).arg(path);
+ .arg(g_config->c_dataTextStyle).arg(path);
} else {
ret = QFile::copy(oriImagePath, filePath);
if (!ret) {
errStr = tr("Fail to copy image %2.")
- .arg(vconfig.c_dataTextStyle).arg(filePath);
+ .arg(g_config->c_dataTextStyle).arg(filePath);
}
}
if (!ret) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
- tr("Fail to insert image %2.").arg(vconfig.c_dataTextStyle).arg(title),
+ tr("Fail to insert image %2.").arg(g_config->c_dataTextStyle).arg(title),
errStr,
QMessageBox::Ok,
QMessageBox::Ok,
@@ -576,7 +576,7 @@ bool VMdEditOperations::handleKeyReturn(QKeyEvent *p_event)
bool handled = false;
m_autoIndentPos = -1;
- if (vconfig.getAutoIndent()) {
+ if (g_config->getAutoIndent()) {
handled = true;
QTextCursor cursor = m_editor->textCursor();
@@ -588,7 +588,7 @@ bool VMdEditOperations::handleKeyReturn(QKeyEvent *p_event)
textInserted = VEditUtils::insertBlockWithIndent(cursor);
// Continue the list from previous line.
- if (vconfig.getAutoList() && autolist) {
+ if (g_config->getAutoList() && autolist) {
textInserted = VEditUtils::insertListMarkAsPreviousBlock(cursor) || textInserted;
}
diff --git a/src/vmdtab.cpp b/src/vmdtab.cpp
index 2a02f799..276843fa 100644
--- a/src/vmdtab.cpp
+++ b/src/vmdtab.cpp
@@ -18,12 +18,12 @@
#include "vconstants.h"
#include "vwebview.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VMdTab::VMdTab(VFile *p_file, VEditArea *p_editArea,
OpenFileMode p_mode, QWidget *p_parent)
: 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);
@@ -105,7 +105,7 @@ void VMdTab::viewWebByConverter()
VMarkdownConverter mdConverter;
QString toc;
QString html = mdConverter.generateHtml(m_file->getContent(),
- vconfig.getMarkdownExtensions(),
+ g_config->getMarkdownExtensions(),
toc);
m_document->setHtml(html);
updateTocFromHtml(toc);
@@ -190,7 +190,7 @@ void VMdTab::readFile()
// Prompt to save the changes.
int ret = VUtils::showMessage(QMessageBox::Information, tr("Information"),
tr("Note %2 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?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save, this);
@@ -240,7 +240,7 @@ bool VMdTab::saveFile()
qWarning() << filePath << "being written has been removed";
VUtils::showMessage(QMessageBox::Warning, tr("Warning"), tr("Fail to save note."),
tr("File %2 being written has been removed.")
- .arg(vconfig.c_dataTextStyle).arg(filePath),
+ .arg(g_config->c_dataTextStyle).arg(filePath),
QMessageBox::Ok, QMessageBox::Ok, this);
return false;
}
@@ -278,7 +278,7 @@ void VMdTab::setupMarkdownViewer()
VPreviewPage *page = new VPreviewPage(m_webViewer);
m_webViewer->setPage(page);
- m_webViewer->setZoomFactor(vconfig.getWebZoomFactor());
+ m_webViewer->setZoomFactor(g_config->getWebZoomFactor());
m_document = new VDocument(m_file, m_webViewer);
diff --git a/src/vnote.cpp b/src/vnote.cpp
index c09550f3..eb92170e 100644
--- a/src/vnote.cpp
+++ b/src/vnote.cpp
@@ -13,7 +13,7 @@
#include "vmainwindow.h"
#include "vorphanfile.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
QString VNote::s_markdownTemplate;
QString VNote::s_markdownTemplatePDF;
@@ -55,7 +55,7 @@ VNote::VNote(QObject *parent)
: QObject(parent), m_mainWindow(dynamic_cast(parent))
{
initTemplate();
- vconfig.getNotebooks(m_notebooks, this);
+ g_config->getNotebooks(m_notebooks, this);
}
void VNote::initPalette(QPalette palette)
@@ -169,8 +169,8 @@ void VNote::updateTemplate()
// Get background color
QString rgb;
- const QString &curRenderBg = vconfig.getCurRenderBackgroundColor();
- const QVector &predefinedColors = vconfig.getPredefinedColors();
+ const QString &curRenderBg = g_config->getCurRenderBackgroundColor();
+ const QVector &predefinedColors = g_config->getPredefinedColors();
if (curRenderBg != "System") {
for (int i = 0; i < predefinedColors.size(); ++i) {
if (predefinedColors[i].name == curRenderBg) {
@@ -184,7 +184,7 @@ void VNote::updateTemplate()
cssStyle += "body { background-color: #" + rgb + " !important; }\n";
}
- if (vconfig.getEnableImageConstraint()) {
+ if (g_config->getEnableImageConstraint()) {
// Constain the image width.
cssStyle += "img { max-width: 100% !important; height: auto !important; }\n";
}
@@ -193,7 +193,7 @@ void VNote::updateTemplate()
const QString cssHolder("CSS_PLACE_HOLDER");
s_markdownTemplate = VUtils::readFileFromDisk(c_markdownTemplatePath);
- s_markdownTemplate.replace(cssHolder, vconfig.getTemplateCssUrl());
+ s_markdownTemplate.replace(cssHolder, g_config->getTemplateCssUrl());
s_markdownTemplatePDF = s_markdownTemplate;
@@ -204,7 +204,7 @@ void VNote::updateTemplate()
// Shoudl not display scrollbar in PDF.
cssStyle += "pre code { white-space: pre-wrap !important; "
"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
// be cut off.
cssStyle += "img { max-width: 100% !important; height: auto !important; }\n";
diff --git a/src/vnotebook.cpp b/src/vnotebook.cpp
index 36aee9a5..c42fdbe5 100644
--- a/src/vnotebook.cpp
+++ b/src/vnotebook.cpp
@@ -6,7 +6,7 @@
#include "vconfigmanager.h"
#include "vfile.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VNotebook::VNotebook(const QString &name, const QString &path, QObject *parent)
: QObject(parent), m_name(name)
@@ -221,7 +221,7 @@ VFile *VNotebook::tryLoadFile(const QString &p_path)
const QString &VNotebook::getImageFolder() const
{
if (m_imageFolder.isEmpty()) {
- return vconfig.getImageFolder();
+ return g_config->getImageFolder();
} else {
return m_imageFolder;
}
diff --git a/src/vnotebookselector.cpp b/src/vnotebookselector.cpp
index f18115c7..ba6685f3 100644
--- a/src/vnotebookselector.cpp
+++ b/src/vnotebookselector.cpp
@@ -21,7 +21,7 @@
#include "veditarea.h"
#include "vnofocusitemdelegate.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
extern VNote *g_vnote;
const int VNotebookSelector::c_notebookStartIdx = 1;
@@ -68,7 +68,7 @@ void VNotebookSelector::initActions()
void VNotebookSelector::updateComboBox()
{
- int index = vconfig.getCurNotebookIndex();
+ int index = g_config->getCurNotebookIndex();
disconnect(this, SIGNAL(currentIndexChanged(int)),
this, SLOT(handleCurIndexChanged(int)));
@@ -85,7 +85,7 @@ void VNotebookSelector::updateComboBox()
this, SLOT(handleCurIndexChanged(int)));
if (m_notebooks.isEmpty()) {
- vconfig.setCurNotebookIndex(-1);
+ g_config->setCurNotebookIndex(-1);
setCurrentIndex(0);
} else {
setCurrentIndexNotebook(index);
@@ -140,7 +140,7 @@ void VNotebookSelector::handleCurIndexChanged(int p_index)
tooltip = nb->getName();
}
setToolTip(tooltip);
- vconfig.setCurNotebookIndex(p_index);
+ g_config->setCurNotebookIndex(p_index);
emit curNotebookChanged(nb);
}
@@ -200,13 +200,13 @@ void VNotebookSelector::createNotebook(const QString &p_name,
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to create notebook "
"%2 in %3.")
- .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);
return;
}
m_notebooks.append(nb);
- vconfig.setNotebooks(m_notebooks);
+ g_config->setNotebooks(m_notebooks);
addNotebookItem(nb->getName());
setCurrentIndexNotebook(m_notebooks.size() - 1);
@@ -240,7 +240,7 @@ void VNotebookSelector::deleteNotebook(VNotebook *p_notebook, bool p_deleteFiles
int idx = indexOfNotebook(p_notebook);
m_notebooks.remove(idx);
- vconfig.setNotebooks(m_notebooks);
+ g_config->setNotebooks(m_notebooks);
removeNotebookItem(idx);
@@ -253,7 +253,7 @@ void VNotebookSelector::deleteNotebook(VNotebook *p_notebook, bool p_deleteFiles
tr("Fail to delete the root folder of notebook "
"%2 from disk. You may open "
"the folder and check it manually.")
- .arg(vconfig.c_dataTextStyle).arg(name), "",
+ .arg(g_config->c_dataTextStyle).arg(name), "",
QMessageBox::Open | QMessageBox::Ok,
QMessageBox::Ok, this);
if (cho == QMessageBox::Open) {
@@ -297,7 +297,7 @@ void VNotebookSelector::editNotebookInfo()
updated = true;
notebook->rename(name);
updateComboBoxItem(index, name);
- vconfig.setNotebooks(m_notebooks);
+ g_config->setNotebooks(m_notebooks);
}
QString imageFolder = dialog.getImageFolder();
diff --git a/src/vorphanfile.cpp b/src/vorphanfile.cpp
index a7329d8c..b1a4277b 100644
--- a/src/vorphanfile.cpp
+++ b/src/vorphanfile.cpp
@@ -6,7 +6,7 @@
#include "utils/vutils.h"
#include "vconfigmanager.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VOrphanFile::VOrphanFile(const QString &p_path, QObject *p_parent,
bool p_modifiable, bool p_systemFile)
@@ -51,7 +51,7 @@ QString VOrphanFile::retriveImagePath() const
{
QString folder = m_imageFolder;
if (m_imageFolder.isEmpty()) {
- folder = vconfig.getImageFolderExt();
+ folder = g_config->getImageFolderExt();
}
QFileInfo fi(folder);
@@ -140,7 +140,7 @@ bool VOrphanFile::isRelativeImageFolder() const
{
QString folder = m_imageFolder;
if (m_imageFolder.isEmpty()) {
- folder = vconfig.getImageFolderExt();
+ folder = g_config->getImageFolderExt();
}
return !QFileInfo(folder).isAbsolute();
@@ -150,7 +150,7 @@ QString VOrphanFile::getImageFolderInLink() const
{
QString folder = m_imageFolder;
if (m_imageFolder.isEmpty()) {
- folder = vconfig.getImageFolderExt();
+ folder = g_config->getImageFolderExt();
}
return folder;
diff --git a/src/voutline.cpp b/src/voutline.cpp
index 212a3d87..dd1f7f31 100644
--- a/src/voutline.cpp
+++ b/src/voutline.cpp
@@ -8,10 +8,8 @@
#include "vtoc.h"
#include "utils/vutils.h"
#include "vnote.h"
-#include "vconfigmanager.h"
extern VNote *g_vnote;
-extern VConfigManager vconfig;
VOutline::VOutline(QWidget *parent)
: QTreeWidget(parent), VNavigationMode()
diff --git a/src/vvimindicator.cpp b/src/vvimindicator.cpp
index c0969a1c..648dbf91 100644
--- a/src/vvimindicator.cpp
+++ b/src/vvimindicator.cpp
@@ -14,7 +14,7 @@
#include "vbuttonwithwidget.h"
#include "vedittab.h"
-extern VConfigManager vconfig;
+extern VConfigManager *g_config;
VVimIndicator::VVimIndicator(QWidget *p_parent)
: QWidget(p_parent), m_vim(NULL)
@@ -187,23 +187,23 @@ static QString modeBackgroundColor(VimMode p_mode)
switch (p_mode) {
case VimMode::Normal:
- color = vconfig.getEditorVimNormalBg();
+ color = g_config->getEditorVimNormalBg();
break;
case VimMode::Insert:
- color = vconfig.getEditorVimInsertBg();
+ color = g_config->getEditorVimInsertBg();
break;
case VimMode::Visual:
- color = vconfig.getEditorVimVisualBg();
+ color = g_config->getEditorVimVisualBg();
break;
case VimMode::VisualLine:
- color = vconfig.getEditorVimVisualBg();
+ color = g_config->getEditorVimVisualBg();
break;
case VimMode::Replace:
- color = vconfig.getEditorVimReplaceBg();
+ color = g_config->getEditorVimReplaceBg();
break;
default: