diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-08-19 16:01:05 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-08-21 10:13:23 +0200 |
commit | 63a4ecea93e278eeaa5de23d774d4dee06d9c4fa (patch) | |
tree | 01e0b9031cb3dba9c5ec8af8ba95a87790d8b4c8 /examples/quickcontrols2/texteditor/qml | |
parent | 7c2ec7dc49799fffb2ed48a3a5afe2d8561ce3ee (diff) |
TextEditor: Add modified handling
Add a modified property to the document and add
handling in onClosing(). Connect the actions to
call close() instead of Qt.quit() for it to
become active.
Change-Id: I0fec75629db64e91508ed8ba45d4fb60be146b1b
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'examples/quickcontrols2/texteditor/qml')
-rw-r--r-- | examples/quickcontrols2/texteditor/qml/texteditor.qml | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/examples/quickcontrols2/texteditor/qml/texteditor.qml b/examples/quickcontrols2/texteditor/qml/texteditor.qml index a1cb3435..6c95335b 100644 --- a/examples/quickcontrols2/texteditor/qml/texteditor.qml +++ b/examples/quickcontrols2/texteditor/qml/texteditor.qml @@ -80,7 +80,7 @@ ApplicationWindow { } Shortcut { sequence: StandardKey.Quit - onActivated: Qt.quit() + onActivated: close() } Shortcut { sequence: StandardKey.Copy @@ -121,7 +121,7 @@ ApplicationWindow { } MenuItem { text: qsTr("&Quit") - onTriggered: Qt.quit() + onTriggered: close() } } @@ -205,6 +205,14 @@ ApplicationWindow { id: errorDialog } + MessageDialog { + id : quitDialog + title: qsTr("Quit?") + text: qsTr("The file has been modified. Quit anyway?") + buttons: (MessageDialog.Yes | MessageDialog.No) + onYesClicked: Qt.quit() + } + header: ToolBar { leftPadding: 8 @@ -449,4 +457,11 @@ ApplicationWindow { onTriggered: colorDialog.open() } } + + onClosing: { + if (document.modified) { + quitDialog.open() + close.accepted = false + } + } } |