Fix stuck menu options on community/room list

This commit is contained in:
SyldraTheCat 2022-06-09 10:49:46 +00:00
parent 3af5331c62
commit 5c11f6d7d8
No known key found for this signature in database
GPG key ID: 280A2D3028A3E9C7
2 changed files with 84 additions and 98 deletions

View file

@ -32,23 +32,6 @@ Page {
enabled: !Settings.mobileMode enabled: !Settings.mobileMode
} }
Platform.Menu {
id: communityContextMenu
property string tagId
function show(id_, tags_) {
tagId = id_;
open();
}
Platform.MenuItem {
text: qsTr("Hide rooms with this tag or from this space by default.")
onTriggered: Communities.toggleTagId(communityContextMenu.tagId)
}
}
delegate: ItemDelegate { delegate: ItemDelegate {
id: communityItem id: communityItem
@ -65,7 +48,7 @@ Page {
ToolTip.text: model.tooltip ToolTip.text: model.tooltip
ToolTip.delay: Nheko.tooltipDelay ToolTip.delay: Nheko.tooltipDelay
onClicked: Communities.setCurrentTagId(model.id) onClicked: Communities.setCurrentTagId(model.id)
onPressAndHold: communityContextMenu.show(model.id) onPressAndHold: communityContextMenu.open()
states: [ states: [
State { State {
name: "highlight" name: "highlight"
@ -97,12 +80,24 @@ Page {
} }
] ]
Platform.Menu {
id: communityContextMenu
Platform.MenuItem {
text: qsTr("Hide rooms with this tag or from this space by default.")
checkable: true
checked: model.hidden
onTriggered: Communities.toggleTagId(model.id);
}
}
Item { Item {
anchors.fill: parent anchors.fill: parent
TapHandler { TapHandler {
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
onSingleTapped: communityContextMenu.show(model.id) onSingleTapped: communityContextMenu.open()
gesturePolicy: TapHandler.ReleaseWithinBounds gesturePolicy: TapHandler.ReleaseWithinBounds
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad
} }

View file

@ -109,83 +109,6 @@ Page {
} }
Platform.Menu {
id: roomContextMenu
property string roomid
property var tags
function show(roomid_, tags_) {
roomid = roomid_;
tags = tags_;
open();
}
InputDialog {
id: newTag
title: qsTr("New tag")
prompt: qsTr("Enter the tag you want to use:")
onAccepted: function(text) {
Rooms.toggleTag(roomContextMenu.roomid, "u." + text, true);
}
}
Platform.MenuItem {
text: qsTr("Open separately")
onTriggered: {
var roomWindow = roomWindowComponent.createObject(null, {
"room": Rooms.getRoomById(roomContextMenu.roomid),
"roomPreview": Rooms.getRoomPreviewById(roomContextMenu.roomid)
});
roomWindow.showNormal();
destroyOnClose(roomWindow);
}
}
Platform.MenuItem {
text: qsTr("Leave room")
onTriggered: TimelineManager.openLeaveRoomDialog(roomContextMenu.roomid)
}
Platform.MenuSeparator {
text: qsTr("Tag room as:")
}
Instantiator {
model: Communities.tagsWithDefault
onObjectAdded: roomContextMenu.insertItem(index + 3, object)
onObjectRemoved: roomContextMenu.removeItem(object)
delegate: Platform.MenuItem {
property string t: modelData
text: {
switch (t) {
case "m.favourite":
return qsTr("Favourite");
case "m.lowpriority":
return qsTr("Low priority");
case "m.server_notice":
return qsTr("Server notice");
default:
return t.substring(2);
}
}
checkable: true
checked: roomContextMenu.tags !== undefined && roomContextMenu.tags.includes(t)
onTriggered: Rooms.toggleTag(roomContextMenu.roomid, t, checked)
}
}
Platform.MenuItem {
text: qsTr("Create new tag...")
onTriggered: newTag.show()
}
}
delegate: ItemDelegate { delegate: ItemDelegate {
id: roomItem id: roomItem
@ -231,7 +154,7 @@ Page {
} }
onPressAndHold: { onPressAndHold: {
if (!isInvite) if (!isInvite)
roomContextMenu.show(roomId, tags); roomContextMenu.open();
} }
states: [ states: [
@ -265,6 +188,74 @@ Page {
} }
] ]
Platform.Menu {
id: roomContextMenu
InputDialog {
id: newTag
title: qsTr("New tag")
prompt: qsTr("Enter the tag you want to use:")
onAccepted: function(text) {
Rooms.toggleTag(roomId, "u." + text, true);
}
}
Platform.MenuItem {
text: qsTr("Open separately")
onTriggered: {
var roomWindow = roomWindowComponent.createObject(null, {
"room": Rooms.getRoomById(roomId),
"roomPreview": Rooms.getRoomPreviewById(roomId)
});
roomWindow.showNormal();
destroyOnClose(roomWindow);
}
}
Platform.MenuItem {
text: qsTr("Leave room")
onTriggered: TimelineManager.openLeaveRoomDialog(roomId)
}
Platform.MenuSeparator {
text: qsTr("Tag room as:")
}
Instantiator {
model: Communities.tagsWithDefault
onObjectAdded: roomContextMenu.insertItem(index + 3, object)
onObjectRemoved: roomContextMenu.removeItem(object)
delegate: Platform.MenuItem {
property string t: modelData
text: {
switch (t) {
case "m.favourite":
return qsTr("Favourite");
case "m.lowpriority":
return qsTr("Low priority");
case "m.server_notice":
return qsTr("Server notice");
default:
return t.substring(2);
}
}
checkable: true
checked: tags !== undefined && tags.includes(t)
onTriggered: Rooms.toggleTag(roomId, t, checked)
}
}
Platform.MenuItem {
text: qsTr("Create new tag...")
onTriggered: newTag.show()
}
}
// NOTE(Nico): We want to prevent the touch areas from overlapping. For some reason we need to add 1px of padding for that... // NOTE(Nico): We want to prevent the touch areas from overlapping. For some reason we need to add 1px of padding for that...
Item { Item {
anchors.fill: parent anchors.fill: parent
@ -274,7 +265,7 @@ Page {
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
onSingleTapped: { onSingleTapped: {
if (!TimelineManager.isInvite) if (!TimelineManager.isInvite)
roomContextMenu.show(roomId, tags); roomContextMenu.open();
} }
gesturePolicy: TapHandler.ReleaseWithinBounds gesturePolicy: TapHandler.ReleaseWithinBounds