ecere/gui/dialogs/FindDialog: Fixed autoCreate to default to false
[sdk] / ecere / src / gui / dialogs / FindDialog.ec
1 namespace gui::dialogs;
2
3 import "Window"
4
5 public class FindDialog : Window
6 {
7    text = $"Find";
8    hasClose = true;
9    tabCycle = true;
10    borderStyle = fixed;
11    background = formColor;
12    minClientSize = { 400, 112 };
13    autoCreate = false;
14
15 public:
16    property EditBox editBox { set { editBox = value; } };
17    property const char * searchString { set { findWhat.contents = value; } get { return findWhat.contents; } };
18    property bool wholeWord { set { wholeWord.checked = value; } get { return wholeWord.checked; } };
19    property bool matchCase { set { matchCase.checked = value; } get { return matchCase.checked; } };
20    property bool searchUp { set { (value ? searchUp : searchDown).checked = true; } get { return searchUp.checked; } };
21
22 private:
23    EditBox editBox;
24
25    Button wholeWord
26    {
27       this, isCheckbox = true, text = $"Whole word only", position = { 10, 40 }, hotKey = altW
28    };
29
30    Button matchCase
31    {
32       this, isCheckbox = true, text = $"Match case", position = { 10, 60 }, hotKey = altC
33    };
34
35    Button searchUp
36    {
37       this, isRadio = true, text = $"Up", position = { 220, 50 }, hotKey = altU
38    };
39
40    Button searchDown
41    {
42       this, isRadio = true, text = $"Down", position = { 220, 70 }, hotKey = altD, checked = true;
43    };
44
45    Label directionLabel
46    {
47       this, text = $"Direction", position = { 220, 35 }
48    };
49
50    Button findNext
51    {
52       this, keyRepeat = true, isDefault = true, text = $"Find Next", anchor = { right = 10, top = 10 }, size = { 80 }, hotKey = altF;
53
54       bool NotifyClicked(Button control, int x, int y, Modifiers mods)
55       {
56          const char * searchString = findWhat.contents;
57          bool searchUp = this.searchUp.checked;
58          bool wholeWord = this.wholeWord.checked;
59          bool matchCase = this.matchCase.checked;
60
61          if(!editBox || !editBox.Find(searchString, wholeWord, matchCase, !searchUp))
62             MessageBox { type = ok, master = this, text = $"Find", contents = $"Search string not found." }.Modal();
63          else
64          {
65             findWhat.Activate();
66             Destroy(0);
67          }
68          return true;
69       }
70    };
71
72    Button cancel
73    {
74       this, text = $"Cancel", anchor = Anchor { right = 10, top = 45 }, size = { 80 }, hotKey = escape;
75
76       bool NotifyClicked(Button control, int x, int y, Modifiers mods)
77       {
78          findWhat.Activate();
79          Destroy(0);
80          return true;
81       }
82    };
83
84    EditBox findWhat
85    {
86       this, text = $"Find what:", anchor = { left = 100, right = 100, top = 10 }, size.h = 20, hotKey = altN;
87    };
88
89    Label findWhatLabel { this, position = { 10, 10 }, labeledWindow = findWhat };
90
91    bool OnKeyHit(Key key, unichar ch)
92    {
93       if(ch && !key.alt && !key.ctrl && !key.shift && (matchCase.active || wholeWord.active))
94       {
95          findWhat.Activate();
96          return findWhat.OnKeyHit(key, ch);
97       }
98       return true;
99    }
100 }