cleaned all trailing white space from source files.
[sdk] / ide / src / panels / WatchesView.ec
1 import "ide"
2
3 class WatchesView : Window
4 {
5    visible = false;
6    text = $"Watches";
7    borderStyle = sizable;
8    background = { 224, 224, 224 };
9    hasClose = true;
10    anchor = Anchor { left = 0, right = 0, bottom = 0 };
11    size.h = 240;
12
13    bool moved, logging;
14
15    ListBox listBox
16    {
17       parent = this, hasHeader = true, hasVertScroll = true, alwaysEdit = true, collapseControl = true, resizable = true;
18       anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
19       background = viewsBackground;
20       foreground = viewsText;
21       selectionColor = selectionColor, selectionText = selectionText;
22
23       bool NotifyChanged(ListBox listBox, DataRow row)
24       {
25          char * expression = row.GetData(expressionField);
26
27          if(expression && expression[0])
28          {
29             TrimLSpaces(expression, expression);
30             TrimRSpaces(expression, expression);
31          }
32
33          if(expression && expression[0])
34          {
35             row.SetData(valueField, null);
36             if(row == listBox.lastRow)
37             {
38                DataRow newRow = listBox.AddRow();
39                newRow.SetData(expressionField, null);
40                newRow.SetData(valueField, null);
41                listBox.currentRow = newRow;
42             }
43             ide.debugger.ChangeWatch(row, expression);
44          }
45          else
46          {
47             ide.debugger.ChangeWatch(row, expression);
48             if(row != listBox.lastRow)
49             {
50                //Type type = (Type)row.GetData(typeField);
51                //if(type) FreeType(type);
52                listBox.DeleteRow(row);
53             }
54             else
55                row.SetData(valueField, null);
56          }
57          return true;
58       }
59
60       bool NotifyKeyHit(ListBox listBox, DataRow row, Key key, unichar ch)
61       {
62          if((SmartKey)key == del)
63          {
64             listBox.StopEditing(true);
65             if(row && row != listBox.lastRow)
66             {
67                //Type type = (Type)row.GetData(typeField);
68                ide.debugger.ChangeWatch(row, null);
69                //if(type) FreeType(type);
70                listBox.DeleteRow(null);
71             }
72          }
73          return true;
74       }
75
76       bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
77       {
78          if(listBox.currentField != expressionField)
79             listBox.currentField = expressionField;
80          return true;
81       }
82    };
83    DataField expressionField { "char *", true, width = 130, header = $"Expression" };
84    DataField typeField { "Type", false, width = 180, header = $"Type" };
85    //DataField addressField { "char *", true, width = 80, header = $"Symbol Address" };
86    DataField valueField { class(WatchMultiLineString), true, width = 330, header = $"Value", freeData = false };
87
88    WatchesView()
89    {
90       listBox.AddField(expressionField);
91       listBox.AddField(typeField);
92       listBox.AddField(valueField);
93    }
94
95    bool OnKeyDown(Key key, unichar ch)
96    {
97       switch(key)
98       {
99          case escape: ide.ShowCodeEditor(); break;
100       }
101       return true;
102    }
103
104    bool OnClose(bool parentClosing)
105    {
106       visible = false;
107       if(!parentClosing)
108          ide.RepositionWindows(false);
109       return parentClosing;
110    }
111
112    void Show()
113    {
114       visible = true;
115       ide.RepositionWindows(false);
116       Activate();
117    }
118
119    void LoadFromWorkspace()
120    {
121       for(wh : ide.workspace.watches)
122          AddWatch(wh);
123    }
124
125    void AddWatch(Watch wh)
126    {
127       DataRow row = listBox.AddRowAfter(listBox.lastRow.previous);
128       row.tag = (int64)wh;
129       wh.row = row;
130       UpdateWatch(wh);
131    }
132
133    void UpdateWatch(Watch wh)
134    {
135       if(wh)
136       {
137          DataRow row = wh.row;
138          if(row && row.tag)
139          {
140             row.SetData(expressionField, wh.expression);
141             row.SetData(typeField, wh.type);
142             //row.SetData(addressField, wh.address);
143             row.SetData(valueField, wh.value);
144          }
145       }
146    }
147
148    void Clear()
149    {
150       DataRow row;
151       listBox.Clear();
152       row = listBox.AddRow();
153       row.SetData(expressionField, null);
154       row.SetData(typeField, null);
155       row.SetData(valueField, null);
156       if(ide.workspace)
157       {
158          for(w : ide.workspace.watches)
159             w.row = null;
160       }
161    }
162 }
163
164 class WatchMultiLineString : String
165 {
166    Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
167    {
168       if(this && strchr(this, '\n'))
169       {
170          // Don't show the editbox right away so that the text is highlighted by default
171          EditBox editBox
172          {
173             parent = dataBox, master = obsolete, visible = false,
174             borderStyle = contour,
175             //interim = true,
176             hasHorzScroll = true, hasVertScroll = true,
177             modifyVirtualArea = false,
178             anchor = { 0, 0, 0, 0 };
179             //position = { x + dataBox.absPosition.x, y + dataBox.absPosition.y };
180             //size = { w, h * 4 };
181             multiLine = true;
182
183             bool OnKeyDown(Key key, unichar ch)
184             {
185                /*if(key == escape)
186                {
187                   ((ListBox)master.master).currentField = ((ListBox)master.master).firstField;
188                   return false;
189                }*/
190                return EditBox::OnKeyDown(key, ch);
191             }
192
193             bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
194             {
195                if(active) SelectAll(); else Deselect();
196                return EditBox::OnActivate(active, previous, goOnWithActivation, direct);
197             }
198
199             void DataBox::NotifyUpdate(EditBox editBox)
200             {
201                Modified();
202
203             }
204          };
205          dataBox.size = { w, h * 4 + 2 };
206          if(dataBox.size.h + dataBox.position.y > dataBox.parent.clientSize.h)
207             dataBox.position.y = dataBox.parent.clientSize.h - dataBox.size.h;
208          if(dataBox.size.w + dataBox.position.x > dataBox.parent.clientSize.w)
209             dataBox.position.x = dataBox.parent.clientSize.w - dataBox.size.w;
210
211          editBox.contents = this;
212          editBox.visible = true;
213          editBox.Create();
214          if(!dataBox.active)
215          {
216             editBox.Deselect();
217             editBox.Home();
218          }
219          return editBox;
220       }
221       else
222          return String::OnEdit(dataBox, obsolete, x, y, w,h, userData);
223    }
224
225    bool OnSaveEdit(Window window, void * object)
226    {
227       bool changed = false;
228       EditBox editBox = (EditBox)window;
229       if(editBox.modifiedDocument)
230       {
231       /*
232          EditLine line;
233          int size = 0;
234          char * string;
235
236          delete this;
237
238          for(line = editBox.firstLine; line; line = line.next)
239             size += line.count+1;
240          this = string = new char[size+1];
241          size = 0;
242          for(line = editBox.firstLine; line; line = line.next)
243          {
244             memcpy(string + size, line.text, line.count);
245             size += line.count;
246             string[size] = '\n';
247             size++;
248          }
249          string[size] = '\0';
250 */
251          changed = true;
252       }
253       return changed;
254    }
255
256    void OnDisplay(Surface surface, int x, int y, int width, void * fieldData, Alignment alignment, DataDisplayFlags displayFlags)
257    {
258       if(this)
259       {
260          char ch;
261          char * string = this;
262          char actualString[8196];
263          int c, len = 0;
264          for(c = 0; (ch = string[c]) && len < sizeof(actualString)-1; c++)
265          {
266             if(ch == '\t') { actualString[len++] = '\\'; actualString[len++] = 't'; }
267             else if(ch == '\r') { actualString[len++] = '\\'; actualString[len++] = 'r'; }
268             else if(ch == '\n') { actualString[len++] = '\\'; actualString[len++] = 'n'; }
269             else actualString[len++] = ch;
270          }
271          actualString[len] = 0;
272          ((void (*)(void *, void *, void *, int, int, int, void *, uint, uint))(void *)class(String)._vTbl[__ecereVMethodID_class_OnDisplay])(class(String), actualString, surface, x, y, width, null, alignment, displayFlags);
273       }
274    }
275 };