/* * TxMenu.hpp * * Created on: Dec 10, 2009 * Author: crueger */ #ifndef TXMENU_HPP_ #define TXMENU_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include "Menu/Menu.hpp" #include "Helpers/defs.hpp" class MenuItem; /** Menu for the TextUI. * * Used to produce any kind of text menu. This is a generic text menu user * interface, i.e. we have a list of MenuItem's, which can either be * -# Action's * -# Displayers * -# Separators * -# other Menu's * * In this manner we have a tree structure, the (sub)menus generating new * branches, the rest making up the leaves. * * All Items are displayed via a given output stream and user is prompted * for a key. The item corresponding to that key is then activated. */ class TxMenu { public: class LeaveAction; TxMenu(std::ostream& _outputter, const std::string _title, char _spacer=STD_MENU_TITLE_SPACER,int _length=STD_MENU_LENGTH); ~TxMenu(); void addItem(MenuItem*); void removeItem(MenuItem*); void display(); std::string getTitle(); std::ostream& getOutputter(); char getSuitableShortForm(std::set &ShortcutList, const std::string name) const; /** * Call doQuit if you want to return from this menu. */ void doQuit(); /** * Check whether someone has chosen to quit */ bool hasQuit(); void addDefault(MenuItem*); protected: void showEntry(MenuItem*); private: std::list items; MenuItem* defaultItem; std::ostream& outputter; std::string title; char spacer; int length; bool quit; }; #endif /* TXMENU_HPP_ */