From f5efa975c6eeb453739f2d8b50c68bd3999d2cfe Mon Sep 17 00:00:00 2001 From: Bent Witthold Date: Mon, 9 Mar 2026 15:48:56 +0100 Subject: [PATCH] When trying to close the application changes can be saved, discarded or the exit can be canceled via dialog. --- Main.qml | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) 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...") + } + } }