Confirmation popup to clear messages
This commit is contained in:
parent
f40e853078
commit
2611e86517
|
@ -2,10 +2,16 @@ import QtQuick 2.12
|
||||||
import QtQuick.Layouts 1.12
|
import QtQuick.Layouts 1.12
|
||||||
|
|
||||||
HPopup {
|
HPopup {
|
||||||
|
id: popup
|
||||||
onAboutToShow: okClicked = false
|
onAboutToShow: okClicked = false
|
||||||
|
|
||||||
|
|
||||||
|
signal ok()
|
||||||
|
signal cancel()
|
||||||
|
|
||||||
|
|
||||||
property alias label: label
|
property alias label: label
|
||||||
|
property alias text: label.text
|
||||||
property bool okClicked: false
|
property bool okClicked: false
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,8 +21,8 @@ HPopup {
|
||||||
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
|
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
|
||||||
]
|
]
|
||||||
box.buttonCallbacks: ({
|
box.buttonCallbacks: ({
|
||||||
ok: button => { okClicked = true; popup.close() },
|
ok: button => { okClicked = true; popup.ok(); popup.close() },
|
||||||
cancel: button => { okClicked = false; popup.close() },
|
cancel: button => { okClicked = false; popup.cancel(); popup.close() },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
16
src/qml/Chat/ClearMessagesPopup.qml
Normal file
16
src/qml/Chat/ClearMessagesPopup.qml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import QtQuick 2.12
|
||||||
|
import "../Base"
|
||||||
|
|
||||||
|
HOkCancelPopup {
|
||||||
|
text: qsTr(
|
||||||
|
"Clear this room's messages?\n" +
|
||||||
|
"The messages will only be removed on your side. " +
|
||||||
|
"They will be available again after you restart the application."
|
||||||
|
)
|
||||||
|
|
||||||
|
onOk: py.callClientCoro(userId, "clear_events", [roomId])
|
||||||
|
|
||||||
|
|
||||||
|
property string userId: ""
|
||||||
|
property string roomId: ""
|
||||||
|
}
|
|
@ -127,8 +127,10 @@ Column {
|
||||||
HMenuItem {
|
HMenuItem {
|
||||||
icon.name: "clear-messages"
|
icon.name: "clear-messages"
|
||||||
text: qsTr("Clear messages")
|
text: qsTr("Clear messages")
|
||||||
onTriggered: py.callClientCoro(
|
onTriggered: Utils.makePopup(
|
||||||
chatPage.userId, "clear_events", [chatPage.roomId],
|
"Chat/ClearMessagesPopup.qml",
|
||||||
|
chatPage,
|
||||||
|
{userId: chatPage.userId, roomId: chatPage.roomId},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,10 +116,13 @@ HShortcutHandler {
|
||||||
HShortcut {
|
HShortcut {
|
||||||
enabled: window.uiState.page == "Chat/Chat.qml"
|
enabled: window.uiState.page == "Chat/Chat.qml"
|
||||||
sequences: settings.keys.clearRoomMessages
|
sequences: settings.keys.clearRoomMessages
|
||||||
onPressed: py.callClientCoro(
|
onPressed: Utils.makePopup(
|
||||||
window.uiState.pageProperties.userId,
|
"Chat/ClearMessagesPopup.qml",
|
||||||
"clear_events",
|
mainUI,
|
||||||
[window.uiState.pageProperties.roomId],
|
{
|
||||||
|
userId: window.uiState.pageProperties.userId,
|
||||||
|
roomId: window.uiState.pageProperties.roomId,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,45 @@
|
||||||
|
function makeObject(url, parent=null, properties={}, callback=null) {
|
||||||
|
let comp = Qt.createComponent(url, Component.Asynchronous)
|
||||||
|
let ready = false
|
||||||
|
|
||||||
|
comp.statusChanged.connect(status => {
|
||||||
|
if ([Component.Null, Component.Error].includes(status)) {
|
||||||
|
console.error("Failed creating component: ", comp.errorString())
|
||||||
|
|
||||||
|
} else if (status == Component.Ready) {
|
||||||
|
let incu = comp.incubateObject(parent, properties, Qt.Asynchronous)
|
||||||
|
|
||||||
|
if (incu.status == Component.Ready) {
|
||||||
|
if (callback) callback(incu.object)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
incu.onStatusChanged = (istatus) => {
|
||||||
|
if (incu.status == Component.Error) {
|
||||||
|
console.error("Failed incubating object: ",
|
||||||
|
incu.errorString())
|
||||||
|
|
||||||
|
} else if (istatus == Component.Ready && callback && ! ready) {
|
||||||
|
if (callback) callback(incu.object)
|
||||||
|
ready = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (comp.status == Component.Ready) comp.statusChanged(comp.status)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function makePopup(url, parent=null, properties={}, callback=null) {
|
||||||
|
makeObject(url, parent, properties, (popup) => {
|
||||||
|
popup.open()
|
||||||
|
popup.closed.connect(() => { popup.destroy() })
|
||||||
|
if (callback) callback(popup)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function isEmptyObject(obj) {
|
function isEmptyObject(obj) {
|
||||||
return Object.entries(obj).length === 0 && obj.constructor === Object
|
return Object.entries(obj).length === 0 && obj.constructor === Object
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user