diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 2560315ad70..8bd65c7018f 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -877,6 +877,7 @@ public: void updateRedoAction(); void updateUndoAction(); void updateCopyAction(bool on); + void updatePasteAction(); public: TextEditorWidget *q; @@ -1074,6 +1075,7 @@ public: QAction *m_copyAction = nullptr; QAction *m_copyHtmlAction = nullptr; QAction *m_cutAction = nullptr; + QAction *m_pasteAction = nullptr; QAction *m_autoIndentAction = nullptr; QAction *m_autoFormatAction = nullptr; QAction *m_visualizeWhitespaceAction = nullptr; @@ -1272,6 +1274,8 @@ TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent) connect(q, &QPlainTextEdit::copyAvailable, this, &TextEditorWidgetPrivate::updateCopyAction); + connect(qApp->clipboard(), &QClipboard::changed, this, &TextEditorWidgetPrivate::updatePasteAction); + m_parenthesesMatchingTimer.setSingleShot(true); m_parenthesesMatchingTimer.setInterval(50); connect(&m_parenthesesMatchingTimer, &QTimer::timeout, @@ -4257,11 +4261,13 @@ void TextEditorWidgetPrivate::registerActions() .addOnTriggered([this] { q->cut(); }) .setScriptable(true) .contextAction(); - m_modifyingActions << ActionBuilder(this, PASTE) - .setContext(m_editorContext) - .addOnTriggered([this] { q->paste(); }) - .setScriptable(true) - .contextAction(); + m_pasteAction = ActionBuilder(this, PASTE) + .setContext(m_editorContext) + .addOnTriggered([this] { q->paste(); }) + .setScriptable(true) + .contextAction(); + m_modifyingActions << m_pasteAction; + ActionBuilder(this, SELECTALL) .setContext(m_editorContext) .setScriptable(true) @@ -4710,7 +4716,7 @@ void TextEditorWidgetPrivate::updateActions() updateRedoAction(); updateUndoAction(); updateCopyAction(q->textCursor().hasSelection()); - + updatePasteAction(); updateOptionalActions(); } @@ -4755,6 +4761,12 @@ void TextEditorWidgetPrivate::updateCopyAction(bool hasCopyableText) m_copyHtmlAction->setEnabled(hasCopyableText); } +void TextEditorWidgetPrivate::updatePasteAction() +{ + if (m_pasteAction) + m_pasteAction->setEnabled(!q->isReadOnly() && !qApp->clipboard()->text(QClipboard::Mode::Clipboard).isEmpty()); +} + bool TextEditorWidget::codeFoldingVisible() const { return d->m_codeFoldingVisible;