diff --git a/changes.md b/changes.md index 59709fca..1afe2599 100644 --- a/changes.md +++ b/changes.md @@ -1,4 +1,10 @@ # Changes History +## v1.3 +- Support code block syntax highlight in edit mode; +- A more pleasant AutoIndent and AutoList; +- `Ctrl+` instead of `Ctrl+Alt+` to insert title; +- Support custom Markdown CSS styles and editor styles; + ## v1.2 - Support **MathJax**. - Fix a crash on macOS. diff --git a/src/resources/icons/add_style.svg b/src/resources/icons/add_style.svg new file mode 100644 index 00000000..86bd5b44 --- /dev/null +++ b/src/resources/icons/add_style.svg @@ -0,0 +1,7 @@ + + + + + + diff --git a/src/translations/vnote_zh_CN.qm b/src/translations/vnote_zh_CN.qm index f3075c82..d7cf79fb 100644 Binary files a/src/translations/vnote_zh_CN.qm and b/src/translations/vnote_zh_CN.qm differ diff --git a/src/translations/vnote_zh_CN.ts b/src/translations/vnote_zh_CN.ts index 1987b356..65192c65 100644 --- a/src/translations/vnote_zh_CN.ts +++ b/src/translations/vnote_zh_CN.ts @@ -970,12 +970,28 @@ 使用该背景色对Markdown进行渲染 - + + + &Add Style + 添加样式 (&A) + + + + Open the folder to add your custom CSS style files + 打开样式文件夹以添加自定义CSS样式文件 + + + Editor &Style 编辑器样式 (&S) - + + Open the folder to add your custom MDHL style files + 打开样式文件夹以添加自定义MDHL样式文件 + + + Set as the editor style 使用该样式设置编辑器 @@ -1131,32 +1147,32 @@ - + System 默认 - + Rendering &Style 渲染样式 (&S) - + Set as the CSS style for Markdown rendering 使用该CSS样式对Markdown进行渲染 - + &Background Color 背景颜色 (&B) - + Use system's background color configuration for editor 为编辑器使用系统的背景色设置 - + Set as the background color for editor 使用该背景色设置编辑器 diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index 4101e03f..79445c89 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -773,35 +773,54 @@ void VMainWindow::initRenderBackgroundMenu(QMenu *menu) } } -void VMainWindow::initRenderStyleMenu(QMenu *p_menu) +void VMainWindow::updateRenderStyleMenu() { - QMenu *styleMenu = p_menu->addMenu(tr("Rendering &Style")); - styleMenu->setToolTipsVisible(true); + QMenu *menu = dynamic_cast(sender()); + V_ASSERT(menu); - QActionGroup *styleAct = new QActionGroup(this); - connect(styleAct, &QActionGroup::triggered, - this, &VMainWindow::setRenderStyle); + QList actions = menu->actions(); + // Remove all other actions except the first one. + for (int i = 1; i < actions.size(); ++i) { + menu->removeAction(actions[i]); + m_renderStyleActs->removeAction(actions[i]); + delete actions[i]; + } - bool foundCurrentCss = false; + // Update the menu actions with styles. QVector styles = vconfig.getCssStyles(); for (auto const &style : styles) { - QAction *act = new QAction(style, styleAct); + QAction *act = new QAction(style, m_renderStyleActs); act->setToolTip(tr("Set as the CSS style for Markdown rendering")); act->setCheckable(true); act->setData(style); + // Add it to the menu. + menu->addAction(act); + if (vconfig.getTemplateCss() == style) { act->setChecked(true); - foundCurrentCss = true; } } +} - if (!foundCurrentCss && styles.isEmpty()) { - delete styleAct; - return; - } +void VMainWindow::initRenderStyleMenu(QMenu *p_menu) +{ + QMenu *styleMenu = p_menu->addMenu(tr("Rendering &Style")); + styleMenu->setToolTipsVisible(true); + connect(styleMenu, &QMenu::aboutToShow, + this, &VMainWindow::updateRenderStyleMenu); - styleMenu->addActions(styleAct->actions()); + m_renderStyleActs = new QActionGroup(this); + connect(m_renderStyleActs, &QActionGroup::triggered, + this, &VMainWindow::setRenderStyle); + + QAction *addAct = new QAction(QIcon(":/resources/icons/add_style.svg"), + tr("&Add Style"), m_renderStyleActs); + addAct->setToolTip(tr("Open the folder to add your custom CSS style files")); + addAct->setCheckable(true); + addAct->setData("AddStyle"); + + styleMenu->addAction(addAct); } void VMainWindow::initEditorBackgroundMenu(QMenu *menu) @@ -838,35 +857,54 @@ void VMainWindow::initEditorBackgroundMenu(QMenu *menu) } } -void VMainWindow::initEditorStyleMenu(QMenu *p_menu) +void VMainWindow::updateEditorStyleMenu() { - QMenu *styleMenu = p_menu->addMenu(tr("Editor &Style")); - styleMenu->setToolTipsVisible(true); + QMenu *menu = dynamic_cast(sender()); + V_ASSERT(menu); - QActionGroup *styleAct = new QActionGroup(this); - connect(styleAct, &QActionGroup::triggered, - this, &VMainWindow::setEditorStyle); + QList actions = menu->actions(); + // Remove all other actions except the first one. + for (int i = 1; i < actions.size(); ++i) { + menu->removeAction(actions[i]); + m_editorStyleActs->removeAction(actions[i]); + delete actions[i]; + } - bool found = false; + // Update the menu actions with styles. QVector styles = vconfig.getEditorStyles(); for (auto const &style : styles) { - QAction *act = new QAction(style, styleAct); + QAction *act = new QAction(style, m_editorStyleActs); act->setToolTip(tr("Set as the editor style")); act->setCheckable(true); act->setData(style); + // Add it to the menu. + menu->addAction(act); + if (vconfig.getEditorStyle() == style) { act->setChecked(true); - found = true; } } +} - if (!found && styles.isEmpty()) { - delete styleAct; - return; - } +void VMainWindow::initEditorStyleMenu(QMenu *p_menu) +{ + QMenu *styleMenu = p_menu->addMenu(tr("Editor &Style")); + styleMenu->setToolTipsVisible(true); + connect(styleMenu, &QMenu::aboutToShow, + this, &VMainWindow::updateEditorStyleMenu); - styleMenu->addActions(styleAct->actions()); + m_editorStyleActs = new QActionGroup(this); + connect(m_editorStyleActs, &QActionGroup::triggered, + this, &VMainWindow::setEditorStyle); + + QAction *addAct = new QAction(QIcon(":/resources/icons/add_style.svg"), + tr("&Add Style"), m_editorStyleActs); + addAct->setToolTip(tr("Open the folder to add your custom MDHL style files")); + addAct->setCheckable(true); + addAct->setData("AddStyle"); + + styleMenu->addAction(addAct); } void VMainWindow::setRenderBackgroundColor(QAction *action) @@ -884,8 +922,15 @@ void VMainWindow::setRenderStyle(QAction *p_action) return; } - vconfig.setTemplateCss(p_action->data().toString()); - vnote->updateTemplate(); + QString data = p_action->data().toString(); + if (data == "AddStyle") { + // Add custom style. + QUrl url = QUrl::fromLocalFile(vconfig.getStyleConfigFolder()); + QDesktopServices::openUrl(url); + } else { + vconfig.setTemplateCss(data); + vnote->updateTemplate(); + } } void VMainWindow::setEditorStyle(QAction *p_action) @@ -894,7 +939,14 @@ void VMainWindow::setEditorStyle(QAction *p_action) return; } - vconfig.setEditorStyle(p_action->data().toString()); + QString data = p_action->data().toString(); + if (data == "AddStyle") { + // Add custom style. + QUrl url = QUrl::fromLocalFile(vconfig.getStyleConfigFolder()); + QDesktopServices::openUrl(url); + } else { + vconfig.setEditorStyle(data); + } } void VMainWindow::updateActionStateFromTabStatusChange(const VFile *p_file, diff --git a/src/vmainwindow.h b/src/vmainwindow.h index e2385610..e4298749 100644 --- a/src/vmainwindow.h +++ b/src/vmainwindow.h @@ -54,6 +54,8 @@ private slots: void setRenderBackgroundColor(QAction *action); void setRenderStyle(QAction *p_action); void setEditorStyle(QAction *p_action); + void updateRenderStyleMenu(); + void updateEditorStyleMenu(); void changeHighlightCursorLine(bool p_checked); void changeHighlightSelectedWord(bool p_checked); void changeHighlightSearchedWord(bool p_checked); @@ -158,6 +160,9 @@ private: QAction *m_autoIndentAct; + QActionGroup *m_renderStyleActs; + QActionGroup *m_editorStyleActs; + // Menus QMenu *viewMenu; diff --git a/src/vnote.qrc b/src/vnote.qrc index 9ab465ec..1556fe27 100644 --- a/src/vnote.qrc +++ b/src/vnote.qrc @@ -99,5 +99,6 @@ resources/docs/shortcuts_en.md resources/docs/shortcuts_zh.md resources/styles/default.css + resources/icons/add_style.svg