407dd72c6ac474a805965589f2f144154b82714e
[sdk] / ide / src / panels / CallStackView.ec
1 #include <stdarg.h>
2
3 import "ecere"
4 import "CodeEditor"
5
6 class CallStackView : Window
7 {
8    visible = false;
9    borderStyle = sizableDeep;
10    background = { 224, 224, 224 };
11    hasClose = true;
12    mergeMenus = false;
13    text = $"Call Stack";
14    menu = Menu { };
15    anchor = Anchor { left = 0, right = 0.2, top = 0 };
16    size.h = 200;
17
18    virtual void OnSelectFrame(int frameIndex);
19    virtual void OnToggleBreakpoint();
20
21    bool moved, logging;
22    FindDialog findDialog { master = this, editBox = editBox, isModal = true, autoCreate = false, text = $"Find" };
23
24    EditBox editBox
25    {
26       parent = this, freeCaret = true, autoEmpty = true, multiLine = true, readOnly = true;
27       hasVertScroll = true, hasHorzScroll = true, borderStyle = none;
28       anchor = Anchor { left = 20, top = 0, right = 0, bottom = 0 };
29       background = viewsBackground;
30       foreground = viewsText;
31       selectionColor = selectionColor, selectionText = selectionText;
32
33       bool NotifyDoubleClick(EditBox editBox, EditLine line, Modifiers mods)
34       {
35          int frameIndex = -1;
36          if(strcmp(editBox.line.text, "..."))
37             frameIndex = atoi(editBox.line.text);
38          OnSelectFrame(frameIndex);
39          return false;
40       }
41
42       bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
43       {
44          if(key == enter || key == keyPadEnter)
45          {
46             int frameIndex = -1;
47             if(strcmp(editBox.line.text, "..."))
48                frameIndex = atoi(editBox.line.text);
49             OnSelectFrame(frameIndex);
50             return false;
51          }
52          if(key == f9)
53          {
54             OnToggleBreakpoint();
55             return false;
56          }
57          return true;
58       }
59
60       void OnVScroll(ScrollBarAction action, int position, Key key)
61       {
62          if(anchor.left.distance)
63          {
64             Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
65             parent.Update(box);
66          }
67          EditBox::OnVScroll(action, position, key);
68       }
69    };
70
71    Menu editMenu { menu, $"Edit", e };
72    MenuItem item;
73
74    MenuItem copyItem
75    {
76       editMenu, $"Copy", c, ctrlC;
77       bool NotifySelect(MenuItem selection, Modifiers mods)
78       {
79          editBox.Copy();
80          return true;
81       }
82    };
83    MenuDivider { editMenu };
84    MenuItem { editMenu, $"Find Previous", e, Key { f3, shift = true }, NotifySelect = MenuEditFind, id = 0 };
85    MenuItem { editMenu, $"Find Next", n, f3, NotifySelect = MenuEditFind, id = 1 };
86    MenuItem { editMenu, $"Find", f, ctrlF, NotifySelect = MenuEditFind, id = 2 };
87
88    bool MenuEditFind(MenuItem selection, Modifiers mods)
89    {
90       int64 id = selection.id;
91       const char * searchString = findDialog.searchString;
92       if(id != 2 && searchString[0])
93       {
94          editBox.Find(searchString, findDialog.wholeWord, findDialog.matchCase, id != 0);
95          return true;
96       }
97       findDialog.Create();
98       return true;
99    }
100
101    void Logf(const char * format, ...)
102    {
103       char string[MAX_F_STRING*10];
104       va_list args;
105       va_start(args, format);
106       vsnprintf(string, sizeof(string), format, args);
107       string[sizeof(string)-1] = 0;
108       va_end(args);
109
110       Log(string);
111    }
112
113    void LogRaw(const char * entry)
114    {
115       Log(entry);
116    }
117    void Log(const char * string)
118    {
119       EditLine line1;
120       EditLine line2;
121       int x1, y1, x2, y2;
122       Point scroll;
123       logging = true;
124       if(moved)
125       {
126          editBox.GetSelPos(&line1, &y1, &x1, &line2, &y2, &x2, false);
127          scroll = editBox.scroll;
128       }
129       editBox.End();
130       editBox.PutS(string);
131       editBox.Update(null);
132       if(moved)
133       {
134          editBox.scroll = scroll;
135          editBox.SetSelPos(line1, y1, x1, line2, y2, x2);
136       }
137       logging = false;
138    }
139    void Clear()
140    {
141       editBox.Clear();
142       moved = false;
143    }
144    void Home()
145    {
146       editBox.Home();
147    }
148    void Show()
149    {
150       visible = true;
151       ide.RepositionWindows(false);
152       Activate();
153    }
154 }