From 2d678bdcf6d23dc82ad5edbb55443003e170fca3 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 29 Apr 2021 23:38:45 +0200 Subject: [PATCH] Allow copying messages via right click fixes #291 --- resources/qml/MessageView.qml | 2 +- resources/qml/TimelineRow.qml | 4 ++-- resources/qml/TimelineView.qml | 14 +++++++++++++- resources/qml/delegates/TextMessage.qml | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml index 29c658f7..1f483bf9 100644 --- a/resources/qml/MessageView.qml +++ b/resources/qml/MessageView.qml @@ -117,7 +117,7 @@ ScrollView { image: ":/icons/icons/ui/vertical-ellipsis.png" ToolTip.visible: hovered ToolTip.text: qsTr("Options") - onClicked: messageContextMenu.show(row.model.id, row.model.type, row.model.isEncrypted, row.model.isEditable, "", optionsButton) + onClicked: messageContextMenu.show(row.model.id, row.model.type, row.model.isEncrypted, row.model.isEditable, "", row.model.body, optionsButton) } } diff --git a/resources/qml/TimelineRow.qml b/resources/qml/TimelineRow.qml index e9c8b297..7bc3df63 100644 --- a/resources/qml/TimelineRow.qml +++ b/resources/qml/TimelineRow.qml @@ -28,12 +28,12 @@ Item { TapHandler { acceptedButtons: Qt.RightButton - onSingleTapped: messageContextMenu.show(model.id, model.type, model.isEncrypted, model.isEditable, contentItem.child.hoveredLink) + onSingleTapped: messageContextMenu.show(model.id, model.type, model.isEncrypted, model.isEditable, contentItem.child.hoveredLink, contentItem.child.copyText) gesturePolicy: TapHandler.ReleaseWithinBounds } TapHandler { - onLongPressed: messageContextMenu.show(model.id, model.type, model.isEncrypted, model.isEditable, contentItem.child.hoveredLink) + onLongPressed: messageContextMenu.show(model.id, model.type, model.isEncrypted, model.isEditable, contentItem.child.hoveredLink, contentItem.child.copyText) onDoubleTapped: chat.model.reply = model.id gesturePolicy: TapHandler.ReleaseWithinBounds } diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index ce5d54c0..442047d5 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -93,15 +93,20 @@ Page { property string eventId property string link + property string text property int eventType property bool isEncrypted property bool isEditable - function show(eventId_, eventType_, isEncrypted_, isEditable_, link_, showAt_) { + function show(eventId_, eventType_, isEncrypted_, isEditable_, link_, text_, showAt_) { eventId = eventId_; eventType = eventType_; isEncrypted = isEncrypted_; isEditable = isEditable_; + if (text_) + text = text_; + else + text = ""; if (link_) link = link_; else @@ -112,6 +117,13 @@ Page { open(); } + Platform.MenuItem { + visible: messageContextMenu.text + enabled: visible + text: qsTr("Copy") + onTriggered: Clipboard.text = messageContextMenu.text + } + Platform.MenuItem { visible: messageContextMenu.link enabled: visible diff --git a/resources/qml/delegates/TextMessage.qml b/resources/qml/delegates/TextMessage.qml index 1624d95c..f44165b4 100644 --- a/resources/qml/delegates/TextMessage.qml +++ b/resources/qml/delegates/TextMessage.qml @@ -7,6 +7,7 @@ import im.nheko 1.0 MatrixText { property string formatted: model.data.formattedBody + property string copyText: selectedText ? getText(selectionStart, selectionEnd) : model.data.body text: "" + formatted.replace("
", "
")
     width: parent ? parent.width : undefined