From e9919c5e4ccf5b8a174b1b918a6a9c5173329549 Mon Sep 17 00:00:00 2001 From: Ali Kianian Date: Thu, 3 Apr 2025 14:59:25 +0300 Subject: [PATCH] QmlDesigner: Update paste action on clipboard changes Fixes: QDS-10999 Change-Id: I03e477be64036ffbd3baf2c2286406f3ef2ae2b7 Reviewed-by: David Schulz --- src/plugins/texteditor/texteditor.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) 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;