From 55eb71b2e0c9565d08785ab1227b983da33274a2 Mon Sep 17 00:00:00 2001 From: Pedro Lamas Date: Tue, 10 Jan 2023 14:45:15 +0000 Subject: [PATCH] fix: always show Preview Gcode in context menu Signed-off-by: Pedro Lamas --- src/components/widgets/filesystem/FileSystem.vue | 6 +++--- .../widgets/filesystem/FileSystemContextMenu.vue | 7 +++++-- src/store/layout/getters.ts | 6 ++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/widgets/filesystem/FileSystem.vue b/src/components/widgets/filesystem/FileSystem.vue index 4e4fcdf34c..ece250bb74 100644 --- a/src/components/widgets/filesystem/FileSystem.vue +++ b/src/components/widgets/filesystem/FileSystem.vue @@ -672,10 +672,10 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM this.getGcode(file) .then(response => response?.data) .then((gcode) => { - // If we aren't on the dashboard, push the user back there. - if (this.$router.currentRoute.path !== '/') { - this.$router.push({ path: '/' }) + if (this.$router.currentRoute.path !== '/' || !this.$store.getters['layout/isEnabledInCurrentLayout']('gcode-preview-card')) { + this.$router.push({ path: '/preview' }) } + this.$store.dispatch('gcodePreview/loadGcode', { file, gcode diff --git a/src/components/widgets/filesystem/FileSystemContextMenu.vue b/src/components/widgets/filesystem/FileSystemContextMenu.vue index 5dd8b52565..9338a876fd 100644 --- a/src/components/widgets/filesystem/FileSystemContextMenu.vue +++ b/src/components/widgets/filesystem/FileSystemContextMenu.vue @@ -189,8 +189,11 @@ export default class FileSystemContextMenu extends Mixins(StateMixin, FilesMixin } get canPreviewGcode () { - const layoutName = this.$store.getters['layout/getSpecificLayoutName'] - return (this.$store.getters['layout/isEnabledInLayout'](layoutName, 'gcode-preview-card') && this.root === 'gcodes') + return ( + this.file.type === 'file' && + this.file.extension === 'gcode' && + this.root === 'gcodes' + ) } get supportsJobQueue (): boolean { diff --git a/src/store/layout/getters.ts b/src/store/layout/getters.ts index a470ba5488..832408aeb5 100644 --- a/src/store/layout/getters.ts +++ b/src/store/layout/getters.ts @@ -36,6 +36,12 @@ export const getters: GetterTree = { return configs.find(configs => configs.id === id)?.enabled ?? false }, + isEnabledInCurrentLayout: (state, getters) => (id: string) => { + const layout = getters.getSpecificLayoutName + + return getters.isEnabledInLayout(layout, id) + }, + /** * Return a layout's container given a layout name and container name. */