From f36eb4646b23e65e36f0b476bed0177d6230d06d Mon Sep 17 00:00:00 2001 From: InsanityAutomation <38436470+InsanityAutomation@users.noreply.github.com> Date: Sat, 13 Mar 2021 08:37:49 -0500 Subject: [PATCH] Custom menu items confirm option (#21338) Co-authored-by: Scott Lahteine --- Marlin/Configuration_adv.h | 8 +++++++- Marlin/src/lcd/menu/menu_custom.cpp | 15 ++++++++++++++- Marlin/src/lcd/menu/menu_main.cpp | 12 +++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 9ab3e2d04..fb1f79b23 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3455,22 +3455,28 @@ //#define CUSTOM_USER_MENU_TITLE "Custom Commands" #define USER_SCRIPT_DONE "M117 User Script Done" #define USER_SCRIPT_AUDIBLE_FEEDBACK - //#define USER_SCRIPT_RETURN // Return to status screen after a script + //#define USER_SCRIPT_RETURN // Return to status screen after a script + #define CUSTOM_MENU_ONLY_IDLE // Only show custom menu when the machine is idle #define USER_DESC_1 "Home & UBL Info" #define USER_GCODE_1 "G28\nG29W" + //#define USER_CONFIRM_1 // Show a confirmation dialog before this action #define USER_DESC_2 "Preheat for " PREHEAT_1_LABEL #define USER_GCODE_2 "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) + //#define USER_CONFIRM_2 #define USER_DESC_3 "Preheat for " PREHEAT_2_LABEL #define USER_GCODE_3 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) + //#define USER_CONFIRM_3 #define USER_DESC_4 "Heat Bed/Home/Level" #define USER_GCODE_4 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nG28\nG29" + //#define USER_CONFIRM_4 #define USER_DESC_5 "Home & Info" #define USER_GCODE_5 "G28\nM503" + //#define USER_CONFIRM_5 #endif /** diff --git a/Marlin/src/lcd/menu/menu_custom.cpp b/Marlin/src/lcd/menu/menu_custom.cpp index f3f946883..cc1a8a6e8 100644 --- a/Marlin/src/lcd/menu/menu_custom.cpp +++ b/Marlin/src/lcd/menu/menu_custom.cpp @@ -46,7 +46,20 @@ void _lcd_user_gcode(PGM_P const cmd) { void menu_user() { START_MENU(); BACK_ITEM(MSG_MAIN); - #define USER_ITEM(N) ACTION_ITEM_P(PSTR(USER_DESC_##N), []{ _lcd_user_gcode(PSTR(USER_GCODE_##N _DONE_SCRIPT)); }); + + #define GCODE_LAMBDA(N) []{ _lcd_user_gcode(PSTR(USER_GCODE_##N _DONE_SCRIPT)); } + #define _USER_ITEM(N) ACTION_ITEM_P(PSTR(USER_DESC_##N), GCODE_LAMBDA(N)); + #define _USER_ITEM_CONFIRM(N) \ + SUBMENU_P(PSTR(USER_DESC_##N), []{ \ + MenuItem_confirm::confirm_screen( \ + GCODE_LAMBDA(N), \ + ui.goto_previous_screen, \ + PSTR(USER_DESC_##N "?") \ + ); \ + }) + + #define USER_ITEM(N) do{ if (ENABLED(USER_CONFIRM_##N)) _USER_ITEM_CONFIRM(N); else _USER_ITEM(N); }while(0) + #if HAS_USER_ITEM(1) USER_ITEM(1); #endif diff --git a/Marlin/src/lcd/menu/menu_main.cpp b/Marlin/src/lcd/menu/menu_main.cpp index 1e864e35b..d19e236a8 100644 --- a/Marlin/src/lcd/menu/menu_main.cpp +++ b/Marlin/src/lcd/menu/menu_main.cpp @@ -211,11 +211,13 @@ void menu_main() { SUBMENU(MSG_CONFIGURATION, menu_configuration); #if ENABLED(CUSTOM_USER_MENUS) - #ifdef CUSTOM_USER_MENU_TITLE - SUBMENU_P(PSTR(CUSTOM_USER_MENU_TITLE), menu_user); - #else - SUBMENU(MSG_USER_MENU, menu_user); - #endif + if (TERN1(CUSTOM_MENU_ONLY_IDLE, !busy)) { + #ifdef CUSTOM_USER_MENU_TITLE + SUBMENU_P(PSTR(CUSTOM_USER_MENU_TITLE), menu_user); + #else + SUBMENU(MSG_USER_MENU, menu_user); + #endif + } #endif #if ENABLED(ADVANCED_PAUSE_FEATURE)