fix:confirmation for editor closing

This commit is contained in:
thelastWallE 2021-10-02 22:08:29 +02:00
parent 12e08bb20d
commit a6539f203c
1 changed files with 5 additions and 9 deletions

View File

@ -16,16 +16,14 @@
$(function () { $(function () {
function KlipperEditorViewModel(parameters) { function KlipperEditorViewModel(parameters) {
var self = this; var self = this;
var obKlipperConfig = null;
var editor = null; var editor = null;
var editor_dirty = false;
self.settings = parameters[0]; self.settings = parameters[0];
self.klipperViewModel = parameters[1]; self.klipperViewModel = parameters[1];
self.CfgFilename = ko.observable(""); self.CfgFilename = ko.observable("");
self.CfgContent = ko.observable(""); self.CfgContent = ko.observable("");
self.config = [] self.loadedConfig = "";
self.header = OctoPrint.getRequestHeaders({ self.header = OctoPrint.getRequestHeaders({
"content-type": "application/json", "content-type": "application/json",
@ -36,7 +34,7 @@ $(function () {
editor.focus(); editor.focus();
self.setEditorDivSize(); self.setEditorDivSize();
$(window).on('resize', function(){ $(window).on('resize', function(){
self.klipperViewModel.sleep(500).then( self.klipperViewModel.sleep(200).then(
function () { function () {
self.setEditorDivSize(); self.setEditorDivSize();
} }
@ -45,7 +43,8 @@ $(function () {
}); });
self.closeEditor = function () { self.closeEditor = function () {
if (editor_dirty===true) { self.CfgContent(editor.getValue());
if (self.loadedConfig != self.CfgContent()) {
showConfirmationDialog({ showConfirmationDialog({
message: gettext( message: gettext(
"Your file seems to have changed." "Your file seems to have changed."
@ -84,13 +83,12 @@ $(function () {
self.process = function (config) { self.process = function (config) {
return new Promise(function (resolve) { return new Promise(function (resolve) {
self.config = config; self.loadedConfig = config.content;
self.CfgFilename(config.file); self.CfgFilename(config.file);
self.CfgContent(config.content); self.CfgContent(config.content);
if (editor) { if (editor) {
editor.session.setValue(self.CfgContent()); editor.session.setValue(self.CfgContent());
editor_dirty=false;
editor.setFontSize(self.settings.settings.plugins.klipper.configuration.fontsize()); editor.setFontSize(self.settings.settings.plugins.klipper.configuration.fontsize());
self.settings.settings.plugins.klipper.configuration.old_config(config.content); self.settings.settings.plugins.klipper.configuration.old_config(config.content);
editor.clearSelection(); editor.clearSelection();
@ -137,7 +135,6 @@ $(function () {
var msg = "" var msg = ""
if (response.saved === true) { if (response.saved === true) {
self.klipperViewModel.showPopUp("success", gettext("Save Config"), gettext("File saved.")); self.klipperViewModel.showPopUp("success", gettext("Save Config"), gettext("File saved."));
editor_dirty = false;
if (self.settings.settings.plugins.klipper.configuration.restart_onsave()==true) { if (self.settings.settings.plugins.klipper.configuration.restart_onsave()==true) {
self.klipperViewModel.requestRestart(); self.klipperViewModel.requestRestart();
} }
@ -235,7 +232,6 @@ $(function () {
editor.session.on('change', function (delta) { editor.session.on('change', function (delta) {
self.CfgContent(editor.getValue()); self.CfgContent(editor.getValue());
editor_dirty = true;
editor.resize(); editor.resize();
}); });
}; };