/* * MenuItem.cpp * * Created on: Dec 10, 2009 * Author: crueger */ #include "Menu/MenuItem.hpp" #include "Menu/Menu.hpp" #include #include /** * produce a new MenuItem using with a description and a trigger. * The MenuItem is then added to the menu passed to it. */ MenuItem::MenuItem(char _trigger, const char* _description,Menu* menu) : trigger(_trigger), added(false) { description = new string(_description); add_to_menu(menu); } MenuItem::~MenuItem() { delete description; } /** * check if the trigger matches and call doTrigger if it does. */ bool MenuItem::checkTrigger(char key) { if(key == trigger) { doTrigger(); return true; } else return false; } char MenuItem::getTrigger() { return trigger; } const string MenuItem::getDescription() { return *description; } /** * Produce a formated output of this item containing trigger and description * Normal format is: " - " */ const string MenuItem::formatEntry(){ stringstream s; s << getTrigger() << " - " << getDescription(); return s.str(); } /** * check if this item is within a menu and add to menu if it is not yet contained anywhere * * TODO: include funtionality to move Items from one menu to another */ void MenuItem::add_to_menu(Menu* menu) { if(!wasAdded()) { menu->addItem(this); added=true; } } bool MenuItem::wasAdded(){ return added; }