Skip to content

Commit d38bc5e

Browse files
committed
feat(editor): re-add In-Place Preview toggle to Markdown toolbar
Re-add the runtime In-Place Preview toggle button (default on, edit-mode only) to MarkdownViewWindow2's toolbar, migrated from the legacy MarkdownViewWindow. The toggle drives MarkdownEditor::setInplacePreviewEnabled and stays in sync via a runtime member re-applied on lazy editor creation. Refs #2709
1 parent 9ac510d commit d38bc5e

5 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/widgets/markdownviewwindow2.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,20 @@ void MarkdownViewWindow2::addAdditionalRightToolBarActions(QToolBar *p_toolBar)
214214
setEditViewMode(mode);
215215
});
216216
}
217+
218+
// In-place preview toggle (visible only in Edit mode).
219+
{
220+
auto *inplacePreviewAction =
221+
addAction(p_toolBar, ViewWindowToolBarHelper2::InplacePreview);
222+
// setChecked before connect so this does not fire the toggled handler.
223+
inplacePreviewAction->setChecked(m_inplacePreviewEnabled);
224+
connect(inplacePreviewAction, &QAction::toggled, this, [this](bool p_checked) {
225+
m_inplacePreviewEnabled = p_checked;
226+
if (m_mode == ViewWindowMode::Edit && m_editor) {
227+
m_editor->setInplacePreviewEnabled(p_checked);
228+
}
229+
});
230+
}
217231
}
218232

219233
void MarkdownViewWindow2::handlePrint() {
@@ -292,6 +306,9 @@ void MarkdownViewWindow2::setupTextEditor() {
292306
m_previewHelper->setMarkdownEditor(m_editor);
293307
m_editor->setPreviewHelper(m_previewHelper);
294308

309+
// Apply the current in-place preview toggle state to the freshly created editor.
310+
m_editor->setInplacePreviewEnabled(m_inplacePreviewEnabled);
311+
295312
// Set content path and base path from Buffer2.
296313
// contentPath: used by MarkdownEditor::getRelativeLink() for generating relative links.
297314
// basePath: used by vtextedit's PreviewMgr for resolving relative URLs to absolute paths.

src/widgets/markdownviewwindow2.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ protected slots:
216216
QString m_pendingAnchor;
217217
MarkdownEditorConfig::EditViewMode m_editViewMode = MarkdownEditorConfig::EditViewMode::EditOnly;
218218

219+
// Runtime on/off for in-place preview (toolbar toggle). Not persisted; mirrors
220+
// the editor default (VMarkdownEditor::m_inplacePreviewEnabled = true).
221+
bool m_inplacePreviewEnabled = true;
222+
219223
QTimer *m_syncPreviewTimer = nullptr;
220224
QSharedPointer<QPrinter> m_printer;
221225

src/widgets/viewwindow2.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,13 @@ QAction *ViewWindow2::addAction(QToolBar *p_toolBar, ViewWindowToolBarHelper2::A
529529
[act, this]() { act->setVisible(m_mode == ViewWindowMode::Edit); });
530530
break;
531531

532+
case ViewWindowToolBarHelper2::InplacePreview:
533+
// Visible only in Edit mode. Subclass wires the toggled signal.
534+
act->setVisible(false);
535+
connect(this, &ViewWindow2::modeChanged, this,
536+
[act, this]() { act->setVisible(m_mode == ViewWindowMode::Edit); });
537+
break;
538+
532539
case ViewWindowToolBarHelper2::Tag: {
533540
auto *toolBtn = dynamic_cast<QToolButton *>(p_toolBar->widgetForAction(act));
534541
Q_ASSERT(toolBtn);

src/widgets/viewwindowtoolbarhelper2.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@ QAction *ViewWindowToolBarHelper2::addAction(QToolBar *p_tb, Action p_action,
349349
}
350350
break;
351351

352+
case Action::InplacePreview:
353+
act = p_tb->addAction(
354+
generateIcon(p_services, QStringLiteral("inplace_preview_editor.svg")),
355+
QObject::tr("Toggle In-Place Preview"));
356+
act->setProperty("iconName", QStringLiteral("inplace_preview_editor.svg"));
357+
act->setCheckable(true);
358+
break;
359+
352360
case Action::Outline: {
353361
act = p_tb->addAction(generateIcon(p_services, QStringLiteral("outline_editor.svg")),
354362
QObject::tr("Outline"));

src/widgets/viewwindowtoolbarhelper2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class ViewWindowToolBarHelper2 {
5454
// Live preview toggle (Edit mode only).
5555
ToggleLivePreview,
5656

57+
// In-place preview toggle (Edit mode only).
58+
InplacePreview,
59+
5760
// Outline popup button.
5861
Outline,
5962

0 commit comments

Comments
 (0)