Skip to content

Commit

Permalink
fix: fix editor save & restart button behavior (mainsail-crew#1483)
Browse files Browse the repository at this point in the history
  • Loading branch information
meteyou authored Jul 24, 2023
1 parent 0c5aca8 commit 8447be2
Show file tree
Hide file tree
Showing 24 changed files with 22 additions and 94 deletions.
20 changes: 14 additions & 6 deletions src/components/TheEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -239,25 +239,33 @@ export default class TheEditor extends Mixins(BaseMixin) {
if (!this.isWriteable) return null
if (['printing', 'paused'].includes(this.printer_state)) return null
// check for generic services <service>.conf (like moonraker.conf, crowsnest.conf, sonar.conf)
if (this.availableServices.includes(this.filenameWithoutExtension) && this.fileExtension === 'conf')
return this.filenameWithoutExtension
// old webcam service DEPRECATED
if (this.filename.startsWith('webcam') && ['conf', 'txt'].includes(this.fileExtension)) return 'webcamd'
// check for mooncord config files
if (this.filename.startsWith('mooncord') && this.fileExtension === 'json') return 'mooncord'
if (this.filename === 'moonraker.conf') return this.moonrakerRestartInstance ?? 'moonraker'
// fallback for moonraker with multi instances
if (this.filename === 'moonraker.conf') return 'moonraker'
// all .cfg files will be klipper config files
if (this.fileExtension === 'cfg') return 'klipper'
return null
}
get restartServiceNameExists() {
if (!this.restartServiceName) return true
// hide the button, if there is no service found
if (this.restartServiceName === null) return false
return this.availableServices.includes(this.restartServiceName)
}
// klipper and moonraker uses specific api calls instead of generic service restart
if (['klipper', 'moonraker'].includes(this.restartServiceName)) return true
get moonrakerRestartInstance() {
return this.$store.state.gui.editor.moonrakerRestartInstance
return this.availableServices.includes(this.restartServiceName)
}
get confirmUnsavedChanges() {
Expand Down
45 changes: 7 additions & 38 deletions src/components/settings/SettingsEditorTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@
:title="$t('Settings.EditorTab.UseEscToClose')"
:sub-title="$t('Settings.EditorTab.UseEscToCloseDescription')"
:dynamic-slot-width="true">
<v-switch v-model="escToClose" hide-details class="mt-0"></v-switch>
<v-switch v-model="escToClose" hide-details class="mt-0" />
</settings-row>
<v-divider class="my-2"></v-divider>
<v-divider class="my-2" />
<settings-row
:title="$t('Settings.EditorTab.ConfirmUnsavedChanges')"
:sub-title="$t('Settings.EditorTab.ConfirmUnsavedChangesDescription')"
:dynamic-slot-width="true">
<v-switch v-model="confirmUnsavedChanges" hide-details class="mt-0"></v-switch>
<v-switch v-model="confirmUnsavedChanges" hide-details class="mt-0" />
</settings-row>

<v-divider class="my-2"></v-divider>
<v-divider class="my-2" />
<settings-row
:title="$t('Settings.EditorTab.TabSize')"
:sub-title="$t('Settings.EditorTab.TabSizeDescription')"
:dynamic-slot-width="true">
<v-select v-model="tabSize" :items="tabSizes" hide-details outlined dense attached></v-select>
<v-select v-model="tabSize" :items="tabSizes" hide-details outlined dense attached />
</settings-row>

<v-divider class="my-2"></v-divider>
<v-divider class="my-2" />
<settings-row
:title="$t('Settings.EditorTab.KlipperRestartMethod')"
:sub-title="$t('Settings.EditorTab.KlipperRestartMethodDescription')">
Expand All @@ -34,23 +32,8 @@
hide-details
outlined
dense
attached></v-select>
attached />
</settings-row>
<v-divider class="my-2"></v-divider>
<template v-if="availableMoonrakerInstances.length > 1">
<settings-row
:title="$t('Settings.EditorTab.MoonrakerRestartInstance')"
:sub-title="$t('Settings.EditorTab.MoonrakerRestartInstanceDescription')">
<v-select
v-model="moonrakerRestartInstance"
:items="availableMoonrakerInstances"
hide-details
outlined
dense
attached></v-select>
</settings-row>
<v-divider class="my-2"></v-divider>
</template>
</v-card-text>
</v-card>
</div>
Expand Down Expand Up @@ -115,19 +98,5 @@ export default class SettingsEditorTab extends Mixins(BaseMixin) {
set klipperRestartMethod(newVal) {
this.$store.dispatch('gui/saveSetting', { name: 'editor.klipperRestartMethod', value: newVal })
}
get moonrakerRestartInstance() {
return this.$store.state.gui.editor.moonrakerRestartInstance
}
set moonrakerRestartInstance(newVal) {
this.$store.dispatch('gui/saveSetting', { name: 'editor.moonrakerRestartInstance', value: newVal })
}
get availableMoonrakerInstances() {
const available_instances = this.$store.state.server.system_info?.available_services ?? []
return available_instances.filter((name: string) => name.startsWith('moonraker')).sort()
}
}
</script>
2 changes: 0 additions & 2 deletions src/locales/cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,6 @@
"Editor": "Editor",
"KlipperRestartMethod": "Metoda restartu Klipperu",
"KlipperRestartMethodDescription": "Vyberte metodu restartu, která se použije při editaci konfiguračních souborů Klipperu v \"Uložit a restartovat\".",
"MoonrakerRestartInstance": "Restart instance Moonrakeru",
"MoonrakerRestartInstanceDescription": "Vyberte, která služba Moonrakeru se restartuje v \"Uložit a restartovat\", když se editují konfigurační soubory Moonrakeru.",
"UseEscToClose": "Použít ESC pro zavření editoru",
"UseEscToCloseDescription": "Umožňuje použití klávesy ESC k zavření editoru"
},
Expand Down
2 changes: 0 additions & 2 deletions src/locales/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,6 @@
"Editor": "Editor",
"KlipperRestartMethod": "Metode for genstart af Klipper",
"KlipperRestartMethodDescription": "Vælg hvilken metode der skal bruges ved brug af 'Gem & Genstart' når der redigeres i Klipper config filer.",
"MoonrakerRestartInstance": "Genstart Moonraker instans",
"MoonrakerRestartInstanceDescription": "Vælg hvilken instans af Moonraker servicen der skal genstartes ved brug af 'Gem & Genstart' når der redigeres i Moonraker config filer.",
"UseEscToClose": "Tryk ESC for at lukke Editor.",
"UseEscToCloseDescription": "Tillader at ESC lukker Editor"
},
Expand Down
2 changes: 0 additions & 2 deletions src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,6 @@
"Editor": "Editor",
"KlipperRestartMethod": "Klipper Neustartmethode",
"KlipperRestartMethodDescription": "Wähle aus, welche Neustartmethode verwendet werden soll wenn 'Speichern & Neustarten' geklickt wir im Editor.",
"MoonrakerRestartInstance": "Moonraker Neustartinstanz",
"MoonrakerRestartInstanceDescription": "Wähle aus, welche Moonrakerinstanz neu gestartet werden soll wenn 'Speichern & Neustarten' im Editor geklickt wird.",
"UseEscToClose": "ESC drücken um Editor zu schließen",
"UseEscToCloseDescription": "Erlaubt es den Editor mit ESC zu schließen.",
"TabSize": "TAB Größe",
Expand Down
2 changes: 0 additions & 2 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,6 @@
"Editor": "Editor",
"KlipperRestartMethod": "Klipper restart method",
"KlipperRestartMethodDescription": "Select which restart method will be used on 'Save & Restart' when editing Klipper config files.",
"MoonrakerRestartInstance": "Moonraker restart instance",
"MoonrakerRestartInstanceDescription": "Select which Moonraker service will restart on 'Save & Restart' when editing Moonraker config files.",
"UseEscToClose": "Use ESC to close editor",
"UseEscToCloseDescription": "Allows the ESC key to close the editor",
"TabSize": "TAB Size",
Expand Down
2 changes: 0 additions & 2 deletions src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,6 @@
"Editor": "Editor",
"KlipperRestartMethod": "Metodo de reinicio de klipper",
"KlipperRestartMethodDescription": "Elija metodo de reinicio que sera usado cuando editamos configuracion de klipper y presionamos \"Guardar y Reiniciar\"",
"MoonrakerRestartInstance": "Instancia de Moonraker a reinicar",
"MoonrakerRestartInstanceDescription": "Elija que instacia de moonrker se reiniciara cuando editando configuracionde monnraker presionemos \"Guardar y reiniciar\" ",
"UseEscToClose": "Use ESC para cerrar",
"UseEscToCloseDescription": "Permite que la tecla ESC cierre el editor"
},
Expand Down
2 changes: 0 additions & 2 deletions src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,6 @@
"Editor": "Editeur",
"KlipperRestartMethod": "Méthode de redémarrage de Klipper",
"KlipperRestartMethodDescription": "Choisissez la méthode utilisée pour redémarrer Klipper lors d'un appui sur 'Save & Restart' après édition des fichiers de configuration.",
"MoonrakerRestartInstance": "Redémarrage Moonraker",
"MoonrakerRestartInstanceDescription": "Choisissez quel service Moonraker doit redémarrer lors d'un appui sur 'Save & Restart' après édition des fichiers de configuration.",
"UseEscToClose": "Utiliser la touche \"esc\" pour fermer l'éditeur",
"UseEscToCloseDescription": "Autoriser la touche \"esc\" de fermer l'éditeur."
},
Expand Down
2 changes: 0 additions & 2 deletions src/locales/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,6 @@
"Editor": "Szerkesztő",
"KlipperRestartMethod": "Klipper újraindítási mód",
"KlipperRestartMethodDescription": "Válaszd ki milyen újraindítási módot használjunk a 'Ment és Újraindít' esetén, amikor a klipper konfig fájlait szerkeszted.",
"MoonrakerRestartInstance": "Moonraker példány Újraindítása",
"MoonrakerRestartInstanceDescription": "Válaszd ki melyik Moonraker szolgáltatást indítsuk újra a 'Ment és Újraindít' esetén, amikor a Moonraker konfig fájlait szerkeszted.",
"UseEscToClose": "Kilépéshez nyomd meg az ESC gombot",
"UseEscToCloseDescription": "Az ESC gomb megnyomása bezárja a szerkesztőt",
"TabSize": "TAB Méret",
Expand Down
2 changes: 0 additions & 2 deletions src/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,6 @@
"Editor": "エディター",
"KlipperRestartMethod": "Klipper再始動の方法",
"KlipperRestartMethodDescription": "Klipperの設定ファイルを編集する際に'保存して再始動'での再始動方法を選択してください。",
"MoonrakerRestartInstance": "Moonraker インスタンスの再始動",
"MoonrakerRestartInstanceDescription": "Moonrakerの設定ファイルを編集する際に'保存して再始動'で、どのMoonrakerサービスを再始動するか選択してください。",
"UseEscToClose": "ESCキーでエディターを終了します。",
"UseEscToCloseDescription": "ESCキーでエディターを終了できます。"
},
Expand Down
2 changes: 0 additions & 2 deletions src/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,6 @@
"Editor": "파일 편집기",
"KlipperRestartMethod": "클리퍼 재시작 방법",
"KlipperRestartMethodDescription": "printer.cfg 파일을 수정 후, '저장 및 다시 시작'을 클릭할 때 사용할 다시 시작 방법을 선택합니다",
"MoonrakerRestartInstance": "문래커 재시작 방법",
"MoonrakerRestartInstanceDescription": "moonraker.conf 파일을 수정할 때 '저장 및 다시 시작'을 클릭할 때 사용할 문래커 서비스를 선택합니다",
"UseEscToClose": "ESC키를 눌러 종료",
"UseEscToCloseDescription": "ESC 키를 눌렀을 때 파일 편집기를 종료하며 만약 비활성화 했을 경우 ESC 키를 누르는 즉시 기존 입력 값은 모두 취소됩니다"
},
Expand Down
2 changes: 0 additions & 2 deletions src/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,6 @@
"Editor": "Editor",
"KlipperRestartMethod": "Klipper restart methode",
"KlipperRestartMethodDescription": "Selecteerd welke herstart methode gebruikt wordt bij 'Save & Restart' na het bewerken van de Klipper config files.",
"MoonrakerRestartInstance": "Moonraker instantie herstarten",
"MoonrakerRestartInstanceDescription": "Selecteer welke Moonraker service herstart na 'Save & Restart' bij het bewerken van Moonraker config bestanden.",
"UseEscToClose": "Gebruik ESC om de editor te sluiten",
"UseEscToCloseDescription": "Laat de ESC toets de editor sluiten"
},
Expand Down
2 changes: 0 additions & 2 deletions src/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,6 @@
"Editor": "Edytor",
"KlipperRestartMethod": "Metoda restartu Klippera",
"KlipperRestartMethodDescription": "Wybierz która metoda ponownego uruchomienia ma być używana podczas 'Zapisz i Uruchom ponownie' podczas edytowania plików konfiguracyjnych Klippera.",
"MoonrakerRestartInstance": "Ponowne uruchomienie instancji Moonrakera",
"MoonrakerRestartInstanceDescription": "Wybierz która metoda ponownego uruchomienia ma być używana podczas 'Zapisz i Uruchom ponownie' podczas edytowania plików konfiguracyjnych Moonrakera.",
"UseEscToClose": "Naciśnij ESC, aby wyjść z edytora",
"UseEscToCloseDescription": "Umożliwia zamknięcie edytora za pomocą klawisza ESC",
"TabSize": "Rozmiar tabulacji",
Expand Down
2 changes: 0 additions & 2 deletions src/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,6 @@
"Editor": "Editor",
"KlipperRestartMethod": "Método para reiniciar Klipper",
"KlipperRestartMethodDescription": "Selecione o método de reinicialização que será usado em 'Salvar e Reiniciar' ao editar arquivos de configuração do Klipper.",
"MoonrakerRestartInstance": "Reiniciar a instância do Moonraker",
"MoonrakerRestartInstanceDescription": "Selecione qual serviço do Moonraker será reiniciado em 'Salvar e Reiniciar' ao editar arquivos de configuração do Moonraker.",
"Spaces": "Espaços: {count}",
"TabSize": "Tamanho TAB",
"TabSizeDescription": "Ajusta quantos espaços devem ser usados para a indentação de TAB.",
Expand Down
2 changes: 0 additions & 2 deletions src/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,6 @@
"Editor": "Редактор",
"KlipperRestartMethod": "Способ перезапуска Klipper",
"KlipperRestartMethodDescription": "Выберите какой способ перезапуска Klipper будет использоваться, после нажатия 'СОХРАНИТЬ И ПЕРЕЗАПУСТИТЬ' при редактировании конфигурационных файлов Klipper.",
"MoonrakerRestartInstance": "Способ перезапуска Moonraker",
"MoonrakerRestartInstanceDescription": "Выберите какой способ перезапуска Moonraker будет использоваться, после нажатия 'СОХРАНИТЬ И ПЕРЕЗАПУСТИТЬ' при редактировании конфигурационных файлов Moonraker.",
"UseEscToClose": "Использование клавиши ESC",
"UseEscToCloseDescription": "Позволяет использовать клавишу ESC для закрытия редактора",
"TabSize": "Размер табуляции",
Expand Down
2 changes: 0 additions & 2 deletions src/locales/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,6 @@
"Editor": "Redigerare",
"KlipperRestartMethod": "Klipper omstartsmetod",
"KlipperRestartMethodDescription": "Välj vilken omstartsmetod som ska användas på 'Spara och starta om' vid redigering av Klipper-konfigurationsfiler.",
"MoonrakerRestartInstance": "Starta om Moonraker instans",
"MoonrakerRestartInstanceDescription": "Välj vilken Moonraker-tjänst som ska startas om under \"Spara och starta om\" när du redigerar Moonraker-konfigurationsfiler.",
"UseEscToClose": "Använd ESC för att stänga redigeringsprogrammet",
"UseEscToCloseDescription": "Tillåter att ESC-tangenten stänger redigeraren"
},
Expand Down
2 changes: 0 additions & 2 deletions src/locales/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,6 @@
"Editor": "Editör",
"KlipperRestartMethod": "Klipper yeniden başlatma yöntemi",
"KlipperRestartMethodDescription": "Klipper yapılandırma dosyalarını düzenlerken 'Kaydet ve Yeniden Başlat' seçildiğinde hangi yeniden başlatma yönteminin kullanılacağını seçin.",
"MoonrakerRestartInstance": "Moonraker örnek yeniden başlatma",
"MoonrakerRestartInstanceDescription": "Moonraker yapılandırma dosyalarını düzenlerken 'Kaydet ve Yeniden Başlat' seçildiğinde hangi Moonraker hizmetinin yeniden başlayacağını seçin.",
"UseEscToClose": "Editörü kapatmak için ESC tuşunu kullan",
"UseEscToCloseDescription": "ESC tuşunun editörü kapatmasına izin verir",
"TabSize": "TAB Boyutu",
Expand Down
2 changes: 0 additions & 2 deletions src/locales/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,6 @@
"Editor": "Редактор",
"KlipperRestartMethod": "Метод перезапуску Klipper",
"KlipperRestartMethodDescription": "Виберіть, який метод перезавантаження буде використовуватися на 'Зберегти та перезапустити' під час редагування файлів конфігурації Klipper..",
"MoonrakerRestartInstance": "Інстанція перезапуску Moonraker",
"MoonrakerRestartInstanceDescription": "Виберіть, яка послуга Moonraker перезапуститься на 'Зберегти та перезапустити' під час редагування файлів конфігурації Moonraker.",
"UseEscToClose": "Використовуйте ESC для закриття редактора",
"UseEscToCloseDescription": "Дозволяє клавішу ESC закрити редактор"
},
Expand Down
2 changes: 0 additions & 2 deletions src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,6 @@
"Editor": "编辑器",
"KlipperRestartMethod": "Klipper重启方法",
"KlipperRestartMethodDescription": "编辑完Klipper配置文件并按下\"保存并重启\"按钮后,使用哪种重启方法。",
"MoonrakerRestartInstance": "重启Moonraker实例",
"MoonrakerRestartInstanceDescription": "编辑完Moonraker配置文件并按下\"保存并重启\"按钮后,重启哪个Moonraker服务。",
"UseEscToClose": "使用ESC关闭编辑器",
"UseEscToCloseDescription": "允许使用ESC键关闭编辑器",
"TabSize": "TAB长度",
Expand Down
2 changes: 0 additions & 2 deletions src/locales/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,6 @@
"Editor": "編輯器",
"KlipperRestartMethod": "Klipper重新啟動方法",
"KlipperRestartMethodDescription": "編輯完Klipper設定檔案並按下\"儲存並重新啟動\"按鈕後,使用哪種重新啟動方法。",
"MoonrakerRestartInstance": "重新啟動Moonraker",
"MoonrakerRestartInstanceDescription": "編輯完Moonraker設定檔案並按下\"儲存並重新啟動\"按鈕後,重新啟動哪個Moonraker服務。",
"Spaces": "空間: {count}",
"TabSize": "標籤大小",
"UseEscToClose": "使用 ESC 關閉編輯器",
Expand Down
Loading

0 comments on commit 8447be2

Please sign in to comment.