Merge pull request #450 from monich/smarter-extra-options
Hide "Extra options..." context menu item if it's not needed
This commit is contained in:
commit
8573b3f6d9
2 changed files with 70 additions and 19 deletions
|
@ -42,14 +42,45 @@ ListItem {
|
||||||
return existingMessage.id === messageId
|
return existingMessage.id === messageId
|
||||||
});
|
});
|
||||||
readonly property bool isOwnMessage: page.myUserId === myMessage.sender.user_id
|
readonly property bool isOwnMessage: page.myUserId === myMessage.sender.user_id
|
||||||
|
readonly property bool canDeleteMessage: myMessage.can_be_deleted_for_all_users || (myMessage.can_be_deleted_only_for_self && myMessage.chat_id === page.myUserId)
|
||||||
property bool hasContentComponent
|
property bool hasContentComponent
|
||||||
property bool additionalOptionsOpened
|
property bool additionalOptionsOpened
|
||||||
|
|
||||||
|
readonly property var additionalItemsModel: (extraContentLoader.item && ("extraContextMenuItems" in extraContentLoader.item)) ?
|
||||||
|
extraContentLoader.item.extraContextMenuItems : 0
|
||||||
|
readonly property int numberOfExtraOptionsOtherThanDeleteMessage:
|
||||||
|
(showCopyMessageToClipboardMenuItem ? 0 : 1) +
|
||||||
|
(showForwardMessageMenuItem ? 0 : 1) +
|
||||||
|
(page.canPinMessages() ? 1 : 0) +
|
||||||
|
(additionalItemsModel ? additionalItemsModel.length : 0)
|
||||||
|
readonly property bool deleteMessageIsOnlyExtraOption: canDeleteMessage && !numberOfExtraOptionsOtherThanDeleteMessage
|
||||||
|
|
||||||
|
readonly property int maxContextMenuItemCount: page.isPortrait ? 5 : 4
|
||||||
|
readonly property int baseContextMenuItemCount: (canReplyToMessage ? 1 : 0) +
|
||||||
|
(myMessage.can_be_edited ? 1 : 0) + 2 /* "Select Message" and "More Options..." */
|
||||||
|
readonly property bool showCopyMessageToClipboardMenuItem: (baseContextMenuItemCount + 1) <= maxContextMenuItemCount
|
||||||
|
readonly property bool showForwardMessageMenuItem: (baseContextMenuItemCount + 2) <= maxContextMenuItemCount
|
||||||
|
// And don't count "More Options..." for "Delete Message" if "Delete Message" is the only extra option
|
||||||
|
readonly property bool haveSpaceForDeleteMessageMenuItem: (baseContextMenuItemCount + 3 - (deleteMessageIsOnlyExtraOption ? 1 : 0)) <= maxContextMenuItemCount
|
||||||
|
|
||||||
highlighted: (down || isSelected || additionalOptionsOpened) && !menuOpen
|
highlighted: (down || isSelected || additionalOptionsOpened) && !menuOpen
|
||||||
openMenuOnPressAndHold: !messageListItem.precalculatedValues.pageIsSelecting
|
openMenuOnPressAndHold: !messageListItem.precalculatedValues.pageIsSelecting
|
||||||
|
|
||||||
signal replyToMessage()
|
signal replyToMessage()
|
||||||
signal editMessage()
|
signal editMessage()
|
||||||
|
signal forwardMessage()
|
||||||
|
|
||||||
|
function deleteMessage() {
|
||||||
|
var chatId = page.chatInformation.id
|
||||||
|
var messageId = myMessage.id
|
||||||
|
Remorse.itemAction(messageListItem, qsTr("Message deleted"), function() {
|
||||||
|
tdLibWrapper.deleteMessages(chatId, [ messageId ]);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyMessageToClipboard() {
|
||||||
|
Clipboard.text = Functions.getMessageText(myMessage, true, userInformation.id, true)
|
||||||
|
}
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if(messageListItem.precalculatedValues.pageIsSelecting) {
|
if(messageListItem.precalculatedValues.pageIsSelecting) {
|
||||||
|
@ -105,27 +136,45 @@ ListItem {
|
||||||
sourceComponent: Component {
|
sourceComponent: Component {
|
||||||
ContextMenu {
|
ContextMenu {
|
||||||
MenuItem {
|
MenuItem {
|
||||||
visible: messageListItem.canReplyToMessage
|
visible: canReplyToMessage
|
||||||
onClicked: messageListItem.replyToMessage()
|
onClicked: replyToMessage()
|
||||||
text: qsTr("Reply to Message")
|
text: qsTr("Reply to Message")
|
||||||
}
|
}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
visible: typeof myMessage.can_be_edited !== "undefined" && myMessage.can_be_edited
|
visible: typeof myMessage.can_be_edited !== "undefined" && myMessage.can_be_edited
|
||||||
onClicked: messageListItem.editMessage()
|
onClicked: editMessage()
|
||||||
text: qsTr("Edit Message")
|
text: qsTr("Edit Message")
|
||||||
}
|
}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
onClicked: {
|
onClicked: page.toggleMessageSelection(myMessage)
|
||||||
page.toggleMessageSelection(myMessage);
|
|
||||||
}
|
|
||||||
text: qsTr("Select Message")
|
text: qsTr("Select Message")
|
||||||
}
|
}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
|
visible: showCopyMessageToClipboardMenuItem
|
||||||
|
onClicked: copyMessageToClipboard()
|
||||||
|
text: qsTr("Copy Message to Clipboard")
|
||||||
|
}
|
||||||
|
MenuItem {
|
||||||
|
visible: showForwardMessageMenuItem
|
||||||
|
onClicked: forwardMessage()
|
||||||
|
text: qsTr("Forward Message")
|
||||||
|
}
|
||||||
|
MenuItem {
|
||||||
|
visible: canDeleteMessage && haveSpaceForDeleteMessageMenuItem
|
||||||
|
onClicked: deleteMessage()
|
||||||
|
text: qsTr("Delete Message")
|
||||||
|
}
|
||||||
|
MenuItem {
|
||||||
|
visible: (numberOfExtraOptionsOtherThanDeleteMessage > 0) ||
|
||||||
|
(deleteMessageIsOnlyExtraOption && !haveSpaceForDeleteMessageMenuItem)
|
||||||
onClicked: {
|
onClicked: {
|
||||||
messageOptionsDrawer.myMessage = myMessage;
|
messageOptionsDrawer.myMessage = myMessage;
|
||||||
messageOptionsDrawer.userInformation = userInformation;
|
messageOptionsDrawer.userInformation = userInformation;
|
||||||
messageOptionsDrawer.sourceItem = messageListItem
|
messageOptionsDrawer.sourceItem = messageListItem
|
||||||
messageOptionsDrawer.additionalItemsModel = (extraContentLoader.item && ("extraContextMenuItems" in extraContentLoader.item)) ? extraContentLoader.item.extraContextMenuItems : 0;
|
messageOptionsDrawer.additionalItemsModel = additionalItemsModel
|
||||||
|
messageOptionsDrawer.showCopyMessageToClipboardMenuItem = !showCopyMessageToClipboardMenuItem
|
||||||
|
messageOptionsDrawer.showForwardMessageMenuItem = !showForwardMessageMenuItem
|
||||||
|
messageOptionsDrawer.showDeleteMessageMenuItem = canDeleteMessage && !haveSpaceForDeleteMessageMenuItem
|
||||||
messageListItem.additionalOptionsOpened = true;
|
messageListItem.additionalOptionsOpened = true;
|
||||||
messageOptionsDrawer.open = true;
|
messageOptionsDrawer.open = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -713,19 +713,21 @@ Page {
|
||||||
property var userInformation: ({})
|
property var userInformation: ({})
|
||||||
property var additionalItemsModel: 0
|
property var additionalItemsModel: 0
|
||||||
property var sourceItem
|
property var sourceItem
|
||||||
|
property bool showCopyMessageToClipboardMenuItem
|
||||||
|
property bool showForwardMessageMenuItem
|
||||||
|
property bool showDeleteMessageMenuItem
|
||||||
|
|
||||||
property list<NamedAction> messageOptionsModel: [
|
property list<NamedAction> messageOptionsModel: [
|
||||||
NamedAction {
|
NamedAction {
|
||||||
visible: true
|
visible: messageOptionsDrawer.showCopyMessageToClipboardMenuItem
|
||||||
name: qsTr("Copy Message to Clipboard")
|
name: qsTr("Copy Message to Clipboard")
|
||||||
action: function () { Clipboard.text = Functions.getMessageText(messageOptionsDrawer.myMessage, true, messageOptionsDrawer.userInformation.id, true); }
|
action: messageOptionsDrawer.myMessage.copyMessageToClipboard
|
||||||
},
|
},
|
||||||
NamedAction {
|
NamedAction {
|
||||||
visible: messageOptionsDrawer.myMessage.can_be_forwarded
|
visible: messageOptionsDrawer.showForwardMessageMenuItem && messageOptionsDrawer.myMessage.can_be_forwarded
|
||||||
name: qsTr("Forward Message")
|
name: qsTr("Forward Message")
|
||||||
action: function () {
|
action: function () {
|
||||||
var messagesToForward = [ messageOptionsDrawer.myMessage ];
|
startForwardingMessages([messageOptionsDrawer.myMessage])
|
||||||
startForwardingMessages(messagesToForward);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NamedAction {
|
NamedAction {
|
||||||
|
@ -741,13 +743,9 @@ Page {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NamedAction {
|
NamedAction {
|
||||||
visible: messageOptionsDrawer.myMessage.can_be_deleted_for_all_users || (messageOptionsDrawer.myMessage.can_be_deleted_only_for_self && messageOptionsDrawer.myMessage.chat_id === chatPage.myUserId)
|
visible: messageOptionsDrawer.showDeleteMessageMenuItem
|
||||||
name: qsTr("Delete Message")
|
name: qsTr("Delete Message")
|
||||||
action: function () {
|
action: messageOptionsDrawer.sourceItem.deleteMessage
|
||||||
var chatId = chatPage.chatInformation.id;
|
|
||||||
var messageId = messageOptionsDrawer.myMessage.id;
|
|
||||||
Remorse.itemAction(messageOptionsDrawer.sourceItem, qsTr("Message deleted"), function() { tdLibWrapper.deleteMessages(chatId, [ messageId ]); });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -758,7 +756,8 @@ Page {
|
||||||
jointModel.push(additionalItemsModel[j]);
|
jointModel.push(additionalItemsModel[j]);
|
||||||
}
|
}
|
||||||
for (var i = 0; i < messageOptionsModel.length; i++) {
|
for (var i = 0; i < messageOptionsModel.length; i++) {
|
||||||
jointModel.push(messageOptionsModel[i]);
|
var item = messageOptionsModel[i]
|
||||||
|
if (item.visible) jointModel.push(item)
|
||||||
}
|
}
|
||||||
drawerListView.model = jointModel;
|
drawerListView.model = jointModel;
|
||||||
focus = true // Take the focus away from the text field
|
focus = true // Take the focus away from the text field
|
||||||
|
@ -1323,6 +1322,9 @@ Page {
|
||||||
newMessageTextField.text = Functions.getMessageText(myMessage, false, chatPage.myUserId, true)
|
newMessageTextField.text = Functions.getMessageText(myMessage, false, chatPage.myUserId, true)
|
||||||
newMessageTextField.focus = true
|
newMessageTextField.focus = true
|
||||||
}
|
}
|
||||||
|
onForwardMessage: {
|
||||||
|
startForwardingMessages([myMessage])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Component {
|
Component {
|
||||||
|
|
Loading…
Reference in a new issue