/* * TxMenu.h * * Created on: Dec 10, 2009 * Author: crueger */ #ifndef TXMENU_H_ #define TXMENU_H_ #include #include #include #include "Menu/Menu.hpp" #include "Actions/Action.hpp" #include "Actions/ActionTraits.hpp" #include "defs.hpp" class MenuItem; /** * Used to produce any kind of text menu * * All Items are displayed and user is prompted for a key. The item corresponding to that key is then activated. */ class TxMenu { public: class LeaveAction : public Action { public: LeaveAction(TxMenu* const, const ActionTraits &_trait); virtual ~LeaveAction(); bool canUndo(); bool shouldUndo(); protected: virtual Dialog* fillDialog(Dialog *dialog); private: virtual void getParametersfromValueStorage(); virtual Action::state_ptr performCall(); virtual Action::state_ptr performUndo(Action::state_ptr); virtual Action::state_ptr performRedo(Action::state_ptr); TxMenu* const menu; }; TxMenu(std::ostream& _outputter, const std::string _title, char _spacer=STD_MENU_TITLE_SPACER,int _length=STD_MENU_LENGTH); virtual ~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_H_ */