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 "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 <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->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 <span style=\"%1\">%2</span>.")
.arg(vconfig.c_dataTextStyle).arg(m_path));
.arg(g_config->c_dataTextStyle).arg(m_path));
} else {
m_warningLabel->setText(tr("<span style=\"%1\">WARNING</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. "
"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 "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("<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.")
.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 "
"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("<span style=\"%1\">WARNING</span>: 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("<span style=\"%1\">WARNING</span>: The folder chosen has already been a root folder "
"of existing notebook <span style=\"%2\">%3</span> 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("<span style=\"%1\">WARNING</span>: 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))) {

View File

@ -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("<span style=\"%1\">WARNING</span>: Name (case-insensitive) already exists. "
"Please choose another name.")
.arg(vconfig.c_warningTextStyle);
.arg(g_config->c_warningTextStyle);
m_warnLabel->setText(nameConflictText);
}
}

View File

@ -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."

View File

@ -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;

View File

@ -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("<span style=\"font-weight: bold;\">Updates Available!</span><br/>"
"Please visit <a href=\"%1\">Github Releases</a> to download the latest version.")
.arg(releaseUrl));

View File

@ -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;
}

View File

@ -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;

View File

@ -24,7 +24,7 @@
#include "vfile.h"
#include "vnote.h"
extern VConfigManager vconfig;
extern VConfigManager *g_config;
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) {
QPushButton *okBtn = dynamic_cast<QPushButton *>(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<int, QList<QString>> &suffixes = vconfig.getDocSuffixes();
const QHash<int, QList<QString>> &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 += "<link rel=\"stylesheet\" type=\"text/css\" href=\"qrc" + VNote::c_mermaidCssFile + "\"/>\n" +
"<script src=\"qrc" + VNote::c_mermaidApiJsFile + "\"></script>\n" +
"<script>var VEnableMermaid = true;</script>\n";
}
if (vconfig.getEnableFlowchart()) {
if (g_config->getEnableFlowchart()) {
extraFile += "<script src=\"qrc" + VNote::c_raphaelJsFile + "\"></script>\n" +
"<script src=\"qrc" + VNote::c_flowchartJsFile + "\"></script>\n" +
"<script>var VEnableFlowchart = true;</script>\n";
}
if (vconfig.getEnableMathjax()) {
if (g_config->getEnableMathjax()) {
extraFile += "<script type=\"text/x-mathjax-config\">"
"MathJax.Hub.Config({\n"
" tex2jax: {inlineMath: [['$','$'], ['\\\\(','\\\\)']]},\n"
@ -544,7 +544,7 @@ QString VUtils::generateHtmlTemplate(MarkdownConverterType p_conType, bool p_exp
"<script>var VEnableMathjax = true;</script>\n";
}
if (vconfig.getEnableImageCaption()) {
if (g_config->getEnableImageCaption()) {
extraFile += "<script>var VEnableImageCaption = true;</script>\n";
}

View File

@ -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);
}

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;}");
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();

View File

@ -1,6 +1,7 @@
#ifndef VCONFIGMANAGER_H
#define VCONFIGMANAGER_H
#include <QObject>
#include <QFont>
#include <QPalette>
#include <QVector>
@ -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();

View File

@ -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 <span style=\"%1\">%2</span>.")
.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 <span style=\"%1\">%2</span> "
"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 <span style=\"%1\">%2</span> while "
"%5 note <span style=\"%3\">%4</span>.")
.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);
}

View File

@ -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 <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);
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 <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);
return;
}
@ -339,7 +339,7 @@ void VDirectoryTree::newSubDirectory()
VDirectory *curDir = getVDirectory(curItem);
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 defaultText("new_folder");
@ -351,7 +351,7 @@ void VDirectoryTree::newSubDirectory()
if (curDir->findSubDirectory(name, false)) {
info = tr("Name (case-insensitive) already exists in "
"<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;
continue;
}
@ -360,7 +360,7 @@ void VDirectoryTree::newSubDirectory()
if (!subDir) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
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);
return;
}
@ -377,7 +377,7 @@ void VDirectoryTree::newRootDirectory()
return;
}
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 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 <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;
continue;
}
@ -396,7 +396,7 @@ void VDirectoryTree::newRootDirectory()
if (!subDir) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
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);
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 <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>: "
"VNote will delete the whole directory (<b>ANY</b> files) "
"<span style=\"%2\">%3</span>."
"<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, 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 <span style=\"%1\">%2</span>.")
.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 <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."),
QMessageBox::Ok, QMessageBox::Ok, this);
}

View File

@ -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<QTextEdit::ExtraSelection> &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<QTextEdit::ExtraSelection> &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, QList<QTextEdit::ExtraSelection
void VEdit::highlightTrailingSpace()
{
if (!vconfig.getEnableTrailingSpaceHighlight()) {
if (!g_config->getEnableTrailingSpaceHighlight()) {
QList<QTextEdit::ExtraSelection> &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<QTextEdit::ExtraSelection> &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<QTextEdit::ExtraSelection> &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) {

View File

@ -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,

View File

@ -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();

View File

@ -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)

View File

@ -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 <span style=\"%1\">%2</span> 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);
}

View File

@ -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 <span style=\"%1\">%2</span>.")
.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<QString> suffixes = vconfig.getDocSuffixes()[(int)DocType::Markdown];
QList<QString> 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 <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.")
.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 <span style=\"%1\">%2</span>.")
.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 <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) "
"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 <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."),
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 <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);
if (QMessageBox::Ok == ret) {
if (!editArea->closeFile(p_file, false)) {

View File

@ -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 <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?"),
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 <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);
return false;
}

View File

@ -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);
}

View File

@ -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<VColor> &bgColors = vconfig.getPredefinedColors();
const QVector<VColor> &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<VColor> &bgColors = vconfig.getPredefinedColors();
const QVector<VColor> &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<QString> styles = vconfig.getCssStyles();
QVector<QString> 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<VColor> &bgColors = vconfig.getPredefinedColors();
const QVector<VColor> &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<QString> styles = vconfig.getEditorStyles();
QVector<QString> 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()

View File

@ -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;
}

View File

@ -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 <span style=\"%1\">%2</span>.")
.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 <span style=\"%1\">%2</span>.")
.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 <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,
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 <span style=\"%1\">%2</span>.")
.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 <span style=\"%1\">%2</span>.")
.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 <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,
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;
}

View File

@ -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 <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?"),
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 <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);
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);

View File

@ -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<VMainWindow *>(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<VColor> &predefinedColors = vconfig.getPredefinedColors();
const QString &curRenderBg = g_config->getCurRenderBackgroundColor();
const QVector<VColor> &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";

View File

@ -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;
}

View File

@ -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 "
"<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);
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 "
"<span style=\"%1\">%2</span> 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();

View File

@ -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;

View File

@ -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()

View File

@ -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: