old explorer: native decorations
[ede] / explorer / src / Finder.ec
1 public import "ecere"
2
3 import "ExplorerTree"
4 import "Panels"
5 import "DeleteBox"
6
7 class ExplorerSearch : Window
8 {
9    hasHorzScroll = false;
10    hasVertScroll = true;
11
12    background = activeBorder;
13
14    //menu = Menu { };
15
16    ExplorerSearchViewTree view;
17
18    SearchThread searchThread { searchPanel = this };
19
20 public:
21
22    void OptTree(bool on)
23    {
24       view.results.Clear();
25       view.results.ClearFields();
26       view.results.AddField(DataField { editable = true });
27       if(on)
28          view.results.AddField(view.resultsFieldPath);
29    }
30
31    void SearchStart()
32    {
33       char text[2048];
34       
35       searchThread.active = true;
36
37       searchThread.optionSubdirs = options.subdirs.checked;
38       searchThread.optionTree = (options.subdirs.checked && options.tree.checked);
39       searchThread.optionBrowser = (options.subdirs.checked && options.browser.checked);
40       searchThread.optionNameMatchCase = findName.optionMatchCase.checked;
41       searchThread.optionNameMatchWord = findName.optionMatchWord.checked;
42       searchThread.optionContentMatchCase = findTextContent.optionMatchCase.checked;
43       searchThread.optionContentMatchWord = findTextContent.optionMatchWord.checked;
44
45       strcpy(searchThread.location, location.GetText());
46       strcpy(searchThread.nameSearch, findName.GetText());
47       strcpy(searchThread.contentSearch, findTextContent.GetText());
48       
49       actions.startStop.text = "Stop Search";
50       actions.clear.disabled = false;
51       view.results.Clear();
52       view.results.hasHeader = !searchThread.optionTree;
53       view.results.treeBranches = searchThread.optionTree;
54       view.browser.Clear();
55       ToggleBrowserDisplay(searchThread.optionBrowser);
56
57       view.browser.text = "Browser";
58       sprintf(text, "Search Results (Searching %s)", location.GetText());
59       view.results.text = text;
60       
61       searchThread.Create();
62    }
63
64    bool SearchStop()
65    {
66       if(searchThread.active)
67       {
68          searchThread.terminate = true;
69          app.Unlock();
70             searchThread.Wait();
71          app.Lock();
72          return true;
73       }
74       return false;
75    }
76
77    void SearchUpdateLabel(char * path)
78    {
79       char text[2048];
80       sprintf(text, "Search Results (Searching %s)", path);
81       view.results.text = text;
82    }
83
84    void AddResult(ExplorerFileBranch branch, ExplorerFileBranch addTo)
85    {
86       AddBranch(branch, true, false, addTo, view.results);
87    }
88
89    void SortResults()
90    {
91       //view.results.Sort(resultsNameField, 1);
92    }
93
94    void AddBrowse(ExplorerFileBranch branch, ExplorerFileBranch addTo)
95    {
96       AddBranch(branch, true, false, addTo, view.browser);
97    }
98
99    void SortBrowser()
100    {
101       //view.browser.Sort(browserNameField, 1);
102    }
103
104    void SearchTerminate()
105    {
106       char text[1024];
107       
108       if(searchThread.terminate)
109          sprintf(text, "Search Results (%d item(s) found), Search was aborted.", searchThread.matchCount);
110       else
111          sprintf(text, "Search Results (%d item(s) found), Search completed successfuly.", searchThread.matchCount);
112       view.results.text = text;
113       sprintf(text, "Browser (%d item(s) searched)", searchThread.count);
114       view.browser.text = text;
115          
116       actions.startStop.text = "Start Search";
117    }
118
119    void ListDirectory(DataRow addTo, char * path)
120    {
121       FileListing listing { path };
122       while(listing.Find())
123       {
124          DataRow row = addTo.AddString(listing.name);
125          row.collapsed = true;
126          if(listing.stats.attribs.isDirectory)
127             ListDirectory(row, listing.path);
128       }
129    }
130
131    void ToggleBrowserDisplay(bool visible)
132    {
133       //view.labelBrowser.visible = visible;
134       view.browser.visible = visible;
135       if(visible)
136          view.results.anchor.bottom = 304;
137       else
138          view.results.anchor.bottom = 4;
139    }
140
141    PanelFileName findName
142    {
143       this, master;
144       anchor = Anchor { left = 4, top = 0, right = 4 };
145    };
146    /*PanelFileSize findSize
147    {
148       this, master;
149       anchor = Anchor { left = 4, top = (int)(findName.position.y + findName.size.h + 4), right = 4 };
150    };*/
151    PanelFileTextContent findTextContent
152    {
153       this, master;
154       anchor = Anchor { left = 4, top = (int)(findName.position.y + findName.size.h + 4), right = 4 };
155    };
156    PanelLocation location
157    {
158       this, master;
159       anchor = Anchor { left = 4, top = (int)(findTextContent.position.y + findTextContent.size.h + 4), right = 4 };
160 #ifdef _DEBUG
161       editBox.contents = "D:\\Projects\\Ecere";
162 #endif
163    };
164    PanelOptions options
165    {
166       this, master;
167       anchor = Anchor { left = 4, top = (int)(location.position.y + location.size.h + 4), right = 4 };
168    };
169    PanelActions actions
170    {
171       this, master;
172       anchor = Anchor { left = 4, top = (int)(options.position.y + options.size.h + 4), right = 4 };
173    };
174
175    ExplorerSearch()
176    {
177    }
178
179    void OnDestroy()
180    {
181       SearchStop();
182    }
183
184 }
185
186 class ExplorerSearchView : ExplorerView
187 {
188    virtual void AddItem(const FileStats stats, const char * name, bool match);
189 }
190
191 class ExplorerSearchViewTree : ExplorerSearchView
192 {
193    
194    DataField resultsFieldPath { "char *" };
195
196    ListBox results
197    {
198       this, master;
199
200       borderStyle = none; // deep
201       hasHorzScroll = true;
202       hasVertScroll = true;
203       fullRowSelect = false;
204       treeBranches = true;
205       collapseControl = true;
206       rootCollapseButton = true;
207       multiSelect = true;
208
209       size = Size { 600, 200 };
210       //anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
211       //anchor = Anchor { left = 8, top = 24, right = 4, bottom = 304 };
212       anchor = Anchor { left = 0, top = 0, right = 0, bottom = 304 };
213       text = "Search Results", hotKey = Key { r, alt = true };
214
215       /*hasHeader = true, moveFields = true, resizable = true, sortable = true;*/
216
217       NotifyKeyHit = CommonNotifyKeyHit;
218       NotifyDoubleClick = Lists_NotifyDoubleClick;
219    };
220    DataField resultsNameField { header = "Name", dataType = "ExplorerFileBranch", width = 304, userData = this };
221    ListBox browser
222    {
223       this, master;
224
225       borderStyle = none; // deep
226       hasHorzScroll = true;
227       hasVertScroll = true;
228       fullRowSelect = false;
229       treeBranches = true;
230       collapseControl = true;
231       rootCollapseButton = true;
232       multiSelect = true;
233
234       size = Size { 624, 268 };
235       anchor = Anchor { left = 8, right = 4, bottom = 4 };
236       text = "Browser", hotKey = Key { e, alt = true };
237
238       /*hasHeader = true, moveFields = true, resizable = true, sortable = true;*/
239
240       NotifyKeyHit = CommonNotifyKeyHit;
241       NotifyDoubleClick = Lists_NotifyDoubleClick;
242    };
243    DataField browserNameField { header = "Name", dataType = "ExplorerFileBranch", width = 304, userData = this }; // editable = true
244
245    bool CommonNotifyKeyHit(ListBox listBox, DataRow row, Key key, unichar ch)
246    {
247       if((SmartKey)key == del)
248       {
249          //DeleteBox { this, source = listBox }.Modal();
250          /*
251          if(MessageBox { finderWnd, text = "text", contents = "contents", type = yesNo }.Modal() == yes)
252          {
253             OldList selection;
254             Link item;
255             
256             listBox.GetMultiSelection(selection);
257             
258             for(item = selection.first; item; item = item.next)
259             {
260                char path[MAX_LOCATION];
261                DataRow row = item.data;
262                ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
263                branch.GetPath(path);
264                if(FileExists(path))
265                   DeleteFile(path);
266                if(!FileExists(path))
267                   DeleteBranch(branch, listBox);
268             }
269             selection.Free(null);
270          }
271          */
272       }
273       return true;
274    }
275
276    bool Lists_NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
277    {  
278       if(listBox.currentRow)
279       {
280          char path[MAX_LOCATION];
281          ExplorerFileBranch branch = (ExplorerFileBranch)listBox.currentRow.tag;
282          //if(listBox != view.results || searchThread.tree)
283          //   GetRowPath(listBox.currentRow, path);
284          //else
285          //   strcpy(path, *(char **)listBox.currentRow.GetData(resultsFieldPath));
286          branch.GetPath(path);
287          ShellOpen(path);
288          return false;
289       }
290       return true;
291    }
292
293    ExplorerSearchViewTree()
294    {
295       results.AddField(resultsNameField);
296       browser.AddField(browserNameField);
297    }
298
299 }
300