diff --git a/src/components/inputs/MacroButton.vue b/src/components/inputs/MacroButton.vue
index 9819a25c6f..a92a01e27e 100644
--- a/src/components/inputs/MacroButton.vue
+++ b/src/components/inputs/MacroButton.vue
@@ -5,7 +5,7 @@
:color="color"
:class="paramArray.length ? 'macroWithParameters' : ''"
:loading="loadings.includes('macro_' + macro.name)"
- :disabled="disabled"
+ :disabled="disabled || paramsRequired"
@click="doSendMacro(macro.name)">
{{ alias ? alias : macro.name.replace(/_/g, ' ') }}
@@ -24,28 +24,53 @@
-
-
-
-
-
-
-
-
- {{ $t('Panels.MacrosPanel.Send') }}
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+ {{ $t('Panels.MacrosPanel.Send') }}
+
+
+
+
@@ -60,33 +85,58 @@
-
-
- {{ mdiCloseThick }}
-
-
-
-
-
-
-
-
-
-
-
- {{ $t('Panels.MacrosPanel.Send') }}
-
-
+
+
+
+ {{ mdiCloseThick }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ $t('Panels.MacrosPanel.Send') }}
+
+
+
@@ -96,20 +146,18 @@
diff --git a/src/components/panels/MacrosPanel.vue b/src/components/panels/MacrosPanel.vue
index c87ac43868..7d4848c158 100644
--- a/src/components/panels/MacrosPanel.vue
+++ b/src/components/panels/MacrosPanel.vue
@@ -40,7 +40,13 @@ export default class MacrosPanel extends Mixins(BaseMixin) {
get macros() {
const macros = this.$store.getters['printer/getMacros']
- return macros.filter((macro: PrinterStateMacro) => !this.hiddenMacros.includes(macro.name.toLowerCase()))
+ return macros.filter(
+ (macro: PrinterStateMacro) => !macro.hidden && !this.hiddenMacros.includes(macro.name.toLowerCase())
+ )
+ }
+
+ get macroState() {
+ return this.$store.getters['printer/getMacro'](this.macro.name)
}
}
diff --git a/src/plugins/helpers.ts b/src/plugins/helpers.ts
index 7f4c89b313..c0ed40da2c 100644
--- a/src/plugins/helpers.ts
+++ b/src/plugins/helpers.ts
@@ -189,9 +189,9 @@ export function formatTime(date: Date): string {
return hours + ':' + minutes + ':' + seconds
}
-export function getMacroParams(macro: { gcode: string }): PrinterStateMacroParams {
+export function getMacroParamsFromConfig(macro: { gcode: string }): PrinterStateMacroParams {
const paramRegex =
- /{%?.*?params\.([A-Za-z_0-9]+)(?:\|(int|string|double))?(?:\|default\('?"?(.*?)"?'?\))?(?:\|(int|string))?.*?%?}/
+ /{%?.*?params\.([A-Za-z_0-9]+)(?:\|(int|string|float))?(?:\|default\('?"?(.*?)"?'?\))?(?:\|(int|string))?.*?%?}/
let params = paramRegex.exec(macro.gcode)
let currentMatch = macro.gcode
@@ -201,10 +201,10 @@ export function getMacroParams(macro: { gcode: string }): PrinterStateMacroParam
ret = {}
}
const name = params[1]
- const t: 'int' | 'string' | 'double' | null = (params[2] ?? params[4] ?? null) as
+ const t: 'int' | 'string' | 'float' | null = (params[2] ?? params[4] ?? null) as
| 'int'
| 'string'
- | 'double'
+ | 'float'
| null
const def = params[3] ?? null
ret[`${name}`] = {
@@ -237,6 +237,25 @@ export function getMacroParams(macro: { gcode: string }): PrinterStateMacroParam
return ret
}
+export function getMacroParamsFromState(hints: any): PrinterStateMacroParams {
+ if (!hints.params) return null
+ const allowedTypes = ['int', 'float', 'string', 'select', 'checkbox']
+ const newParams: PrinterStateMacroParams = {}
+ Object.keys(hints.params).forEach((name: string) => {
+ newParams![name.toUpperCase()] = {
+ // The type list here is from PrinterStateMacroParam
+ type: !Array.isArray(hints.params[name].type)
+ ? hints.params[name].type
+ : hints.params[name].type.find((type: string) => allowedTypes.includes(type)),
+ default: hints.params[name].default ? String(hints.params[name].default) : null,
+ hints: Object.fromEntries(
+ Object.entries(hints.params[name]).filter(([key]) => !['type', 'default'].includes(key))
+ ),
+ }
+ })
+ return newParams
+}
+
export function windowBeforeUnloadFunction(e: BeforeUnloadEvent) {
e.preventDefault()
e.returnValue = ''
diff --git a/src/store/printer/getters.ts b/src/store/printer/getters.ts
index c7ffcc3eb0..3bbcf74045 100644
--- a/src/store/printer/getters.ts
+++ b/src/store/printer/getters.ts
@@ -24,7 +24,12 @@ import {
PrinterGetterObject,
PrinterStateLight,
} from '@/store/printer/types'
-import { caseInsensitiveSort, formatFrequency, getMacroParams } from '@/plugins/helpers'
+import {
+ caseInsensitiveSort,
+ formatFrequency,
+ getMacroParamsFromState,
+ getMacroParamsFromConfig,
+} from '@/plugins/helpers'
import { RootState } from '@/store/types'
import {
mdiFan,
@@ -168,22 +173,21 @@ export const getters: GetterTree = {
const settings = state.configfile?.settings ?? null
Object.keys(config)
- .filter((prop) => prop.toLowerCase().startsWith('gcode_macro'))
+ .filter((prop) => prop.startsWith('gcode_macro') && !settings[prop.toLowerCase()]?.rename_existing)
.forEach((prop) => {
const name = prop.replace('gcode_macro ', '')
- if (name.startsWith('_')) return
+ const variables = state[prop] ?? {}
+ const hints = variables?.front_end_hints
const propLower = prop.toLowerCase()
const propSettings = settings[propLower]
- if ('rename_existing' in propSettings) return
-
- const variables = state[prop] ?? {}
array.push({
name,
description: settings[propLower].description ?? null,
prop: propSettings,
- params: getMacroParams(propSettings),
+ params: hints ? getMacroParamsFromState(hints) : getMacroParamsFromConfig(propSettings),
+ hidden: hints && 'hidden' in hints ? hints.hidden : name.startsWith('_'),
variables,
})
})
diff --git a/src/store/printer/types.ts b/src/store/printer/types.ts
index 5c2665e8a3..676b273dac 100644
--- a/src/store/printer/types.ts
+++ b/src/store/printer/types.ts
@@ -180,8 +180,9 @@ export interface PrinterStateBedMesh {
}
export interface PrinterStateMacroParam {
- type: 'int' | 'double' | 'string' | null
+ type: 'int' | 'float' | 'string' | 'select' | 'checkbox' | null
default: string | null
+ hints?: { [key: string]: any }
}
export type PrinterStateMacroParams = {
@@ -200,6 +201,7 @@ export interface PrinterStateMacro {
[key: string]: any
}
params: PrinterStateMacroParams
+ hidden: boolean
}
export interface PrinterStateKlipperConfig {