浏览代码

added unsaved changes dialog

Malte Veerman 6 年之前
父节点
当前提交
52afa645f8
共有 1 个文件被更改,包括 36 次插入0 次删除
  1. 36 0
      fancontrol-gui/package/contents/ui/Application.qml

+ 36 - 0
fancontrol-gui/package/contents/ui/Application.qml

@@ -20,6 +20,7 @@
 
 import QtQuick 2.4
 import QtQuick.Controls 1.3
+import QtQuick.Dialogs 1.3
 import QtQuick.Layouts 1.1
 import Fancontrol.Qml 1.0 as Fancontrol
 
@@ -35,6 +36,10 @@ ApplicationWindow {
 
     onClosing: {
         windowConfig.save(window);
+        if (Fancontrol.Base.needsApply && !saveOnCloseDialog.answered) {
+            close.accepted = false;
+            saveOnCloseDialog.open();
+        }
     }
 
     Component.onCompleted: {
@@ -99,8 +104,39 @@ ApplicationWindow {
 
     Fancontrol.ErrorDialog {
         id: errorDialog
+
+        visible: false
+        modality: Qt.ApplicationModal
+    }
+
+    Dialog {
+        id: saveOnCloseDialog
+
+        property bool answered: false
+
         visible: false
         modality: Qt.ApplicationModal
+        title: i18n("Unsaved changes")
+        standardButtons: StandardButton.Cancel | StandardButton.Discard | StandardButton.Apply
+
+        onRejected: close()
+        onDiscard: {
+            answered = true;
+            close();
+            window.close();
+        }
+        onApply: {
+            Fancontrol.Base.apply();
+            answered = true;
+            close();
+            window.close();
+        }
+
+        Label {
+            id: text
+            anchors.centerIn: parent
+            text: i18n("There are unsaved changes.\nDo you want to apply these changes?")
+        }
     }
 
     Action {