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

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

Added possibility to add default Items to textMenus

  • 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 */
35bool MenuItem::checkTrigger(char key) {
36 if(key == trigger) {
37 doTrigger();
38 return true;
39 }
40 else
41 return false;
42
43}
44
45char MenuItem::getTrigger() {
46 return trigger;
47}
48
49const string MenuItem::getDescription() {
50 return *description;
51}
52
53/**
54 * Produce a formated output of this item containing trigger and description
55 * Normal format is: "<trigger> - <description>"
56 */
57const string MenuItem::formatEntry(){
58 stringstream s;
59 s << getTrigger() << " - " << getDescription();
60
61 return s.str();
62}
63
64
65/**
66 * check if this item is within a menu and add to menu if it is not yet contained anywhere
67 *
68 * TODO: include funtionality to move Items from one menu to another
69 */
70void MenuItem::add_to_menu(Menu* menu) {
71 if(!wasAdded()) {
72 menu->addItem(this);
73 added=true;
74 }
75}
76
77bool MenuItem::wasAdded(){
78 return added;
79}
Note: See TracBrowser for help on using the repository browser.