public import "ecere" import "ExplorerTree" import "Panels" import "DeleteBox" class ExplorerSearch : Window { hasHorzScroll = false; hasVertScroll = true; background = activeBorder; //menu = Menu { }; ExplorerSearchViewTree view; SearchThread searchThread { searchPanel = this }; public: void OptTree(bool on) { view.results.Clear(); view.results.ClearFields(); view.results.AddField(DataField { editable = true }); if(on) view.results.AddField(view.resultsFieldPath); } void SearchStart() { char text[2048]; searchThread.active = true; searchThread.optionSubdirs = options.subdirs.checked; searchThread.optionTree = (options.subdirs.checked && options.tree.checked); searchThread.optionBrowser = (options.subdirs.checked && options.browser.checked); searchThread.optionNameMatchCase = findName.optionMatchCase.checked; searchThread.optionNameMatchWord = findName.optionMatchWord.checked; searchThread.optionContentMatchCase = findTextContent.optionMatchCase.checked; searchThread.optionContentMatchWord = findTextContent.optionMatchWord.checked; strcpy(searchThread.location, location.GetText()); strcpy(searchThread.nameSearch, findName.GetText()); strcpy(searchThread.contentSearch, findTextContent.GetText()); actions.startStop.text = "Stop Search"; actions.clear.disabled = false; view.results.Clear(); view.results.hasHeader = !searchThread.optionTree; view.results.treeBranches = searchThread.optionTree; view.browser.Clear(); ToggleBrowserDisplay(searchThread.optionBrowser); view.browser.text = "Browser"; sprintf(text, "Search Results (Searching %s)", location.GetText()); view.results.text = text; searchThread.Create(); } bool SearchStop() { if(searchThread.active) { searchThread.terminate = true; app.Unlock(); searchThread.Wait(); app.Lock(); return true; } return false; } void SearchUpdateLabel(char * path) { char text[2048]; sprintf(text, "Search Results (Searching %s)", path); view.results.text = text; } void AddResult(ExplorerFileBranch branch, ExplorerFileBranch addTo) { AddBranch(branch, true, false, addTo, view.results); } void SortResults() { //view.results.Sort(resultsNameField, 1); } void AddBrowse(ExplorerFileBranch branch, ExplorerFileBranch addTo) { AddBranch(branch, true, false, addTo, view.browser); } void SortBrowser() { //view.browser.Sort(browserNameField, 1); } void SearchTerminate() { char text[1024]; if(searchThread.terminate) sprintf(text, "Search Results (%d item(s) found), Search was aborted.", searchThread.matchCount); else sprintf(text, "Search Results (%d item(s) found), Search completed successfuly.", searchThread.matchCount); view.results.text = text; sprintf(text, "Browser (%d item(s) searched)", searchThread.count); view.browser.text = text; actions.startStop.text = "Start Search"; } void ListDirectory(DataRow addTo, char * path) { FileListing listing { path }; while(listing.Find()) { DataRow row = addTo.AddString(listing.name); row.collapsed = true; if(listing.stats.attribs.isDirectory) ListDirectory(row, listing.path); } } void ToggleBrowserDisplay(bool visible) { //view.labelBrowser.visible = visible; view.browser.visible = visible; if(visible) view.results.anchor.bottom = 304; else view.results.anchor.bottom = 4; } PanelFileName findName { this, master; anchor = Anchor { left = 4, top = 0, right = 4 }; }; /*PanelFileSize findSize { this, master; anchor = Anchor { left = 4, top = (int)(findName.position.y + findName.size.h + 4), right = 4 }; };*/ PanelFileTextContent findTextContent { this, master; anchor = Anchor { left = 4, top = (int)(findName.position.y + findName.size.h + 4), right = 4 }; }; PanelLocation location { this, master; anchor = Anchor { left = 4, top = (int)(findTextContent.position.y + findTextContent.size.h + 4), right = 4 }; #ifdef _DEBUG editBox.contents = "D:\\Projects\\Ecere"; #endif }; PanelOptions options { this, master; anchor = Anchor { left = 4, top = (int)(location.position.y + location.size.h + 4), right = 4 }; }; PanelActions actions { this, master; anchor = Anchor { left = 4, top = (int)(options.position.y + options.size.h + 4), right = 4 }; }; ExplorerSearch() { } void OnDestroy() { SearchStop(); } } class ExplorerSearchView : ExplorerView { virtual void AddItem(const FileStats stats, const char * name, bool match); } class ExplorerSearchViewTree : ExplorerSearchView { DataField resultsFieldPath { "char *" }; ListBox results { this, master; borderStyle = none; // deep hasHorzScroll = true; hasVertScroll = true; fullRowSelect = false; treeBranches = true; collapseControl = true; rootCollapseButton = true; multiSelect = true; size = Size { 600, 200 }; //anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 }; //anchor = Anchor { left = 8, top = 24, right = 4, bottom = 304 }; anchor = Anchor { left = 0, top = 0, right = 0, bottom = 304 }; text = "Search Results", hotKey = Key { r, alt = true }; /*hasHeader = true, moveFields = true, resizable = true, sortable = true;*/ NotifyKeyHit = CommonNotifyKeyHit; NotifyDoubleClick = Lists_NotifyDoubleClick; }; DataField resultsNameField { header = "Name", dataType = "ExplorerFileBranch", width = 304, userData = this }; ListBox browser { this, master; borderStyle = none; // deep hasHorzScroll = true; hasVertScroll = true; fullRowSelect = false; treeBranches = true; collapseControl = true; rootCollapseButton = true; multiSelect = true; size = Size { 624, 268 }; anchor = Anchor { left = 8, right = 4, bottom = 4 }; text = "Browser", hotKey = Key { e, alt = true }; /*hasHeader = true, moveFields = true, resizable = true, sortable = true;*/ NotifyKeyHit = CommonNotifyKeyHit; NotifyDoubleClick = Lists_NotifyDoubleClick; }; DataField browserNameField { header = "Name", dataType = "ExplorerFileBranch", width = 304, userData = this }; // editable = true bool CommonNotifyKeyHit(ListBox listBox, DataRow row, Key key, unichar ch) { if((SmartKey)key == del) { //DeleteBox { this, source = listBox }.Modal(); /* if(MessageBox { finderWnd, text = "text", contents = "contents", type = yesNo }.Modal() == yes) { OldList selection; Link item; listBox.GetMultiSelection(selection); for(item = selection.first; item; item = item.next) { char path[MAX_LOCATION]; DataRow row = item.data; ExplorerFileBranch branch = (ExplorerFileBranch)row.tag; branch.GetPath(path); if(FileExists(path)) DeleteFile(path); if(!FileExists(path)) DeleteBranch(branch, listBox); } selection.Free(null); } */ } return true; } bool Lists_NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods) { if(listBox.currentRow) { char path[MAX_LOCATION]; ExplorerFileBranch branch = (ExplorerFileBranch)listBox.currentRow.tag; //if(listBox != view.results || searchThread.tree) // GetRowPath(listBox.currentRow, path); //else // strcpy(path, *(char **)listBox.currentRow.GetData(resultsFieldPath)); branch.GetPath(path); ShellOpen(path); return false; } return true; } ExplorerSearchViewTree() { results.AddField(resultsNameField); browser.AddField(browserNameField); } }