source: molecuilder/src/Menu/MenuItem.cpp@ da09909

Last change on this file since da09909 was da09909, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Improved documentation for menu framework.

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/*
2 * MenuItem.cpp
3 *
4 * Created on: Dec 10, 2009
5 * Author: crueger
6 */
7
8
9
10#include "Menu/MenuItem.hpp"
11#include "Menu/Menu.hpp"
12#include <sstream>
13#include <iostream>
14
15/**
16 * produce a new MenuItem using with a description and a trigger.
17 * The MenuItem is then added to the menu passed to it.
18 */
19MenuItem::MenuItem(char _trigger, const char* _description,Menu* menu) :
20trigger(_trigger),
21added(false)
22{
23 description = new string(_description);
24 add_to_menu(menu);
25}
26
27MenuItem::~MenuItem()
28{
29 delete description;
30}
31
32/**
33 * check if the trigger matches and call doTrigger if it does.
34 */
35void MenuItem::checkTrigger(char key) {
36 if(key == trigger)
37 doTrigger();
38}
39
40char MenuItem::getTrigger() {
41 return trigger;
42}
43
44const string MenuItem::getDescription() {
45 return *description;
46}
47
48/**
49 * Produce a formated output of this item containing trigger and description
50 * Normal format is: "<trigger> - <description>"
51 */
52const string MenuItem::formatEntry(){
53 stringstream s;
54 s << getTrigger() << " - " << getDescription();
55
56 return s.str();
57}
58
59
60/**
61 * check if this item is within a menu and add to menu if it is not yet contained anywhere
62 *
63 * TODO: include funtionality to move Items from one menu to another
64 */
65void MenuItem::add_to_menu(Menu* menu) {
66 if(!wasAdded()) {
67 menu->addItem(this);
68 added=true;
69 }
70}
71
72bool MenuItem::wasAdded(){
73 return added;
74}
Note: See TracBrowser for help on using the repository browser.