|
FMI Ticket System
| Kamen Mladenov | FMI Computer Science Year 1 Group 6 | Project 1 | Project Topic 4 |
|
Handles navigation between multiple commands. More...
#include <Menu.h>
Public Member Functions | |
| Menu () | |
| Sets name as "Menu", leaves all flags to false and creates an empty Command list. | |
| Menu (const char *title, bool backExistsApp, bool isSubMenu) | |
| Copies title, saves flags and creates and empty Command list. More... | |
| Menu (const char *title, bool backExistsApp, bool isSubMenu, const Command *commands, unsigned commandCount) | |
| Copies title, saves flags and copies commands. More... | |
| void | addCommand (const Command &command) |
| Adds a command to the internal Command list. | |
| void | registerError (const char *message) const |
| Tell Menu to show an error message next time it prints. More... | |
| void | registerWarning (const char *message) const |
| Tell Menu to show a warning message next time it prints. More... | |
| void | registerSuccess (const char *message) const |
| Tell Menu to show a success message next time it prints. More... | |
| void | navigate () const |
| Lists commands and after user input executes an appropriate command run() function. More... | |
Handles navigation between multiple commands.
Shows the title, then below it an Error/Warning/Success message if set, lists all command options as an enumerated list, takes command index and calls the chosen command's run() function.
| Menu::Menu | ( | const char * | title, |
| bool | backExistsApp, | ||
| bool | isSubMenu | ||
| ) |
Copies title, saves flags and creates and empty Command list.
| title | C-style string, class stores at most 255 characters (last character is always terminating zero) |
| backExistsApp | Flag whether or not to list the 0-th option as "Exit", rather than "Go Back" |
| isSubMenu | Flag whether or not to show the title as a subTitle or not |
| Menu::Menu | ( | const char * | title, |
| bool | backExistsApp, | ||
| bool | isSubMenu, | ||
| const Command * | commands, | ||
| unsigned | commandCount | ||
| ) |
Copies title, saves flags and copies commands.
| title | C-style string, class stores at most 255 characters (last character is always terminating zero) |
| backExistsApp | Flag whether or not to list the 0-th option as "Exit", rather than "Go Back" |
| isSubMenu | Flag whether or not to show the title as a subTitle or not |
| commands | Pointer to an array of Command instances |
| commandCount | Number of elements that "commands" points to |
| void Menu::navigate | ( | ) | const |
Lists commands and after user input executes an appropriate command run() function.
Prints the title, then an Error/Warning/Sucess message (if set), prints all command names as an ordered list (starting from 1), waits for user input to select one of those commands (by list number) and finally executes the appropriate command's run() function.
After the run() function exists, everything is reprinted. The 0 list index is always "Go Back"/"Exit" and it always stops the reprinting loop.
If there are no commands, prints "Menu is empty!". If user input doesn't correspond to any command, registers an error message and reprints.
| void Menu::registerError | ( | const char * | message | ) | const |
Tell Menu to show an error message next time it prints.
| message | C-style string, saves to pointer for later reuse when showing the message. |
Stores the message pointer in a global variable (in the cpp file) and sets it's type as an Error in another global variable (in the cpp file).
The next time the whole Menu is shown, the message will appear below the title.
| void Menu::registerSuccess | ( | const char * | message | ) | const |
Tell Menu to show a success message next time it prints.
| message | C-style string, saves to pointer for later reuse when showing the message. |
Stores the message pointer in a global variable (in the cpp file) and sets it's type as Success in another global variable (in the cpp file).
The next time the whole Menu is shown, the message will appear below the title.
| void Menu::registerWarning | ( | const char * | message | ) | const |
Tell Menu to show a warning message next time it prints.
| message | C-style string, saves to pointer for later reuse when showing the message. |
Stores the message pointer in a global variable (in the cpp file) and sets it's type as a Warning in another global variable (in the cpp file).
The next time the whole Menu is shown, the message will appear below the title.