From a47575911dfc360a95ae41585694c27aeb082f0a Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Fri, 17 Sep 2010 15:45:54 +0200 Subject: Menu: add box style entry this will allow you to create a box style entry via C API by specifying the type as struct menu_entry me = { .display "test", .type = MENU_ENTRY_BOX, .box_state = 1, .action = action_to_run, } and via shell menu -e -a -m -c [-R] [-b 0|1] -d menu -e -a -m -u submenu -d [-b 0|1] -b with 0 for not selected and 1 for selected and -c for the command to run when changing state Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- commands/menu.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'commands/menu.c') diff --git a/commands/menu.c b/commands/menu.c index d2ac5cdb24..b9d66996a4 100644 --- a/commands/menu.c +++ b/commands/menu.c @@ -49,11 +49,13 @@ struct cmd_menu { char *submenu; int num; int auto_select; + menu_entry_type type; + int box_state; #endif }; #if defined(CONFIG_CMD_MENU_MANAGEMENT) -#define OPTS "m:earlc:d:RsSn:u:A:" +#define OPTS "m:earlc:d:RsSn:u:A:b:B:" #define is_entry(x) ((x)->entry) #else #define OPTS "m:ls" @@ -62,8 +64,8 @@ struct cmd_menu { #if defined(CONFIG_CMD_MENU_MANAGEMENT) /* - * menu -e -a -m -c [-R] -d - * menu -e -a -m -u submenu -d + * menu -e -a -m -c [-R] [-b 0|1 ] -d + * menu -e -a -m -u submenu -d [-b 0|1] */ static int do_menu_entry_add(struct cmd_menu *cm) { @@ -83,11 +85,15 @@ static int do_menu_entry_add(struct cmd_menu *cm) if (cm->submenu) me = menu_add_submenu(m, cm->submenu, cm->description); else - me = menu_add_command_entry(m, cm->description, cm->command); + me = menu_add_command_entry(m, cm->description, cm->command, + cm->type); if (!me) return PTR_ERR(me); - me->non_re_ent = !cm->re_entrant; + me->box_state = cm->box_state > 0 ? 1 : 0; + + if (!cm->submenu) + me->non_re_ent = !cm->re_entrant; return 0; } @@ -358,6 +364,12 @@ static int do_menu(struct command *cmdtp, int argc, char *argv[]) break; case 'A': cm.auto_select = simple_strtoul(optarg, NULL, 10); + case 'b': + cm.type = MENU_ENTRY_BOX; + cm.box_state = simple_strtoul(optarg, NULL, 10); + break; + case 'B': + cm.command = optarg; break; #endif default: @@ -430,11 +442,15 @@ static const __maybe_unused char cmd_menu_help[] = "\n" "Add an entry\n" " (-R for do no exit the menu after executing the command)\n" -" menu -e -a -m -c [-R] -d \n" +" (-b for box style 1 for selected)\n" +" (and optional -c for the command to run when we change the state)\n" +" menu -e -a -m -c [-R] [-b 0|1] -d \n" "Add a submenu entry\n" " (-R is not needed)\n" -" menu -e -a -m -u -d \n" +" (-b for box style 1 for selected)\n" +" (and -c is not needed)\n" +" menu -e -a -m -u submenu -d [-b 0|1] \n" "\n" "Remove an entry\n" " menu -e -r -m -n \n" -- cgit v1.2.3