Confirmation popup to clear messages

This commit is contained in:
miruka
2019-09-09 06:23:46 -04:00
parent f40e853078
commit 2611e86517
5 changed files with 77 additions and 8 deletions

View File

@@ -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) {
return Object.entries(obj).length === 0 && obj.constructor === Object
}