|
Last change
on this file since 3896fc 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
|
| Rev | Line | |
|---|
| [d20ed5] | 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>
|
|---|
| [212c827] | 13 | #include <iostream>
|
|---|
| [d20ed5] | 14 |
|
|---|
| [da09909] | 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 | */
|
|---|
| [d20ed5] | 19 | MenuItem::MenuItem(char _trigger, const char* _description,Menu* menu) :
|
|---|
| [212c827] | 20 | trigger(_trigger),
|
|---|
| 21 | added(false)
|
|---|
| [d20ed5] | 22 | {
|
|---|
| 23 | description = new string(_description);
|
|---|
| [7cb300] | 24 | add_to_menu(menu);
|
|---|
| [d20ed5] | 25 | }
|
|---|
| 26 |
|
|---|
| 27 | MenuItem::~MenuItem()
|
|---|
| 28 | {
|
|---|
| 29 | delete description;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| [da09909] | 32 | /**
|
|---|
| 33 | * check if the trigger matches and call doTrigger if it does.
|
|---|
| 34 | */
|
|---|
| [aa117c] | 35 | bool MenuItem::checkTrigger(char key) {
|
|---|
| 36 | if(key == trigger) {
|
|---|
| [d20ed5] | 37 | doTrigger();
|
|---|
| [aa117c] | 38 | return true;
|
|---|
| 39 | }
|
|---|
| 40 | else
|
|---|
| 41 | return false;
|
|---|
| 42 |
|
|---|
| [d20ed5] | 43 | }
|
|---|
| 44 |
|
|---|
| 45 | char MenuItem::getTrigger() {
|
|---|
| 46 | return trigger;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | const string MenuItem::getDescription() {
|
|---|
| 50 | return *description;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| [da09909] | 53 | /**
|
|---|
| 54 | * Produce a formated output of this item containing trigger and description
|
|---|
| 55 | * Normal format is: "<trigger> - <description>"
|
|---|
| 56 | */
|
|---|
| [d20ed5] | 57 | const string MenuItem::formatEntry(){
|
|---|
| 58 | stringstream s;
|
|---|
| 59 | s << getTrigger() << " - " << getDescription();
|
|---|
| 60 |
|
|---|
| 61 | return s.str();
|
|---|
| 62 | }
|
|---|
| [7cb300] | 63 |
|
|---|
| [da09909] | 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 | */
|
|---|
| [7cb300] | 70 | void MenuItem::add_to_menu(Menu* menu) {
|
|---|
| 71 | if(!wasAdded()) {
|
|---|
| 72 | menu->addItem(this);
|
|---|
| 73 | added=true;
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | bool MenuItem::wasAdded(){
|
|---|
| 78 | return added;
|
|---|
| 79 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.