Changeset 143

Show
Ignore:
Timestamp:
05/15/07 09:49:23 (2 years ago)
Author:
ajps
Message:

Some cleanup of the command menu code - e.g. ESCAPE now steps back a level in the menu instead of closing altogether, cmd_redraw works properly.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/cmd0.c

    r142 r143  
    429429static bool cmd_sub_action(char cmd, void *db, int oid) 
    430430{ 
    431         const command_type *commands = db; 
    432  
    433         /* Forward/back don't do anything */ 
    434         if (cmd == ARROW_LEFT || cmd == ARROW_RIGHT) 
    435                 return FALSE; 
    436  
    437         /* Clear up */ 
    438         screen_load(); 
    439  
    440431        /* Only handle enter */ 
    441432        if (cmd == '\n' || cmd == '\r') 
    442                 commands[oid].hook(); 
    443  
    444         return TRUE; 
     433        { 
     434                return TRUE; 
     435        } 
     436        else 
     437        { 
     438                return FALSE; 
     439        } 
    445440} 
    446441 
     
    448443 * Display a list of commands. 
    449444 */ 
    450 static void cmd_menu(command_list *list
     445static bool cmd_menu(command_list *list, void *selection_p
    451446{ 
    452447        menu_type menu; 
     
    456451        event_type evt; 
    457452        int cursor = 0; 
    458  
     453        command_type *selection = selection_p; 
    459454 
    460455        /* Set up the menu */ 
     
    474469        /* Load de screen */ 
    475470        screen_load(); 
     471 
     472        if (evt.type == EVT_SELECT) 
     473        { 
     474                *selection = list->list[evt.index]; 
     475        } 
     476 
     477        if (evt.type == EVT_ESCAPE) 
     478        { 
     479                return FALSE; 
     480        } 
     481        else 
     482        { 
     483                return TRUE; 
     484        } 
    476485} 
    477486 
     
    480489static bool cmd_list_action(char cmd, void *db, int oid) 
    481490{ 
    482         cmd_menu(&cmds_all[oid]); 
    483         return TRUE; 
     491        if (cmd == '\n' || cmd == '\r' || cmd == '\xff') 
     492        { 
     493                return cmd_menu(&cmds_all[oid], db); 
     494        } 
     495        else 
     496        { 
     497                return FALSE; 
     498        } 
    484499} 
    485500 
     
    501516        event_type evt; 
    502517        int cursor = 0; 
    503  
     518        command_type chosen_command = { NULL, 0, NULL }; 
    504519 
    505520        /* Set up the menu */ 
    506521        WIPE(&menu, menu); 
    507         menu.cmd_keys = "\n\r\xff"; 
     522        menu.cmd_keys = "\x8B\x8C\n\r"; 
    508523        menu.count = N_ELEMENTS(cmds_all) - 1; 
     524        menu.menu_data = &chosen_command; 
    509525        menu_init2(&menu, find_menu_skin(MN_SCROLL), &commands_menu, &area); 
    510526 
     
    518534        /* Load de screen */ 
    519535        screen_load(); 
     536 
     537        /* If a command was chosen, do it. */ 
     538        if (chosen_command.hook) 
     539        { 
     540                chosen_command.hook(); 
     541        } 
    520542} 
    521543