Commit 61f835c1 authored by Jonah Brüchert's avatar Jonah Brüchert 🌳 Committed by Linus Jahn

Only create one contextMenu and pass around references to it

parent 4e84f229
Pipeline #17030 passed with stages
in 78 minutes and 59 seconds
......@@ -425,6 +425,40 @@ ChatPageBase {
// Connect to the database,
model: Kaidan.messageModel
Controls.Menu {
id: contextMenu
property ChatMessage message
Controls.MenuItem {
text: qsTr("Copy Message")
enabled: bodyLabel.visible
onTriggered: {
if (!contextMenu.message.isSpoiler || contextMenu.message.isShowingSpoiler)
Utils.copyToClipboard(contextMenu.message.messageBody);
else
Utils.copyToClipboard(contextMenu.message.spoilerHint);
}
}
Controls.MenuItem {
text: qsTr("Edit Message")
enabled: Kaidan.messageModel.canCorrectMessage(contextMenu.message.msgId)
onTriggered: root.messageEditRequested(message.msgId, contextMenu.message.messageBody)
}
Controls.MenuItem {
text: qsTr("Copy download URL")
enabled: mediaGetUrl
onTriggered: Utils.copyToClipboard(contextMenu.message.mediaGetUrl)
}
Controls.MenuItem {
text: qsTr("Quote")
onTriggered: {
root.quoteRequested(contextMenu.message.messageBody)
}
}
}
delegate: ChatMessage {
msgId: model.id
sender: model.sender
......@@ -441,6 +475,8 @@ ChatPageBase {
isShowingSpoiler: false
spoilerHint: model.spoilerHint
menu: contextMenu
onMessageEditRequested: {
messageToCorrect = id
messageField.text = body
......
......@@ -40,6 +40,8 @@ import MediaUtils 0.1
RowLayout {
id: root
property Controls.Menu menu
property string msgId
property string sender
property bool sentByMe: true
......@@ -112,46 +114,16 @@ RowLayout {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
if (mouse.button === Qt.RightButton)
contextMenu.popup()
if (mouse.button === Qt.RightButton) {
menu.message = root
menu.popup()
}
}
onPressAndHold: {
contextMenu.message = root
contextMenu.popup()
}
}
Controls.Menu {
id: contextMenu
Controls.MenuItem {
text: qsTr("Copy Message")
enabled: bodyLabel.visible
onTriggered: {
if (!isSpoiler || isShowingSpoiler)
Utils.copyToClipboard(messageBody);
else
Utils.copyToClipboard(spoilerHint);
}
}
Controls.MenuItem {
text: qsTr("Edit Message")
enabled: Kaidan.messageModel.canCorrectMessage(msgId)
onTriggered: root.messageEditRequested(msgId, messageBody)
}
Controls.MenuItem {
text: qsTr("Copy download URL")
enabled: mediaGetUrl
onTriggered: Utils.copyToClipboard(mediaGetUrl)
}
Controls.MenuItem {
text: qsTr("Quote")
onTriggered: {
root.quoteRequested(messageBody)
}
}
}
}
ColumnLayout {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment