When trying to close the application changes can be saved, discarded or the exit can be canceled via dialog.
This commit is contained in:
40
Main.qml
40
Main.qml
@ -4,6 +4,7 @@ import QtQuick.Layouts
|
|||||||
import QtQml.Models
|
import QtQml.Models
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
|
property bool discardChangesOnExit: false
|
||||||
property bool isDataModified: !appUndoStack.isClean
|
property bool isDataModified: !appUndoStack.isClean
|
||||||
|
|
||||||
property string titleClean: `${Application.name}`
|
property string titleClean: `${Application.name}`
|
||||||
@ -16,7 +17,6 @@ Window {
|
|||||||
title: appUndoStack.clean ? titleClean : titleDirty
|
title: appUndoStack.clean ? titleClean : titleDirty
|
||||||
|
|
||||||
property int fontSize: 16
|
property int fontSize: 16
|
||||||
|
|
||||||
property color textColor: "black"
|
property color textColor: "black"
|
||||||
|
|
||||||
property color wccDarkDark: "#010101"
|
property color wccDarkDark: "#010101"
|
||||||
@ -49,4 +49,42 @@ Window {
|
|||||||
// footerText.text = ""
|
// footerText.text = ""
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onClosing: event => {
|
||||||
|
if (appUndoStack.clean) {
|
||||||
|
console.debug("Closing on a clean undo stack.")
|
||||||
|
} else {
|
||||||
|
console.debug("Closing on an unclean undo stack!")
|
||||||
|
if (!window.discardChangesOnExit) {
|
||||||
|
event.accepted = false
|
||||||
|
exitOnUnsavedChangesDialog.open()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Dialog {
|
||||||
|
id: exitOnUnsavedChangesDialog
|
||||||
|
title: "Unsaved Changes"
|
||||||
|
modal: false
|
||||||
|
anchors.centerIn: parent
|
||||||
|
width: 300
|
||||||
|
standardButtons: Dialog.Yes | Dialog.Cancel | Dialog.Discard
|
||||||
|
|
||||||
|
contentItem: Label {
|
||||||
|
text: "Do you want save your changes?"
|
||||||
|
}
|
||||||
|
|
||||||
|
onAccepted: {
|
||||||
|
core.saveItems()
|
||||||
|
window.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
onDiscarded: {
|
||||||
|
window.discardChangesOnExit = true
|
||||||
|
window.close()
|
||||||
|
}
|
||||||
|
onRejected: {
|
||||||
|
console.debug("Canceling exit...")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user