fix(editor):ask reload of file after SAVE_CONFIG

This commit is contained in:
thelastWallE 2021-10-07 19:06:16 +02:00
parent c635bc23f2
commit c8a2486b7c
3 changed files with 56 additions and 13 deletions

View File

@ -378,6 +378,10 @@ class KlipperPlugin(
return None
# -- GCODE Hook
def process_sent_GCODE(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
if cmd == "SAVE_CONFIG":
logger.log_info(self, "SAVE_CONFIG detected")
util.send_message(self, type = "reload", subtype = "config")
def on_parse_gcode(self, comm, line, *args, **kwargs):
@ -642,6 +646,7 @@ def __plugin_load__():
"octoprint.server.http.routes": __plugin_implementation__.route_hook,
"octoprint.access.permissions": __plugin_implementation__.get_additional_permissions,
"octoprint.comm.protocol.atcommand.sending": __plugin_implementation__.processAtCommand,
"octoprint.comm.protocol.gcode.sent": __plugin_implementation__.process_sent_GCODE,
"octoprint.comm.protocol.gcode.received": __plugin_implementation__.on_parse_gcode,
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}

View File

@ -25,6 +25,7 @@ $(function () {
self.CfgFilename = ko.observable("");
self.CfgContent = ko.observable("");
self.loadedConfig = "";
self.CfgChangedExtern = false;
self.header = OctoPrint.getRequestHeaders({
"content-type": "application/json",
@ -39,6 +40,12 @@ $(function () {
);
});
self.onShown = function () {
self.checkExternChange();
editor.focus();
self.setEditorDivSize();
}
self.close_selection = function (index) {
switch (index) {
case 0:
@ -101,6 +108,7 @@ $(function () {
if (editor) {
editor.session.setValue(self.CfgContent());
self.CfgChangedExtern = false;
editor.setFontSize(self.settings.settings.plugins.klipper.configuration.fontsize());
self.settings.settings.plugins.klipper.configuration.old_config(config.content);
editor.clearSelection();
@ -114,6 +122,43 @@ $(function () {
});
}
self.onDataUpdaterPluginMessage = function (plugin, data) {
if (plugin == "klipper" && data.type == "reload" && data.subtype == "config") {
self.klipperViewModel.consoleMessage("debug", "onDataUpdaterPluginMessage klipper reload baseconfig");
self.ConfigChangedAfterSave();
}
};
self.ConfigChangedAfterSave = function () {
if (!self.klipperViewModel.hasRight("CONFIG")) return;
if (self.CfgFilename() == self.settings.settings.plugins.klipper.configuration.baseconfig()) {
self.CfgChangedExtern = true;
self.checkExternChange();
}
};
self.checkExternChange = function() {
var baseconfig = self.settings.settings.plugins.klipper.configuration.baseconfig();
if (self.CfgChangedExtern && self.CfgFilename() == baseconfig) {
if (editordialog.is(":visible")) {
var perform = function () {
self.reloadFromFile();
}
var html = "<p>" + gettext("Reload Configfile after SAVE_CONFIG?") + "</p>";
showConfirmationDialog({
title: gettext("Externally changed config") + " " + baseconfig,
html: html,
proceed: gettext("Proceed"),
onproceed: perform,
});
}
}
}
self.checkSyntax = function () {
if (editor.session) {
self.klipperViewModel.consoleMessage("debug", "checkSyntax started");
@ -214,8 +259,10 @@ $(function () {
)
} else {
self.klipperViewModel.showPopUp("success", gettext("Reload Config"), gettext("File reloaded."));
self.CfgChangedExtern = false;
if (editor) {
editor.session.setValue(response.response.config);
self.loadedConfig = response.response.config;
editor.clearSelection();
editor.focus();
}

View File

@ -31,6 +31,10 @@ $(function () {
self.markedForFileRemove = ko.observableArray([]);
$(document).on('shown.bs.modal','#klipper_editor', function () {
self.klipperEditorViewModel.onShown();
});
self.checkFontsize = function () {
if (self.settings.settings.plugins.klipper.configuration.fontsize() > 20) {
self.settings.settings.plugins.klipper.configuration.fontsize(20)
@ -312,21 +316,8 @@ $(function () {
if (plugin == "klipper" && data.type == "reload" && data.subtype == "configlist") {
self.klipperViewModel.consoleMessage("debug", "onDataUpdaterPluginMessage klipper reload configlist");
self.listCfgFiles();
} else if (plugin == "klipper" && data.type == "start" && data.subtype == "config") {
self.klipperViewModel.consoleMessage("debug", "onDataUpdaterPluginMessage klipper start config");
self.startConfig(data.title, data.payload);
}
};
self.startConfig = function (file, content) {
if (!self.klipperViewModel.hasRight("CONFIG")) return;
filename = file || "";
var config = {
content: content,
file: filename,
};
self.klipperEditorViewModel.process(config).then();
};
}
OCTOPRINT_VIEWMODELS.push({