aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor/markdowneditor.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2024-01-24 15:07:07 +0100
committerEike Ziller <eike.ziller@qt.io>2024-01-26 11:31:57 +0000
commitf22fa5275e9c4752ab863ae7ffcaa9ae3786864a (patch)
tree962ffcd8344b796808f40e9b219b2a6e12d6c4c3 /src/plugins/texteditor/markdowneditor.cpp
parentd9404208dae192f318d150df4aed502f0a331c76 (diff)
Use ActionBuilder for Markdown editor
Also add method that sets the ParameterAction for the context action. That is an alternative to "binding" the context action, and is useful in this case, since we do not have a QObject that we can use as a parent for the constructor that creates the ParameterAction from scratch. Change-Id: I6ba05208d33460cfa2df9ce8247f7ca30624c22f Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/plugins/texteditor/markdowneditor.cpp')
-rw-r--r--src/plugins/texteditor/markdowneditor.cpp121
1 files changed, 70 insertions, 51 deletions
diff --git a/src/plugins/texteditor/markdowneditor.cpp b/src/plugins/texteditor/markdowneditor.cpp
index b574a76074f..6f250d23eb5 100644
--- a/src/plugins/texteditor/markdowneditor.cpp
+++ b/src/plugins/texteditor/markdowneditor.cpp
@@ -510,57 +510,76 @@ MarkdownEditorFactory::MarkdownEditorFactory()
const auto textContext = Context(MARKDOWNVIEWER_TEXT_CONTEXT);
const auto context = Context(MARKDOWNVIEWER_ID);
- Command *cmd = nullptr;
- cmd = ActionManager::registerAction(&m_emphasisAction, EMPHASIS_ACTION, textContext);
- cmd->setDescription(Tr::tr("Emphasis"));
- QObject::connect(&m_emphasisAction, &QAction::triggered, EditorManager::instance(), [] {
- auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
- if (editor)
- editor->triggerEmphasis();
- });
- cmd = ActionManager::registerAction(&m_strongAction, STRONG_ACTION, textContext);
- cmd->setDescription(Tr::tr("Strong"));
- QObject::connect(&m_strongAction, &QAction::triggered, EditorManager::instance(), [] {
- auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
- if (editor)
- editor->triggerStrong();
- });
- cmd = ActionManager::registerAction(&m_inlineCodeAction, INLINECODE_ACTION, textContext);
- cmd->setDescription(Tr::tr("Inline Code"));
- QObject::connect(&m_inlineCodeAction, &QAction::triggered, EditorManager::instance(), [] {
- auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
- if (editor)
- editor->triggerInlineCode();
- });
- cmd = ActionManager::registerAction(&m_linkAction, LINK_ACTION, textContext);
- cmd->setDescription(Tr::tr("Hyperlink"));
- QObject::connect(&m_linkAction, &QAction::triggered, EditorManager::instance(), [] {
- auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
- if (editor)
- editor->triggerLink();
- });
-
- cmd = ActionManager::registerAction(&m_toggleEditorAction, TOGGLEEDITOR_ACTION, context);
- cmd->setDescription(Tr::tr("Show Editor"));
- QObject::connect(&m_toggleEditorAction, &QAction::triggered, EditorManager::instance(), [] {
- auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
- if (editor)
- editor->toggleEditor();
- });
- cmd = ActionManager::registerAction(&m_togglePreviewAction, TOGGLEPREVIEW_ACTION, context);
- cmd->setDescription(Tr::tr("Show Preview"));
- QObject::connect(&m_togglePreviewAction, &QAction::triggered, EditorManager::instance(), [] {
- auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
- if (editor)
- editor->togglePreview();
- });
- cmd = ActionManager::registerAction(&m_swapAction, SWAPVIEWS_ACTION, context);
- cmd->setDescription(Tr::tr("Swap Views"));
- QObject::connect(&m_swapAction, &QAction::triggered, EditorManager::instance(), [] {
- auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
- if (editor)
- editor->swapViews();
- });
+
+ ActionBuilder(nullptr, EMPHASIS_ACTION)
+ .adopt(&m_emphasisAction)
+ .setText(Tr::tr("Emphasis"))
+ .setContext(textContext)
+ .addOnTriggered(EditorManager::instance(), [] {
+ auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
+ if (editor)
+ editor->triggerEmphasis();
+ });
+
+ ActionBuilder(nullptr, STRONG_ACTION)
+ .adopt(&m_strongAction)
+ .setText("Strong")
+ .setContext(textContext)
+ .addOnTriggered(EditorManager::instance(), [] {
+ auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
+ if (editor)
+ editor->triggerStrong();
+ });
+
+ ActionBuilder(nullptr, INLINECODE_ACTION)
+ .adopt(&m_inlineCodeAction)
+ .setText(Tr::tr("Inline Code"))
+ .setContext(textContext)
+ .addOnTriggered(EditorManager::instance(), [] {
+ auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
+ if (editor)
+ editor->triggerInlineCode();
+ });
+
+ ActionBuilder(nullptr, LINK_ACTION)
+ .adopt(&m_linkAction)
+ .setText(Tr::tr("Hyperlink"))
+ .setContext(textContext)
+ .addOnTriggered(EditorManager::instance(), [] {
+ auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
+ if (editor)
+ editor->triggerLink();
+ });
+
+ ActionBuilder(nullptr, TOGGLEEDITOR_ACTION)
+ .adopt(&m_toggleEditorAction)
+ .setText(Tr::tr("Show Editor"))
+ .setContext(context)
+ .addOnTriggered(EditorManager::instance(), [] {
+ auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
+ if (editor)
+ editor->toggleEditor();
+ });
+
+ ActionBuilder(nullptr, TOGGLEPREVIEW_ACTION)
+ .adopt(&m_togglePreviewAction)
+ .setText(Tr::tr("Show Preview"))
+ .setContext(context)
+ .addOnTriggered(EditorManager::instance(), [] {
+ auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
+ if (editor)
+ editor->togglePreview();
+ });
+
+ ActionBuilder(nullptr, SWAPVIEWS_ACTION)
+ .adopt(&m_swapAction)
+ .setText(Tr::tr("Swap Views"))
+ .setContext(context)
+ .addOnTriggered(EditorManager::instance(), [] {
+ auto editor = qobject_cast<MarkdownEditor *>(EditorManager::currentEditor());
+ if (editor)
+ editor->swapViews();
+ });
}
void MarkdownEditorWidget::findLinkAt(const QTextCursor &cursor,