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