Markdown: Fix that text editing actions were not available

Add the TextEditorActionHandler and point it to the text editor.

Change-Id: I2c84d6b0160c7402ea32d56ed4dbc72d512072a1
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Eike Ziller
2023-04-19 15:09:49 +02:00
parent 1c60f57340
commit 71f9e536c5
2 changed files with 37 additions and 11 deletions

View File

@@ -21,6 +21,7 @@
namespace TextEditor::Internal { namespace TextEditor::Internal {
const char MARKDOWNVIEWER_ID[] = "Editors.MarkdownViewer"; const char MARKDOWNVIEWER_ID[] = "Editors.MarkdownViewer";
const char MARKDOWNVIEWER_TEXT_CONTEXT[] = "Editors.MarkdownViewer.Text";
const char MARKDOWNVIEWER_MIME_TYPE[] = "text/markdown"; const char MARKDOWNVIEWER_MIME_TYPE[] = "text/markdown";
class MarkdownEditor : public Core::IEditor class MarkdownEditor : public Core::IEditor
@@ -38,10 +39,14 @@ public:
new Utils::MarkdownHighlighter(browser->document()); new Utils::MarkdownHighlighter(browser->document());
// Right side (hidable) // Right side (hidable)
auto editor = new TextEditorWidget(&m_widget); m_textEditorWidget = new TextEditorWidget(&m_widget);
editor->setTextDocument(m_document); m_textEditorWidget->setTextDocument(m_document);
editor->setupGenericHighlighter(); m_textEditorWidget->setupGenericHighlighter();
editor->setMarksVisible(false); m_textEditorWidget->setMarksVisible(false);
auto context = new Core::IContext(this);
context->setWidget(m_textEditorWidget);
context->setContext(Core::Context(MARKDOWNVIEWER_TEXT_CONTEXT));
Core::ICore::addContextObject(context);
setContext(Core::Context(MARKDOWNVIEWER_ID)); setContext(Core::Context(MARKDOWNVIEWER_ID));
setWidget(&m_widget); setWidget(&m_widget);
@@ -60,12 +65,20 @@ public:
connect(m_document.data(), &TextDocument::mimeTypeChanged, connect(m_document.data(), &TextDocument::mimeTypeChanged,
m_document.data(), &TextDocument::changed); m_document.data(), &TextDocument::changed);
connect(toggleEditorVisible, &QToolButton::toggled, connect(toggleEditorVisible,
editor, [editor, toggleEditorVisible](bool editorVisible) { &QToolButton::toggled,
if (editor->isVisible() == editorVisible) m_textEditorWidget,
[this, browser, toggleEditorVisible](bool editorVisible) {
if (m_textEditorWidget->isVisible() == editorVisible)
return; return;
editor->setVisible(editorVisible); m_textEditorWidget->setVisible(editorVisible);
toggleEditorVisible->setText(editorVisible ? Tr::tr("Hide Editor") : Tr::tr("Show Editor")); if (editorVisible)
m_textEditorWidget->setFocus();
else
browser->setFocus();
toggleEditorVisible->setText(editorVisible ? Tr::tr("Hide Editor")
: Tr::tr("Show Editor"));
}); });
connect(m_document->document(), &QTextDocument::contentsChanged, this, [this, browser] { connect(m_document->document(), &QTextDocument::contentsChanged, this, [this, browser] {
@@ -87,14 +100,22 @@ public:
QWidget *toolBar() override { return &m_toolbar; } QWidget *toolBar() override { return &m_toolbar; }
Core::IDocument *document() const override { return m_document.data(); } Core::IDocument *document() const override { return m_document.data(); }
TextEditorWidget *textEditorWidget() const { return m_textEditorWidget; }
private: private:
Core::MiniSplitter m_widget; Core::MiniSplitter m_widget;
TextEditorWidget *m_textEditorWidget;
TextDocumentPtr m_document; TextDocumentPtr m_document;
QWidget m_toolbar; QWidget m_toolbar;
}; };
MarkdownEditorFactory::MarkdownEditorFactory() MarkdownEditorFactory::MarkdownEditorFactory()
: m_actionHandler(MARKDOWNVIEWER_ID,
MARKDOWNVIEWER_TEXT_CONTEXT,
TextEditor::TextEditorActionHandler::None,
[](Core::IEditor *editor) {
return static_cast<MarkdownEditor *>(editor)->textEditorWidget();
})
{ {
setId(MARKDOWNVIEWER_ID); setId(MARKDOWNVIEWER_ID);
setDisplayName(::Core::Tr::tr("Markdown Viewer")); setDisplayName(::Core::Tr::tr("Markdown Viewer"));

View File

@@ -5,12 +5,17 @@
#include <coreplugin/editormanager/ieditorfactory.h> #include <coreplugin/editormanager/ieditorfactory.h>
#include <texteditor/texteditoractionhandler.h>
namespace TextEditor::Internal { namespace TextEditor::Internal {
class MarkdownEditorFactory final : public Core::IEditorFactory class MarkdownEditorFactory final : public Core::IEditorFactory
{ {
public: public:
MarkdownEditorFactory(); MarkdownEditorFactory();
private:
TextEditor::TextEditorActionHandler m_actionHandler;
}; };
} // TextEditor::Internal } // TextEditor::Internal