diff --git a/Main.qml b/Main.qml index 6719055..8cd35d7 100644 --- a/Main.qml +++ b/Main.qml @@ -4,6 +4,7 @@ import QtQuick.Layouts import QtQml.Models Window { + property bool discardChangesOnExit: false property bool isDataModified: !appUndoStack.isClean property string titleClean: `${Application.name}` @@ -16,7 +17,6 @@ Window { title: appUndoStack.clean ? titleClean : titleDirty property int fontSize: 16 - property color textColor: "black" property color wccDarkDark: "#010101" @@ -49,4 +49,42 @@ Window { // 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...") + } + } }