cleaned all trailing white space from source files.
[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
14 public:
15    property EditBox editBox { set { editBox = value; } };
16    property char * searchString { set { findWhat.contents = value; } get { return findWhat.contents; } };
17    property bool wholeWord { set { wholeWord.checked = value; } get { return wholeWord.checked; } };
18    property bool matchCase { set { matchCase.checked = value; } get { return matchCase.checked; } };
19    property bool searchUp { set { (value ? searchUp : searchDown).checked = true; } get { return searchUp.checked; } };
20
21 private:
22    EditBox editBox;
23
24    Button wholeWord
25    {
26       this, isCheckbox = true, text = $"Whole word only", position = { 10, 40 }, hotKey = altW
27    };
28
29    Button matchCase
30    {
31       this, isCheckbox = true, text = $"Match case", position = { 10, 60 }, hotKey = altC
32    };
33
34    Button searchUp
35    {
36       this, isRadio = true, text = $"Up", position = { 220, 50 }, hotKey = altU
37    };
38
39    Button searchDown
40    {
41       this, isRadio = true, text = $"Down", position = { 220, 70 }, hotKey = altD, checked = true;
42    };
43
44    Label directionLabel
45    {
46       this, text = $"Direction", position = { 220, 35 }
47    };
48
49    Button findNext
50    {
51       this, keyRepeat = true, isDefault = true, text = $"Find Next", anchor = { right = 10, top = 10 }, size = { 80 }, hotKey = altF;
52
53       bool NotifyClicked(Button control, int x, int y, Modifiers mods)
54       {
55          char * searchString = findWhat.contents;
56          bool searchUp = this.searchUp.checked;
57          bool wholeWord = this.wholeWord.checked;
58          bool matchCase = this.matchCase.checked;
59
60          if(!editBox || !editBox.Find(searchString, wholeWord, matchCase, !searchUp))
61             MessageBox { type = ok, master = this, text = $"Find", contents = $"Search string not found." }.Modal();
62          else
63          {
64             findWhat.Activate();
65             Destroy(0);
66          }
67          return true;
68       }
69    };
70
71    Button cancel
72    {
73       this, text = $"Cancel", anchor = Anchor { right = 10, top = 45 }, size = { 80 }, hotKey = escape;
74
75       bool NotifyClicked(Button control, int x, int y, Modifiers mods)
76       {
77          findWhat.Activate();
78          Destroy(0);
79          return true;
80       }
81    };
82
83    EditBox findWhat
84    {
85       this, text = $"Find what:", anchor = { left = 100, right = 100, top = 10 }, size.h = 20, hotKey = altN;
86    };
87
88    Label findWhatLabel { this, position = { 10, 10 }, labeledWindow = findWhat };
89
90    bool OnKeyHit(Key key, unichar ch)
91    {
92       if(ch && !key.alt && !key.ctrl && !key.shift && (matchCase.active || wholeWord.active))
93       {
94          findWhat.Activate();
95          return findWhat.OnKeyHit(key, ch);
96       }
97       return true;
98    }
99 }