i18n: ide, ecere, documentor: New strings, Chinese
[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    DataField expressionField { "char *", true, width = 130, header = $"Expression" };
77    DataField typeField { "Type", false, width = 180, header = $"Type" };
78    //DataField addressField { "char *", true, width = 80, header = $"Symbol Address" };
79    DataField valueField { class(WatchMultiLineString), true, width = 330, header = $"Value", freeData = false };
80
81    WatchesView()
82    {
83       listBox.AddField(expressionField);
84       listBox.AddField(typeField);
85       listBox.AddField(valueField);
86    }
87
88    bool OnKeyDown(Key key, unichar ch)
89    {
90       switch(key)
91       {
92          case escape: ide.ShowCodeEditor(); break;
93       }
94       return true;
95    }
96
97    bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
98    {
99       if(active)
100       {
101          //listBox.SelectRow(listBox.firstRow);
102          ide.RepositionWindows(false);
103       }
104       return true;
105    }
106
107    bool OnClose(bool parentClosing)
108    {
109       visible = false;
110       if(!parentClosing)
111          ide.RepositionWindows(false);
112       return parentClosing;
113    }
114
115    void Show()
116    {
117       visible = true;
118       Activate();
119    }
120
121    void LoadFromWorkspace()
122    {
123       for(wh : ide.workspace.watches)
124          AddWatch(wh);
125    }
126
127    void AddWatch(Watch wh)
128    {
129       DataRow row = listBox.AddRowAfter(listBox.lastRow.previous);
130       row.tag = (int)wh;
131       wh.row = row;
132       UpdateWatch(wh);
133    }
134
135    void UpdateWatch(Watch wh)
136    {
137       if(wh)
138       {
139          DataRow row = wh.row;
140          if(row && row.tag)
141          {
142             row.SetData(expressionField, wh.expression);
143             row.SetData(typeField, wh.type);
144             //row.SetData(addressField, wh.address);
145             row.SetData(valueField, wh.value);
146          }
147       }
148    }
149
150    void Clear()
151    {
152       DataRow row;
153       listBox.Clear();
154       row = listBox.AddRow();
155       row.SetData(expressionField, null);
156       row.SetData(typeField, null);
157       row.SetData(valueField, null);
158    }
159 }
160
161 class WatchMultiLineString : String
162 {
163    Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
164    {
165       if(this && strchr(this, '\n'))
166       {
167          // Don't show the editbox right away so that the text is highlighted by default
168          EditBox editBox
169          {
170             parent = dataBox, master = obsolete, visible = false,
171             borderStyle = contour,
172             //interim = true,
173             hasHorzScroll = true, hasVertScroll = true,
174             modifyVirtualArea = false,
175             anchor = { 0, 0, 0, 0 };
176             //position = { x + dataBox.absPosition.x, y + dataBox.absPosition.y };
177             //size = { w, h * 4 }; 
178             multiLine = true;
179
180             bool OnKeyDown(Key key, unichar ch)
181             {
182                /*if(key == escape)
183                {
184                   ((ListBox)master.master).currentField = ((ListBox)master.master).firstField;
185                   return false;
186                }*/
187                return EditBox::OnKeyDown(key, ch);
188             }
189
190             bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
191             {
192                if(active) SelectAll(); else Deselect();
193                return EditBox::OnActivate(active, previous, goOnWithActivation, direct);
194             }
195
196             void DataBox::NotifyUpdate(EditBox editBox)
197             {
198                Modified();          
199
200             }
201          };
202          dataBox.size = { w, h * 4 + 2 }; 
203          if(dataBox.size.h + dataBox.position.y > dataBox.parent.clientSize.h)
204             dataBox.position.y = dataBox.parent.clientSize.h - dataBox.size.h;
205          if(dataBox.size.w + dataBox.position.x > dataBox.parent.clientSize.w)
206             dataBox.position.x = dataBox.parent.clientSize.w - dataBox.size.w;
207
208          editBox.contents = this;
209          editBox.visible = true;
210          editBox.Create();
211          if(!dataBox.active)
212          {
213             editBox.Deselect();
214             editBox.Home();
215          }
216          return editBox;
217       }
218       else
219          return String::OnEdit(dataBox, obsolete, x, y, w,h, userData);
220    }
221
222    bool OnSaveEdit(Window window, void * object)
223    {
224       bool changed = false;
225       EditBox editBox = (EditBox)window;
226       if(editBox.modifiedDocument)
227       {
228       /*
229          EditLine line;
230          int size = 0;
231          char * string;
232
233          delete this;
234
235          for(line = editBox.firstLine; line; line = line.next)
236             size += line.count+1;
237          this = string = new char[size+1];
238          size = 0;
239          for(line = editBox.firstLine; line; line = line.next)
240          {
241             memcpy(string + size, line.text, line.count);
242             size += line.count;
243             string[size] = '\n';
244             size++;
245          }
246          string[size] = '\0';
247 */
248          changed = true;
249       }
250       return changed;
251    }
252
253    void OnDisplay(Surface surface, int x, int y, int width, void * fieldData, Alignment alignment, DataDisplayFlags displayFlags)
254    {
255       if(this)
256       {
257          char ch;
258          char * string = this;
259          char actualString[8196];
260          int c, len = 0;
261          for(c = 0; (ch = string[c]); c++)
262          {
263             if(ch == '\t') { actualString[len++] = '\\'; actualString[len++] = 't'; }
264             else if(ch == '\r') { actualString[len++] = '\\'; actualString[len++] = 'r'; }
265             else if(ch == '\n') { actualString[len++] = '\\'; actualString[len++] = 'n'; }
266             else actualString[len++] = ch;
267          }
268          actualString[len] = 0;
269          class(String)._vTbl[__ecereVMethodID_class_OnDisplay](class(String), actualString, surface, x, y, width, null, alignment, displayFlags);
270       }
271    }
272 };