support user.css for Markdown editor read mode style

This commit is contained in:
Le Tan 2021-11-03 20:43:11 +08:00
parent dc0a9b1a7d
commit d7bfb956ec
33 changed files with 211 additions and 78 deletions

View File

@ -320,6 +320,8 @@ void Buffer::autoSave()
case EditorConfig::AutoSavePolicy::AutoSave:
if (save(false) != OperationCode::Success) {
qWarning() << "AutoSave failed to save buffer, retry later";
} else {
emit autoSaved();
}
break;

View File

@ -188,6 +188,9 @@ namespace vnotex
void attachmentChanged();
// This buffer is AutoSavePolicy::AutoSave.
void autoSaved();
protected:
virtual ViewWindow *createViewWindowInternal(const QSharedPointer<FileOpenParameters> &p_paras, QWidget *p_parent) = 0;

View File

@ -75,7 +75,10 @@ ConfigMgr::ConfigMgr(bool p_isUnitTest, QObject *p_parent)
} else {
locateConfigFolder();
checkAppConfig();
bool needUpdate = checkAppConfig();
if (needUpdate) {
checkUserConfig();
}
}
m_config->init();
@ -134,7 +137,7 @@ void ConfigMgr::locateConfigFolder()
qInfo() << "user config folder" << m_userConfigFolderPath;
}
void ConfigMgr::checkAppConfig()
bool ConfigMgr::checkAppConfig()
{
bool needUpdate = false;
QDir appConfigDir(m_appConfigFolderPath);
@ -212,7 +215,7 @@ void ConfigMgr::checkAppConfig()
FileUtils::copyFile(getConfigFilePath(Source::Default), mainConfigFilePath);
FileUtils::copyDir(extraDataRoot + QStringLiteral("/web"),
appConfigDir.filePath(QStringLiteral("web")));
return;
return needUpdate;
}
#else
Q_ASSERT(needUpdate);
@ -251,6 +254,27 @@ void ConfigMgr::checkAppConfig()
// Main config file.
FileUtils::copyFile(getConfigFilePath(Source::Default), appConfigDir.filePath(c_configFileName));
return needUpdate;
}
void ConfigMgr::checkUserConfig()
{
// Mainly check if the user config and session config is read-only.
const auto userFile = getConfigFilePath(Source::User);
if (QFileInfo::exists(userFile)) {
if (!(QFile::permissions(userFile) & QFile::WriteUser)) {
qDebug() << "make user config file writable" << userFile;
QFile::setPermissions(userFile, QFile::WriteUser);
}
}
const auto sessionFile = getConfigFilePath(Source::Session);
if (QFileInfo::exists(sessionFile)) {
if (!(QFile::permissions(sessionFile) & QFile::WriteUser)) {
qDebug() << "make session config file writable" << sessionFile;
QFile::setPermissions(sessionFile, QFile::WriteUser);
}
}
}
QString ConfigMgr::getConfigFilePath(Source p_src) const
@ -419,6 +443,17 @@ QString ConfigMgr::getUserSnippetFolder() const
return folderPath;
}
QString ConfigMgr::getUserMarkdownUserStyleFile() const
{
auto folderPath = PathUtils::concatenateFilePath(m_userConfigFolderPath, QStringLiteral("web/css"));
auto filePath = PathUtils::concatenateFilePath(folderPath, QStringLiteral("user.css"));
if (!QFileInfo::exists(filePath)) {
QDir().mkpath(folderPath);
FileUtils::writeFile(filePath, QByteArray());
}
return filePath;
}
QString ConfigMgr::getUserOrAppFile(const QString &p_filePath) const
{
QFileInfo fi(p_filePath);

View File

@ -93,6 +93,9 @@ namespace vnotex
QString getUserSnippetFolder() const;
// web/css/user.css.
QString getUserMarkdownUserStyleFile() const;
// If @p_filePath is absolute, just return it.
// Otherwise, first try to find it in user folder, then in app folder.
QString getUserOrAppFile(const QString &p_filePath) const;
@ -135,7 +138,10 @@ namespace vnotex
// Check if app config exists and is updated.
// Update it if in need.
void checkAppConfig();
// Return true if there is update.
bool checkAppConfig();
void checkUserConfig();
static QString getDefaultConfigFilePath();

View File

@ -1,6 +1,8 @@
#ifndef FILEOPENPARAMETERS_H
#define FILEOPENPARAMETERS_H
#include <functional>
#include <QSharedPointer>
#include "global.h"
@ -12,6 +14,12 @@ namespace vnotex
struct FileOpenParameters
{
enum Hook
{
PostSave,
MaxHook
};
ViewWindowMode m_mode = ViewWindowMode::Read;
// Force to enter m_mode.
@ -41,6 +49,8 @@ namespace vnotex
// Whether should save this file into session.
bool m_sessionEnabled = true;
std::function<void()> m_hooks[Hook::MaxHook];
};
}

View File

@ -176,9 +176,9 @@ const QString &HtmlTemplateHelper::getMarkdownViewerTemplate()
return s_markdownViewerTemplate.m_template;
}
void HtmlTemplateHelper::updateMarkdownViewerTemplate(const MarkdownEditorConfig &p_config)
void HtmlTemplateHelper::updateMarkdownViewerTemplate(const MarkdownEditorConfig &p_config, bool p_force)
{
if (p_config.revision() == s_markdownViewerTemplate.m_revision) {
if (!p_force && p_config.revision() == s_markdownViewerTemplate.m_revision) {
return;
}

View File

@ -85,7 +85,7 @@ namespace vnotex
HtmlTemplateHelper() = delete;
static const QString &getMarkdownViewerTemplate();
static void updateMarkdownViewerTemplate(const MarkdownEditorConfig &p_config);
static void updateMarkdownViewerTemplate(const MarkdownEditorConfig &p_config, bool p_force = false);
static QString generateMarkdownViewerTemplate(const MarkdownEditorConfig &p_config, const Paras &p_paras);

View File

@ -118,5 +118,5 @@ QString MainConfig::getVersion(const QJsonObject &p_jobj)
void MainConfig::doVersionSpecificOverride()
{
// In a new version, we may want to change one value by force.
m_editorConfig->getMarkdownEditorConfig().m_spellCheckEnabled = false;
m_coreConfig->m_docksTabBarIconSize = 26;
}

View File

@ -62,7 +62,7 @@
"OpenLastClosedFile" : "Ctrl+Shift+T"
},
"toolbar_icon_size" : 16,
"docks_tabbar_icon_size" : 20,
"docks_tabbar_icon_size" : 26,
"note_management" : {
"external_node" : {
"//comment" : "Wildcard patterns of files and folders to exclude as external files",
@ -152,6 +152,7 @@
"name" : "global_styles",
"enabled" : true,
"styles" : [
"web/css/user.css",
"web/css/globalstyles.css"
]
},

View File

@ -16,6 +16,7 @@
<file>docs/zh_CN/features_tips.txt</file>
<file>web/markdown-viewer-template.html</file>
<file>web/markdown-export-template.html</file>
<file>web/css/user.css</file>
<file>web/css/globalstyles.css</file>
<file>web/css/markdownit.css</file>
<file>web/css/imageviewer.css</file>

View File

@ -10,7 +10,6 @@ code[class*="language-"],
pre[class*="language-"] {
color: #ccc;
background: none;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-size: 1em;
text-align: left;
white-space: pre;

View File

@ -434,8 +434,10 @@ vnotex--DragDropAreaIndicator QLabel {
}
vnotex--MainWindow QLabel#MainWindowTipsLabel {
font-size: 18pt;
font-size: 20pt;
font-weight: bold;
color: @widgets#mainwindow#tips_label#fg;
background-color: @widgets#mainwindow#tips_label#bg;
}
/* QLineEdit */

View File

@ -642,6 +642,10 @@
"fg" : "@base#icon#selected#fg"
}
}
},
"tips_label" : {
"fg" : "@base#master#fg",
"bg" : "@base#master#bg"
}
}
}

View File

@ -67,7 +67,7 @@
"markdown-editor-styles" : {
"Text" : {
"//comment" : "Support a list of fonts separated by ,",
"font-family" : "冬青黑体, YaHei Consolas Hybrid, Microsoft YaHei, 微软雅黑, Microsoft YaHei UI, WenQuanYi Micro Hei, 文泉驿雅黑, Dengxian, 等线体, STXihei, 华文细黑, Liberation Sans, Droid Sans, NSimSun, 新宋体, SimSun, 宋体, Verdana, Helvetica, sans-serif, Tahoma, Arial, Geneva, Georgia, Times New Roman",
"font-family" : "YaHei Consolas Hybrid, 冬青黑体, Microsoft YaHei, 微软雅黑, Microsoft YaHei UI, WenQuanYi Micro Hei, 文泉驿雅黑, Dengxian, 等线体, STXihei, 华文细黑, Liberation Sans, Droid Sans, NSimSun, 新宋体, SimSun, 宋体, Verdana, Helvetica, Tahoma, Arial, Geneva, Georgia, Times New Roman",
"font-size" : 12,
"text-color" : "#ccd1d8",
"background-color" : "#333842",

View File

@ -1,6 +1,6 @@
body {
margin: 0 auto;
font-family: -apple-system, "Noto Sans", "Helvetica Neue", "Segoe UI", Helvetica, sans-serif, Tahoma, Arial, Geneva, Georgia, Palatino, "Times New Roman", "冬青黑体", "YaHei Consolas Hybrid", "Microsoft YaHei", "微软雅黑", "Microsoft YaHei UI", "WenQuanYi Micro Hei", "文泉驿雅黑", Dengxian, "等线体", STXihei, "华文细黑", "Liberation Sans", "Droid Sans", NSimSun, "新宋体", SimSun, "宋体", "Apple Color Emoji", "Segoe UI Emoji";
font-family: "YaHei Consolas Hybrid", "Noto Sans", "Helvetica Neue", "Segoe UI", Helvetica, Tahoma, Arial, Geneva, Georgia, Palatino, "Times New Roman", "冬青黑体", "Microsoft YaHei", "微软雅黑", "Microsoft YaHei UI", "WenQuanYi Micro Hei", "文泉驿雅黑", Dengxian, "等线体", STXihei, "华文细黑", "Liberation Sans", "Droid Sans", NSimSun, "新宋体", SimSun, "宋体", "Apple Color Emoji", "Segoe UI Emoji";
color: #ccd1d8;
line-height: 1.5;
padding: 16px;
@ -95,7 +95,7 @@ pre {
}
code {
font-family: "YaHei Consolas Hybrid", Consolas, Monaco, Monospace, Courier;
font-family: "YaHei Consolas Hybrid", Consolas, Monaco, "Andale Mono", Monospace, "Courier New";
color: #98c379;
word-break: break-word;
}
@ -107,7 +107,7 @@ pre code {
color: #98c379;
background-color: #2d323b;
line-height: 1.5;
font-family: "YaHei Consolas Hybrid", Consolas, Monaco, Monospace, Courier;
font-family: "YaHei Consolas Hybrid", Consolas, Monaco, "Andale Mono", Monospace, "Courier New";
white-space: pre;
-moz-tab-size: 4;
-o-tab-size: 4;

View File

@ -11,7 +11,6 @@ pre[class*="language-"] {
color: black;
background: none;
text-shadow: 0 1px white;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-size: 1em;
text-align: left;
white-space: pre;

View File

@ -120,7 +120,7 @@ vnotex--DragDropAreaIndicator QLabel {
}
vnotex--MainWindow QLabel#MainWindowTipsLabel {
font-size: 18pt;
font-size: 20pt;
font-weight: bold;
}

View File

@ -63,7 +63,7 @@
"markdown-editor-styles" : {
"Text" : {
"//comment" : "Support a list of fonts separated by ,",
"font-family" : "冬青黑体, YaHei Consolas Hybrid, Microsoft YaHei, 微软雅黑, Microsoft YaHei UI, WenQuanYi Micro Hei, 文泉驿雅黑, Dengxian, 等线体, STXihei, 华文细黑, Liberation Sans, Droid Sans, NSimSun, 新宋体, SimSun, 宋体, Verdana, Helvetica, sans-serif, Tahoma, Arial, Geneva, Georgia, Times New Roman",
"font-family" : "YaHei Consolas Hybrid, 冬青黑体, Microsoft YaHei, 微软雅黑, Microsoft YaHei UI, WenQuanYi Micro Hei, 文泉驿雅黑, Dengxian, 等线体, STXihei, 华文细黑, Liberation Sans, Droid Sans, NSimSun, 新宋体, SimSun, 宋体, Verdana, Helvetica, Tahoma, Arial, Geneva, Georgia, Times New Roman",
"font-size" : 12
}
},

View File

@ -1,6 +1,6 @@
body {
margin: 0 auto;
font-family: -apple-system, "Noto Sans", "Helvetica Neue", "Segoe UI", Helvetica, sans-serif, Tahoma, Arial, Geneva, Georgia, Palatino, "Times New Roman", "冬青黑体", "YaHei Consolas Hybrid", "Microsoft YaHei", "微软雅黑", "Microsoft YaHei UI", "WenQuanYi Micro Hei", "文泉驿雅黑", Dengxian, "等线体", STXihei, "华文细黑", "Liberation Sans", "Droid Sans", NSimSun, "新宋体", SimSun, "宋体", "Apple Color Emoji", "Segoe UI Emoji";
font-family: "YaHei Consolas Hybrid", "Noto Sans", "Helvetica Neue", "Segoe UI", Helvetica, Tahoma, Arial, Geneva, Georgia, Palatino, "Times New Roman", "冬青黑体", "Microsoft YaHei", "微软雅黑", "Microsoft YaHei UI", "WenQuanYi Micro Hei", "文泉驿雅黑", Dengxian, "等线体", STXihei, "华文细黑", "Liberation Sans", "Droid Sans", NSimSun, "新宋体", SimSun, "宋体", "Apple Color Emoji", "Segoe UI Emoji";
color: #222222;
line-height: 1.5;
padding: 16px;
@ -90,7 +90,7 @@ pre {
}
code {
font-family: "YaHei Consolas Hybrid", Consolas, Monaco, Monospace, Courier;
font-family: "YaHei Consolas Hybrid", Consolas, Monaco, "Andale Mono", Monospace, "Courier New";
color: #8E24AA;
word-break: break-word;
}
@ -102,7 +102,7 @@ pre code {
color: #222222;
background-color: #E0E0E0;
line-height: 1.5;
font-family: "YaHei Consolas Hybrid", Consolas, Monaco, Monospace, Courier;
font-family: "YaHei Consolas Hybrid", Consolas, Monaco, "Andale Mono", Monospace, "Courier New";
white-space: pre;
-moz-tab-size: 4;
-o-tab-size: 4;

View File

@ -10,7 +10,6 @@ code[class*="language-"],
pre[class*="language-"] {
color: black;
background: none;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-size: 1em;
text-align: left;
white-space: pre;

View File

@ -434,8 +434,10 @@ vnotex--DragDropAreaIndicator QLabel {
}
vnotex--MainWindow QLabel#MainWindowTipsLabel {
font-size: 18pt;
font-size: 20pt;
font-weight: bold;
color: @widgets#mainwindow#tips_label#fg;
background-color: @widgets#mainwindow#tips_label#bg;
}
/* QLineEdit */

View File

@ -638,6 +638,10 @@
"fg" : "@base#icon#selected#fg"
}
}
},
"tips_label" : {
"fg" : "@base#master#fg",
"bg" : "@base#master#bg"
}
}
}

View File

@ -67,7 +67,7 @@
"markdown-editor-styles" : {
"Text" : {
"//comment" : "Support a list of fonts separated by ,",
"font-family" : "冬青黑体, YaHei Consolas Hybrid, Microsoft YaHei, 微软雅黑, Microsoft YaHei UI, WenQuanYi Micro Hei, 文泉驿雅黑, Dengxian, 等线体, STXihei, 华文细黑, Liberation Sans, Droid Sans, NSimSun, 新宋体, SimSun, 宋体, Verdana, Helvetica, sans-serif, Tahoma, Arial, Geneva, Georgia, Times New Roman",
"font-family" : "YaHei Consolas Hybrid, 冬青黑体, Microsoft YaHei, 微软雅黑, Microsoft YaHei UI, WenQuanYi Micro Hei, 文泉驿雅黑, Dengxian, 等线体, STXihei, 华文细黑, Liberation Sans, Droid Sans, NSimSun, 新宋体, SimSun, 宋体, Verdana, Helvetica, Tahoma, Arial, Geneva, Georgia, Times New Roman",
"font-size" : 12,
"text-color" : "#222222",
"background-color" : "#f5f5f5",

View File

@ -1,6 +1,6 @@
body {
margin: 0 auto;
font-family: -apple-system, "Noto Sans", "Helvetica Neue", "Segoe UI", Helvetica, sans-serif, Tahoma, Arial, Geneva, Georgia, Palatino, "Times New Roman", "冬青黑体", "YaHei Consolas Hybrid", "Microsoft YaHei", "微软雅黑", "Microsoft YaHei UI", "WenQuanYi Micro Hei", "文泉驿雅黑", Dengxian, "等线体", STXihei, "华文细黑", "Liberation Sans", "Droid Sans", NSimSun, "新宋体", SimSun, "宋体", "Apple Color Emoji", "Segoe UI Emoji";
font-family: "YaHei Consolas Hybrid", "Noto Sans", "Helvetica Neue", "Segoe UI", Helvetica, Tahoma, Arial, Geneva, Georgia, Palatino, "Times New Roman", "冬青黑体", "Microsoft YaHei", "微软雅黑", "Microsoft YaHei UI", "WenQuanYi Micro Hei", "文泉驿雅黑", Dengxian, "等线体", STXihei, "华文细黑", "Liberation Sans", "Droid Sans", NSimSun, "新宋体", SimSun, "宋体", "Apple Color Emoji", "Segoe UI Emoji";
color: #222222;
line-height: 1.5;
padding: 16px;
@ -90,7 +90,7 @@ pre {
}
code {
font-family: "YaHei Consolas Hybrid", Consolas, Monaco, Monospace, Courier;
font-family: "YaHei Consolas Hybrid", Consolas, Monaco, "Andale Mono", Monospace, "Courier New";
color: #8e24aa;
word-break: break-word;
}
@ -102,7 +102,7 @@ pre code {
color: #222222;
background-color: #e0e0e0;
line-height: 1.5;
font-family: "YaHei Consolas Hybrid", Consolas, Monaco, Monospace, Courier;
font-family: "YaHei Consolas Hybrid", Consolas, Monaco, "Andale Mono", Monospace, "Courier New";
white-space: pre;
-moz-tab-size: 4;
-o-tab-size: 4;

View File

@ -0,0 +1,2 @@
/* Styles here will be placed in the header of the HTML template as global embedded styles. */
/* This file is to hold customized styles provided by user. */

View File

@ -377,6 +377,11 @@ void MainWindow::closeEvent(QCloseEvent *p_event)
}
if (isVisible()) {
// Avoid geometry corruption caused by fullscreen or minimized window.
const auto state = windowState();
if (state & (Qt::WindowMinimized | Qt::WindowFullScreen)) {
showNormal();
}
saveStateAndGeometry();
}
@ -626,6 +631,15 @@ void MainWindow::updateDockWidgetTabBar()
void MainWindow::exportNotes()
{
if (m_exportDialog) {
MessageBoxHelper::notify(MessageBoxHelper::Information,
tr("There is one export dialog running. Please close it first."),
this);
m_exportDialog->activateWindow();
m_exportDialog->show();
return;
}
auto currentNotebook = m_notebookExplorer->currentNotebook().data();
auto viewWindow = m_viewArea->getCurrentViewWindow();
auto folderNode = m_notebookExplorer->currentExploredFolderNode();
@ -636,17 +650,20 @@ void MainWindow::exportNotes()
if (noteNode && !noteNode->hasContent()) {
noteNode = nullptr;
}
auto dialog = new ExportDialog(currentNotebook,
m_exportDialog = new ExportDialog(currentNotebook,
folderNode,
noteNode,
viewWindow ? viewWindow->getBuffer() : nullptr,
nullptr);
connect(dialog, &QDialog::finished,
this, [this, dialog]() {
dialog->deleteLater();
connect(m_exportDialog, &QDialog::finished,
this, [this]() {
m_exportDialog->deleteLater();
m_exportDialog = nullptr;
});
// Let it be able to run at background.
dialog->show();
m_exportDialog->show();
}
void MainWindow::showTips(const QString &p_message, int p_timeoutMilliseconds)
@ -675,7 +692,7 @@ void MainWindow::setTipsAreaVisible(bool p_visible)
int labelW = m_tipsLabel->width();
int labelH = m_tipsLabel->height();
int x = (width() - labelW) / 2;
int y = (height() - labelH) / 2;
int y = (height() - labelH) / 3;
if (x < 0) {
x = 0;
}

View File

@ -26,6 +26,7 @@ namespace vnotex
class SearchPanel;
class SnippetPanel;
class HistoryPanel;
class ExportDialog;
enum { RESTART_EXIT_CODE = 1000 };
@ -169,6 +170,14 @@ namespace vnotex
HistoryPanel *m_historyPanel = nullptr;
ExportDialog *m_exportDialog = nullptr;
QSystemTrayIcon *m_trayIcon = nullptr;
QLabel *m_tipsLabel = nullptr;
QTimer *m_tipsTimer = nullptr;
bool m_layoutReset = false;
// -1: do not request to quit;
@ -177,12 +186,6 @@ namespace vnotex
Qt::WindowStates m_windowOldState = Qt::WindowMinimized;
QSystemTrayIcon *m_trayIcon = nullptr;
QLabel *m_tipsLabel = nullptr;
QTimer *m_tipsTimer = nullptr;
QStringList m_visibleDocksBeforeExpand;
};
} // ns vnotex

View File

@ -35,6 +35,8 @@ void NotebookSelector::setNotebooks(const QVector<QSharedPointer<Notebook>> &p_n
}
updateGeometry();
m_notebooksInitialized = true;
}
void NotebookSelector::reloadNotebook(const Notebook *p_notebook)
@ -179,7 +181,8 @@ void NotebookSelector::clearNavigation()
void NotebookSelector::mousePressEvent(QMouseEvent *p_event)
{
if (count() == 0) {
// Only when notebooks are loaded and there is no notebook, we could prompt for new notebook.
if (m_notebooksInitialized && count() == 0) {
emit newNotebookRequested();
return;
}

View File

@ -53,6 +53,8 @@ namespace vnotex
int findNotebook(ID p_id) const;
bool m_notebooksInitialized = false;
QVector<QModelIndex> m_navigationIndexes;
};
} // ns vnotex

View File

@ -22,7 +22,10 @@
#include <core/configmgr.h>
#include <core/coreconfig.h>
#include <core/sessionconfig.h>
#include <core/editorconfig.h>
#include <core/markdowneditorconfig.h>
#include <core/fileopenparameters.h>
#include <core/htmltemplatehelper.h>
#include "propertydefs.h"
#include "dialogs/settings/settingsdialog.h"
#include "dialogs/updater.h"
@ -390,38 +393,7 @@ QToolBar *ToolBarHelper::setupSettingsToolBar(MainWindow *p_win, QToolBar *p_too
menu->addSeparator();
menu->addAction(MainWindow::tr("Open User Configuration Folder"),
menu,
[]() {
auto folderPath = ConfigMgr::getInst().getUserFolder();
WidgetUtils::openUrlByDesktop(QUrl::fromLocalFile(folderPath));
});
menu->addAction(MainWindow::tr("Open Default Configuration Folder"),
menu,
[]() {
auto folderPath = ConfigMgr::getInst().getAppFolder();
WidgetUtils::openUrlByDesktop(QUrl::fromLocalFile(folderPath));
});
menu->addSeparator();
menu->addAction(MainWindow::tr("Edit User Configuration"),
menu,
[]() {
auto file = ConfigMgr::getInst().getConfigFilePath(ConfigMgr::Source::User);
auto paras = QSharedPointer<FileOpenParameters>::create();
emit VNoteX::getInst().openFileRequested(file, paras);
});
menu->addAction(MainWindow::tr("Open Default Configuration"),
menu,
[]() {
auto file = ConfigMgr::getInst().getConfigFilePath(ConfigMgr::Source::App);
auto paras = QSharedPointer<FileOpenParameters>::create();
paras->m_readOnly = true;
emit VNoteX::getInst().openFileRequested(file, paras);
});
setupConfigurationMenu(menu);
menu->addSeparator();
@ -546,6 +518,51 @@ QToolBar *ToolBarHelper::setupSettingsToolBar(MainWindow *p_win, QToolBar *p_too
return tb;
}
void ToolBarHelper::setupConfigurationMenu(QMenu *p_menu)
{
auto menu = p_menu->addMenu(MainWindow::tr("Configuration"));
menu->addAction(MainWindow::tr("Edit User Configuration File"),
menu,
[]() {
auto file = ConfigMgr::getInst().getConfigFilePath(ConfigMgr::Source::User);
auto paras = QSharedPointer<FileOpenParameters>::create();
paras->m_sessionEnabled = false;
emit VNoteX::getInst().openFileRequested(file, paras);
});
menu->addAction(MainWindow::tr("Open User Configuration Folder"),
menu,
[]() {
auto folderPath = ConfigMgr::getInst().getUserFolder();
WidgetUtils::openUrlByDesktop(QUrl::fromLocalFile(folderPath));
});
menu->addAction(MainWindow::tr("Open Default Configuration Folder"),
menu,
[]() {
auto folderPath = ConfigMgr::getInst().getAppFolder();
WidgetUtils::openUrlByDesktop(QUrl::fromLocalFile(folderPath));
});
menu->addSeparator();
auto act = menu->addAction(MainWindow::tr("Edit Markdown User Styles"),
menu,
[]() {
const auto file = ConfigMgr::getInst().getUserMarkdownUserStyleFile();
auto paras = QSharedPointer<FileOpenParameters>::create();
paras->m_sessionEnabled = false;
paras->m_hooks[FileOpenParameters::PostSave] = []() {
qDebug() << "post save";
const auto &markdownConfig = ConfigMgr::getInst().getEditorConfig().getMarkdownEditorConfig();
HtmlTemplateHelper::updateMarkdownViewerTemplate(markdownConfig, true);
};
emit VNoteX::getInst().openFileRequested(file, paras);
});
act->setStatusTip(MainWindow::tr("Edit the user styles of Markdown editor read mode"));
}
static const QString c_fgPalette = QStringLiteral("widgets#toolbar#icon#fg");
static const QString c_disabledPalette = QStringLiteral("widgets#toolbar#icon#disabled#fg");
static const QString c_dangerousPalette = QStringLiteral("widgets#toolbar#icon#danger#fg");

View File

@ -36,6 +36,8 @@ namespace vnotex
static QToolBar *setupSettingsToolBar(MainWindow *p_win, QToolBar *p_toolBar);
static void updateQuickAccessMenu(QMenu *p_menu);
static void setupConfigurationMenu(QMenu *p_menu);
};
} // ns vnotex

View File

@ -16,7 +16,6 @@
#include <QWidgetAction>
#include <QActionGroup>
#include <core/fileopenparameters.h>
#include "toolbarhelper.h"
#include "vnotex.h"
#include <utils/iconutils.h>
@ -140,10 +139,17 @@ void ViewWindow::handleBufferChanged(const QSharedPointer<FileOpenParameters> &p
connect(buffer, &Buffer::attachmentChanged,
this, &ViewWindow::attachmentChanged);
connect(buffer, &Buffer::autoSaved,
this, [this]() {
executeHook(FileOpenParameters::PostSave);
});
}
m_sessionEnabled = p_paras->m_sessionEnabled;
m_openParas = p_paras;
handleBufferChangedInternal(p_paras);
emit bufferChanged();
@ -887,9 +893,18 @@ bool ViewWindow::save(bool p_force)
return false;
}
executeHook(FileOpenParameters::PostSave);
return true;
}
void ViewWindow::executeHook(FileOpenParameters::Hook p_hook) const
{
if (m_openParas && m_openParas->m_hooks[p_hook]) {
m_openParas->m_hooks[p_hook]();
}
}
void ViewWindow::updateEditReadDiscardActionState(EditReadDiscardAction *p_act)
{
switch (getMode()) {

View File

@ -7,6 +7,7 @@
#include <buffer/buffer.h>
#include <core/global.h>
#include <core/fileopenparameters.h>
#include "viewwindowtoolbarhelper.h"
#include "viewwindowsession.h"
@ -20,7 +21,6 @@ class QActionGroup;
namespace vnotex
{
class ViewSplit;
struct FileOpenParameters;
class DragDropAreaIndicator;
class DragDropAreaIndicatorInterface;
class OutlineProvider;
@ -262,6 +262,8 @@ namespace vnotex
// Managed by QObject.
FindAndReplaceWidget *m_findAndReplace = nullptr;
QSharedPointer<FileOpenParameters> m_openParas;
private:
struct FindInfo
{
@ -314,6 +316,8 @@ namespace vnotex
void updateImageHostMenu();
void executeHook(FileOpenParameters::Hook p_hook) const;
static ViewWindow::TypeAction toolBarActionToTypeAction(ViewWindowToolBarHelper::Action p_action);
Buffer *m_buffer = nullptr;
@ -324,6 +328,7 @@ namespace vnotex
// Last find info.
FindInfo m_findInfo;
// Whether this ViewWindow should be recored to session.
bool m_sessionEnabled = true;
// Null if this window has not been added to any split.