From 18a7f6e8a757683ace666f47032b196cf785f2b9 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Wed, 27 Mar 2024 22:51:59 +0100 Subject: [PATCH] feat: add only save button to editor (#1835) --- src/components/TheEditor.vue | 28 ++++++++++++---------------- src/store/editor/actions.ts | 5 ++++- src/store/editor/mutations.ts | 5 +++++ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/components/TheEditor.vue b/src/components/TheEditor.vue index df97f93ce..bc401cd33 100644 --- a/src/components/TheEditor.vue +++ b/src/components/TheEditor.vue @@ -27,15 +27,6 @@ {{ mdiHelp }} {{ $t('Editor.ConfigReference') }} - - {{ mdiContentSave }} - {{ $t('Editor.SaveClose') }} - {{ mdiRestart }} {{ $t('Editor.SaveRestart') }} + + {{ mdiContentSave }} + {{ mdiCloseThick }} @@ -56,7 +50,7 @@ ref="editor" v-model="sourcecode" :name="filename" - :file-extension="fileExtension"> + :file-extension="fileExtension" /> @@ -105,7 +99,7 @@ - + {{ $t('Editor.DontSave') }} @@ -167,8 +161,6 @@ export default class TheEditor extends Mixins(BaseMixin) { mdiFileDocumentOutline = mdiFileDocumentOutline mdiUsb = mdiUsb - private scrollbarOptions = { scrollbars: { autoHide: 'never' } } - declare $refs: { editor: Codemirror } @@ -343,10 +335,14 @@ export default class TheEditor extends Mixins(BaseMixin) { @Watch('changed') changedChanged(newVal: boolean) { - if (this.confirmUnsavedChanges) { - if (newVal) window.addEventListener('beforeunload', windowBeforeUnloadFunction) - else window.removeEventListener('beforeunload', windowBeforeUnloadFunction) + if (!this.confirmUnsavedChanges) return + + if (newVal) { + window.addEventListener('beforeunload', windowBeforeUnloadFunction) + return } + + window.removeEventListener('beforeunload', windowBeforeUnloadFunction) } } diff --git a/src/store/editor/actions.ts b/src/store/editor/actions.ts index c5112a90f..c7d50b2b8 100644 --- a/src/store/editor/actions.ts +++ b/src/store/editor/actions.ts @@ -133,7 +133,10 @@ export const actions: ActionTree = { } else if (payload.restartServiceName !== null) { Vue.$socket.emit('machine.services.restart', { service: payload.restartServiceName }) } - dispatch('close') + + commit('updateLoadedHash', payload.content) + + if (payload.restartServiceName !== null) dispatch('close') }) .catch((error) => { window.console.log(error.response?.data.error) diff --git a/src/store/editor/mutations.ts b/src/store/editor/mutations.ts index 5fb331451..771b077c5 100644 --- a/src/store/editor/mutations.ts +++ b/src/store/editor/mutations.ts @@ -68,4 +68,9 @@ export const mutations: MutationTree = { state.changed = sha256(payload) != state.loadedHash }, + + updateLoadedHash(state, payload) { + Vue.set(state, 'loadedHash', sha256(payload.replace(/(?:\r\n|\r|\n)/g, '\n'))) + Vue.set(state, 'changed', false) + }, }