Corrected compiler error
[rofl0r-motor.git] / src / ui / ncurses / uiwatcher.cc
blobfe9759736ce7fa6d099a0437236009d6a4b51125
1 #include "uiwatcher.h"
2 #include "uieditor.h"
3 #include "motordebugger.h"
5 uiwatcher watcher;
7 uiwatcher::uiwatcher() {
8 startpos = curpos = 0;
11 uiwatcher::~uiwatcher() {
14 INT uiwatcher::keyhandler(verticalmenu &m, INT k) {
15 vector<string> ws;
16 INT r;
18 m.clearonfocuslost = false;
19 r = -1;
21 switch(k) {
22 case CTRL('d'):
23 watcher.close();
24 case ALT('w'):
25 r = 0;
26 break;
28 case KEY_IC:
29 case CTRL('w'):
30 watcher.add();
31 break;
33 case KEY_DC:
34 ws = debugger.getwatches();
35 if(!ws.empty()) {
36 debugger.removewatch(*(ws.begin()+m.getpos()));
37 watcher.update();
39 break;
42 m.clearonfocuslost = true;
43 return r;
46 void uiwatcher::activate() {
47 textwindow w;
49 if(!visible()) {
50 ed.resizebottom(uiconf.getwatchlines());
52 m = verticalmenu(uiconf.getcolor(cp_menufr), uiconf.getcolor(cp_menusel));
53 w = textwindow(0, LINES-uiconf.getwatchlines()-1, COLS-1, LINES-2, uiconf.getcolor(cp_menufr));
54 w.open();
56 m.setwindow(w);
57 m.otherkeys = &keyhandler;
58 m.clearonfocuslost = true;
59 fvisible = true;
62 update();
65 void uiwatcher::add() {
66 string buf;
68 if(ui.input(motorui::text, buf = ed.atcursor(), _("Watch expression: "))
69 == motorui::yes) {
70 if(!debugger.iswatch(buf)) {
71 debugger.addwatch(buf);
74 if(visible()) {
75 activate();
76 update();
81 void uiwatcher::modify(const string &expr, const string &val) {
82 string buf;
84 if(ui.input(motorui::text, buf = val, _("change the value to: ")) == motorui::yes) {
85 debugger.setvar(expr, buf);
89 void uiwatcher::update() {
90 string val;
91 vector<string> ws;
92 vector<string>::iterator iw;
94 if(visible()) {
95 m.clear();
96 ws = debugger.getwatches();
98 for(iw = ws.begin(); iw != ws.end(); iw++) {
99 val = debugger.getvar(*iw);
100 m.additem(" " + *iw + ": " + (val.empty() ? _("(not avail)") : val));
103 m.redraw();
107 void uiwatcher::exec() {
108 INT i;
109 vector<string> ws;
110 vector<string>::iterator iw;
112 if(!visible()) activate();
114 ui.log(_("Watches: ~Ins~ add, ~Del~ remove, ~^D~ close, ~A-W~ return to editor"));
116 while(1) {
117 update();
118 if(!(i = m.open())) break;
120 if(debugger.running() && i) {
121 ws = debugger.getwatches();
122 iw = ws.begin()+i-1;
123 modify(*iw, debugger.getvar(*iw));
127 m.getpos(startpos, curpos);
128 ui.log();
131 bool uiwatcher::visible() {
132 return fvisible;
135 void uiwatcher::close() {
136 m.close();
137 ed.resizebottom(0);
138 fvisible = false;