old explorer: native decorations
[ede] / explorer / src / Panels.ec
1 import "Explorer"
2 //import "ecere"
3 //import "Finder"
4
5 class Panel : Label
6 {
7    //background = activeBorder;
8    size = { 200, 40 };
9    isGroupBox = true;
10    //background = activeBorder;
11
12    bool OnMoving(int * x, int * y, int w, int h)
13    {
14       //if(((ExplorerWindow)master).userMode)
15       //   return false;
16       return true; 
17    }
18 }
19
20 class PanelText : Panel
21 {
22    // IDEA: Would it be totally unreasonable for a group box to use client size
23    //       to set the actual size considering the size of the border?
24    //       Also, to have anchors be relative to the client size?
25    clientSize = { 200, 40 };
26    size = { 200, 64 };
27    //background = activeBorder;
28    
29    EditBox editBox
30    {
31       this;
32       //borderStyle = none;
33       size = { 160, 20 };
34       anchor = { left = 8, top = 16, right = 8 };
35    };
36    
37    char * GetText()
38    {
39       return editBox.contents;
40    }
41 }
42
43 class PanelTextMatch : PanelText
44 {
45    clientSize = { 200, 40 };
46    size = { 200, 64 };
47
48    Button optionMatchCase
49    {
50       this;
51       //toggle = true, inactive = true;
52       isCheckbox = true;
53       text = "Match Case", hotKey = Key { c, alt = true };
54       //size = { 40, 18 };
55       //anchor = { left = 4, top = 40, right = 0.508f };
56       anchor = { top = 38, right = 8 };
57    };
58    Button optionMatchWord
59    {
60       this;
61       //toggle = true, inactive = true;
62       isCheckbox = true;
63       text = "Match Whole Word", hotKey = Key { w, alt = true };
64       //size = { 40, 18 };
65       position = Point { y = 62 };
66       //anchor = { left = 0.508f, top = 40, right = 4 };
67       anchor = { top = 38, right = 8 };
68    };
69
70    bool OnPostCreate()
71    {
72       optionMatchCase.anchor.right = (int)optionMatchWord.size.w + 8 + 2;
73       return true;
74    }
75
76    /*void OnResize(int width, int height)
77    {
78       optionMatchCase.anchor.right = (int)optionMatchWord.size.w + 8 + 2;
79    }*/
80 }
81
82 class PanelFileName : PanelTextMatch
83 {
84    clientSize = { 200, 40 };
85    size = { 200, 64 };
86    text = "File Name";
87    hotKey = Key { n, alt = true };
88
89 #ifdef _DEBUG
90    editBox.contents = "Ecere";
91 #endif
92 }
93
94 class PanelFileSize : Panel
95 {
96    clientSize = { 200, 40 };
97    size = { 200, 64 };
98
99    text = "File Size";
100    hotKey = Key { s, alt = true };
101    
102    uint compare;
103
104    EditBox editBox 
105    {      
106       this;
107       //borderStyle = none;
108       contents = "1024";
109       size = { 102, 18 };
110       anchor = { left = 8, top = 16, right = 130 };
111
112       bool NotifyModified(EditBox editBox)
113       {
114          UpdateCompare();
115          return true;
116       }
117    };
118    Button optionGB
119    {
120       this;
121       toggle = true, inactive = true;
122       text = "GB";
123       size = { 30, 18 };
124       anchor = { top = 16, right = 98 };
125       NotifyClicked = optionScale_NotifyClicked;
126    };
127    Button optionMB
128    {
129       this;
130       toggle = true, inactive = true;
131       text = "MB";
132       size = { 30, 18 };
133       anchor = { top = 16, right = 66 };
134       NotifyClicked = optionScale_NotifyClicked;
135    };
136    Button optionKB
137    {
138       this;
139       toggle = true, checked = true, inactive = true;
140       text = "KB";
141       size = { 30, 18 };
142       anchor = { top = 16, right = 34 };
143       NotifyClicked = optionScale_NotifyClicked;
144    };
145    Button optionB
146    {
147       this;
148       toggle = true, inactive = true;
149       text = "B";
150       size = { 30, 18 };
151       anchor = { top = 16, right = 4 };
152       NotifyClicked = optionScale_NotifyClicked;
153    };
154
155    Button optionSmaller
156    {
157       this;
158       toggle = true, inactive = true;
159       text = "Smaller";
160       size = { 74, 18 };
161       anchor = { left = 4, top = 41, right = 0.67f };
162       NotifyClicked = optionCompare_NotifyClicked
163    };
164    Button optionEqual
165    {
166       this;
167       toggle = true, inactive = true;
168       text = "Equal";
169       size = { 74, 18 };
170       anchor = { left = 0.34f, top = 41, right = 0.34f };
171       NotifyClicked = optionCompare_NotifyClicked;
172    };
173    Button optionGreater
174    {
175       this;
176       toggle = true, checked = true, inactive = true;
177       text = "Greater";
178       size = { 74, 18 };
179       anchor = { left = 0.67f, top = 41, right = 4 };
180       NotifyClicked = optionCompare_NotifyClicked;
181    };
182
183    bool optionScale_NotifyClicked(Button button, int x, int y, Modifiers mods)
184    {
185       optionGB.checked = (button == optionGB);
186       optionMB.checked = (button == optionMB);
187       optionKB.checked = (button == optionKB);
188       optionB.checked = (button == optionB);
189       UpdateCompare();
190       return true;
191    }
192
193    bool optionCompare_NotifyClicked(Button button, int x, int y, Modifiers mods)
194    {
195       optionSmaller.checked = (button == optionSmaller);
196       optionEqual.checked = (button == optionEqual);
197       optionGreater.checked = (button == optionGreater);
198       return true;
199    }
200
201    bool Match(uint size)
202    {
203       if(optionSmaller.checked)
204          return size < compare;
205       else if(optionEqual.checked)
206          return size = compare;
207       else if(optionGreater.checked)
208          return size > compare;
209       else
210          return false;
211    }
212
213    void UpdateCompare()
214    {
215       if(optionGB.checked)
216          compare = atoi(editBox.contents) * 1024 * 1024 * 1024;
217       else if(optionMB.checked)
218          compare = atoi(editBox.contents) * 1024 * 1024;
219       else if(optionKB.checked)
220          compare = atoi(editBox.contents) * 1024;
221       else if(optionB.checked)
222          compare = atoi(editBox.contents);
223    }
224
225 }
226
227 class PanelFileTextContent : PanelTextMatch
228 {
229    clientSize = { 200, 40 };
230    size = { 200, 64 };
231    text = "Text Content";
232    hotKey = Key { x, alt = true };
233 }
234
235 class PanelLocation : Panel
236 {
237    clientSize = { 200, 40 };
238    size = { 200, 44 };
239    text = "Location";
240    hotKey = Key { l, alt = true };
241
242    FileDialog fileDialog
243    {
244       master, master;
245       type = selectDir;
246       text = "Select Search Location...";
247    };
248
249    EditBox editBox
250    {
251       this;
252       //borderStyle = none;
253       contents = "/";
254       size = { 160, 20 };
255       anchor = { left = 8, top = 16, right = 2 + 24 + 8 };
256    };
257    
258    ToolButton browse
259    {
260       this;
261       anchor = { top = 14, right = 8 };
262       toolId = ExplorerToolId::browse;
263       
264       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
265       {
266          fileDialog.currentDirectory = editBox.contents;
267          if(fileDialog.Modal() == ok)
268             editBox.contents = fileDialog.filePath;
269          return true;
270       }
271    };
272
273    /*Button buttonBrowse
274    {
275       this;
276       text = "Browse", hotKey = Key { b, alt = true };
277       size = { 160, 29 };
278       anchor = { left = 8, top = 41, right = 8 };
279
280    };*/
281
282    char * GetText()
283    {
284       return editBox.contents;
285    }
286 }
287
288 class PanelOptions : Panel 
289 {
290    clientSize = { 200, 60 };
291    size = { 200, 80 };
292    text = "Options";
293    hotKey = Key { o, alt = true };
294    
295    Button subdirs
296    {
297       this;
298       toggle = true, checked = true;
299       text = "Search Sub Directories", hotKey = Key { d, alt = true };
300       size = { 160, 18 };
301       anchor = { left = 8, top = 16, right = 8 };
302
303       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
304       {
305          if(button.checked)
306          {
307             tree.disabled = false;
308             browser.disabled = false;
309          }
310          else
311          {
312             // I need a way to show this unchecked while keeping it original checked value
313             tree.disabled = true;
314             browser.disabled = true;
315          }
316          return true;
317       }
318    };
319    Button tree
320    {
321       this;
322       toggle = true, checked = true, inactive = true;
323       text = "Display Results With Tree", hotKey = Key { t, alt = true };
324       size = { 160, 18 };
325       anchor = { left = 8, top = 40, right = 8 };
326    
327       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
328       {
329          ExplorerSearch search = (ExplorerSearch)parent;
330          search.OptTree(button.checked);
331          return true;
332       }
333    };
334    Button browser
335    {
336       this;
337       toggle = true, checked = true, inactive = true;
338       text = "Show Browser", hotKey = Key { h, alt = true };
339       size = { 160, 18 };
340       anchor = { left = 8, top = 60, right = 8 };
341    };
342 }
343
344 class PanelActions : Panel 
345 {
346    clientSize = { 200, 38 };
347    size = { 200, 48 };
348    text = "Actions";
349    hotKey = Key { o, alt = true };
350    
351    Button startStop
352    {
353       this;
354       isDefault = true;
355       text = "Start Search", hotKey = Key { s, alt = true };
356       size = { 80, 26 };
357       anchor = { top = 16, right = 92 };
358
359       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
360       {
361          ExplorerSearch search = (ExplorerSearch)parent;
362          //--//if(!finderWnd.SearchStop())
363             search.SearchStart();
364          return true;
365       }
366    };
367    Button clear
368    {
369       this;
370       disabled = true;
371       text = "Clear Results", hotKey = Key { c, alt = true };
372       size = { 80, 26 };
373       anchor = { top = 16, right = 8 };
374
375       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
376       {
377          ExplorerSearch search = (ExplorerSearch)parent;
378          search.SearchStop();
379          search.view.results.Clear();
380          search.view.browser.Clear();
381          button.disabled = true;
382          return true;
383       }
384    };
385 }
386