8f0e3c36534210d95d8c04f6ee7d7d8564b005f9
[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       /*
30       background = colorScheme.viewsBackground;
31       foreground = colorScheme.viewsText;
32       selectionColor = colorScheme.selectionColor;
33       selectionText = colorScheme.selectionText;
34       */
35
36       bool NotifyDoubleClick(EditBox editBox, EditLine line, Modifiers mods)
37       {
38          int frameIndex = -1;
39          if(strcmp(editBox.line.text, "..."))
40             frameIndex = atoi(editBox.line.text);
41          OnSelectFrame(frameIndex);
42          return false;
43       }
44
45       bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
46       {
47          if(key == enter || key == keyPadEnter)
48          {
49             int frameIndex = -1;
50             if(strcmp(editBox.line.text, "..."))
51                frameIndex = atoi(editBox.line.text);
52             OnSelectFrame(frameIndex);
53             return false;
54          }
55          if(key == f9)
56          {
57             OnToggleBreakpoint();
58             return false;
59          }
60          return true;
61       }
62
63       void OnVScroll(ScrollBarAction action, int position, Key key)
64       {
65          if(anchor.left.distance)
66          {
67             Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
68             parent.Update(box);
69          }
70          EditBox::OnVScroll(action, position, key);
71       }
72    };
73
74    Menu editMenu { menu, $"Edit", e };
75    MenuItem item;
76
77    MenuItem copyItem
78    {
79       editMenu, $"Copy", c, ctrlC;
80       bool NotifySelect(MenuItem selection, Modifiers mods)
81       {
82          editBox.Copy();
83          return true;
84       }
85    };
86    MenuDivider { editMenu };
87    MenuItem { editMenu, $"Find Previous", e, Key { f3, shift = true }, NotifySelect = MenuEditFind, id = 0 };
88    MenuItem { editMenu, $"Find Next", n, f3, NotifySelect = MenuEditFind, id = 1 };
89    MenuItem { editMenu, $"Find", f, ctrlF, NotifySelect = MenuEditFind, id = 2 };
90
91    bool MenuEditFind(MenuItem selection, Modifiers mods)
92    {
93       int64 id = selection.id;
94       const char * searchString = findDialog.searchString;
95       if(id != 2 && searchString[0])
96       {
97          editBox.Find(searchString, findDialog.wholeWord, findDialog.matchCase, id != 0);
98          return true;
99       }
100       findDialog.Create();
101       return true;
102    }
103
104    void Logf(const char * format, ...)
105    {
106       char string[MAX_F_STRING*10];
107       va_list args;
108       va_start(args, format);
109       vsnprintf(string, sizeof(string), format, args);
110       string[sizeof(string)-1] = 0;
111       va_end(args);
112
113       Log(string);
114    }
115
116    void LogRaw(const char * entry)
117    {
118       Log(entry);
119    }
120    void Log(const char * string)
121    {
122       EditLine line1;
123       EditLine line2;
124       int x1, y1, x2, y2;
125       Point scroll;
126       logging = true;
127       if(moved)
128       {
129          editBox.GetSelPos(&line1, &y1, &x1, &line2, &y2, &x2, false);
130          scroll = editBox.scroll;
131       }
132       editBox.End();
133       editBox.PutS(string);
134       editBox.Update(null);
135       if(moved)
136       {
137          editBox.scroll = scroll;
138          editBox.SetSelPos(line1, y1, x1, line2, y2, x2);
139       }
140       logging = false;
141    }
142    void Clear()
143    {
144       editBox.Clear();
145       moved = false;
146    }
147    void Home()
148    {
149       editBox.Home();
150    }
151    void Show()
152    {
153       visible = true;
154       ide.RepositionWindows(false);
155       Activate();
156    }
157 }