From f92e1a9791201c2f7eccd091ef5a81c7ccd104e2 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sat, 24 Jul 2021 12:55:11 +0800 Subject: [PATCH] MarkdownEditor: support disabling in-place preview temporarily --- libs/vtextedit | 2 +- src/data/core/core.qrc | 1 + src/data/core/icons/inplace_preview_editor.svg | 15 +++++++++++++++ src/widgets/historypanel.cpp | 8 ++++++-- src/widgets/markdownviewwindow.cpp | 12 ++++++++++++ src/widgets/viewwindow.cpp | 10 ++++++++++ src/widgets/viewwindowtoolbarhelper.cpp | 9 +++++++++ src/widgets/viewwindowtoolbarhelper.h | 3 ++- 8 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/data/core/icons/inplace_preview_editor.svg diff --git a/libs/vtextedit b/libs/vtextedit index 47902164..922084a3 160000 --- a/libs/vtextedit +++ b/libs/vtextedit @@ -1 +1 @@ -Subproject commit 47902164b0e11f5debfb40deb649d451d650660f +Subproject commit 922084a388e1f135e25297ba84a9d0ca0078ed06 diff --git a/src/data/core/core.qrc b/src/data/core/core.qrc index 554554cd..b4168dce 100644 --- a/src/data/core/core.qrc +++ b/src/data/core/core.qrc @@ -21,6 +21,7 @@ icons/menu.svg icons/settings.svg icons/view.svg + icons/inplace_preview_editor.svg icons/settings_menu.svg icons/whatsthis.svg icons/help_menu.svg diff --git a/src/data/core/icons/inplace_preview_editor.svg b/src/data/core/icons/inplace_preview_editor.svg new file mode 100644 index 00000000..176f2647 --- /dev/null +++ b/src/data/core/icons/inplace_preview_editor.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/src/widgets/historypanel.cpp b/src/widgets/historypanel.cpp index c3918093..9dd35b9f 100644 --- a/src/widgets/historypanel.cpp +++ b/src/widgets/historypanel.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -215,9 +216,12 @@ void HistoryPanel::addItem(const HistoryItemFull &p_hisItem) item->setText(PathUtils::fileNameCheap(p_hisItem.m_item.m_path)); item->setData(Qt::UserRole, p_hisItem.m_item.m_path); if (p_hisItem.m_notebookName.isEmpty()) { - item->setToolTip(p_hisItem.m_item.m_path); + item->setToolTip(tr("%1\n%2").arg(p_hisItem.m_item.m_path, + Utils::dateTimeString(p_hisItem.m_item.m_lastAccessedTimeUtc.toLocalTime()))); } else { - item->setToolTip(tr("[%1] %2").arg(p_hisItem.m_notebookName, p_hisItem.m_item.m_path)); + item->setToolTip(tr("[%1] %2\n%3").arg(p_hisItem.m_notebookName, + p_hisItem.m_item.m_path, + Utils::dateTimeString(p_hisItem.m_item.m_lastAccessedTimeUtc.toLocalTime()))); } } diff --git a/src/widgets/markdownviewwindow.cpp b/src/widgets/markdownviewwindow.cpp index 0d77413e..be1afe79 100644 --- a/src/widgets/markdownviewwindow.cpp +++ b/src/widgets/markdownviewwindow.cpp @@ -250,6 +250,8 @@ void MarkdownViewWindow::setupToolBar() auto toolBar = createToolBar(this); const auto &editorConfig = ConfigMgr::getInst().getEditorConfig(); + const auto &markdownEditorConfig = editorConfig.getMarkdownEditorConfig(); + const int iconSize = editorConfig.getToolBarIconSize(); toolBar->setIconSize(QSize(iconSize, iconSize)); @@ -266,6 +268,16 @@ void MarkdownViewWindow::setupToolBar() addAction(toolBar, ViewWindowToolBarHelper::SectionNumber); + { + auto act = addAction(toolBar, ViewWindowToolBarHelper::InplacePreview); + connect(act, &QAction::triggered, + this, [this, act](bool p_checked) { + if (!isReadMode()) { + m_editor->setInplacePreviewEnabled(p_checked); + } + }); + } + addAction(toolBar, ViewWindowToolBarHelper::TypeHeading); addAction(toolBar, ViewWindowToolBarHelper::TypeBold); addAction(toolBar, ViewWindowToolBarHelper::TypeItalic); diff --git a/src/widgets/viewwindow.cpp b/src/widgets/viewwindow.cpp index 9af9e94d..90c0bb21 100644 --- a/src/widgets/viewwindow.cpp +++ b/src/widgets/viewwindow.cpp @@ -441,6 +441,16 @@ QAction *ViewWindow::addAction(QToolBar *p_toolBar, ViewWindowToolBarHelper::Act break; } + case ViewWindowToolBarHelper::InplacePreview: + { + act = ViewWindowToolBarHelper::addAction(p_toolBar, p_action); + connect(this, &ViewWindow::modeChanged, + this, [this, act]() { + act->setEnabled(inModeCanInsert() && getBuffer()); + }); + break; + } + default: Q_ASSERT(false); break; diff --git a/src/widgets/viewwindowtoolbarhelper.cpp b/src/widgets/viewwindowtoolbarhelper.cpp index 416f3b28..ab437485 100644 --- a/src/widgets/viewwindowtoolbarhelper.cpp +++ b/src/widgets/viewwindowtoolbarhelper.cpp @@ -351,6 +351,15 @@ QAction *ViewWindowToolBarHelper::addAction(QToolBar *p_tb, Action p_action) break; } + case Action::InplacePreview: + { + act = p_tb->addAction(ToolBarHelper::generateIcon("inplace_preview_editor.svg"), + ViewWindow::tr("Toggle In-Place Preview")); + act->setCheckable(true); + act->setChecked(true); + break; + } + default: Q_ASSERT(false); break; diff --git a/src/widgets/viewwindowtoolbarhelper.h b/src/widgets/viewwindowtoolbarhelper.h index 78f1d172..385fdbf1 100644 --- a/src/widgets/viewwindowtoolbarhelper.h +++ b/src/widgets/viewwindowtoolbarhelper.h @@ -43,7 +43,8 @@ namespace vnotex Attachment, Outline, FindAndReplace, - SectionNumber + SectionNumber, + InplacePreview }; static QAction *addAction(QToolBar *p_tb, Action p_action);