+ void ToggleSearchMode(bool inSearch)
+ {
+ SearchStop();
+ //search.visible = inSearch;
+ //panelSearch.checked = inSearch; // <------ this is toggling panelSearch even though it shouldn't
+ //searchSpace.visible = !inSearch;
+ searchBar.visible = inSearch;
+ history[historyIndex].inSearch = inSearch;
+ size = { size.w, size.h };
+ view.pathColumn = inSearch;
+ /*if(inSearch)
+ searchThread.InitResults();*/
+ if(inSearch && /*(*/searchInFileName.contents[0]/* || searchInFileContents.contents[0])*/)
+ SearchStart();
+ }
+
+ void ReadyTree()
+ {
+ if(tree.visible)
+ {
+ if(!treeInitialized)
+ {
+ tree.path = "/"; // this should be available as a parameter
+ treeInitialized = true;
+ }
+ tree.SelectLocation(view.path);
+ }
+ }
+
+ void Refresh()
+ {
+ if(searchBar.visible)
+ SearchStart();
+ else
+ {
+ if(tree.visible)
+ tree.Refresh();
+ view.Refresh();
+ }
+ }
+
+ void GoTo(char * location, bool viewIsAtLocation, bool treeIsAtLocation)
+ {
+ HistoryItem item = null;
+ if(!history.count || fstrcmp(history[historyIndex].path, location))
+ {
+ int c;
+ for(c = 0; c < history.count; c++)
+ if(!fstrcmp(history[c].path, location))
+ break;
+ if(c == history.count)
+ {
+ item = { path = CopyString(location) };
+ if(history.count)
+ {
+ while(historyIndex < history.count-1)
+ {
+ delete history[history.count-1].path;
+ history.count--;
+ }
+ }
+ history.Add(item);
+ historyIndex = history.count-1;
+ }
+ else
+ historyIndex = c;
+ }
+ GoToHistoryIndex(viewIsAtLocation, treeIsAtLocation, item != null);
+ }
+
+ void GoToHistoryIndex(bool viewIsAtLocation, bool treeIsAtLocation, bool updateHistoryItem)
+ {
+ HistoryItem item = history[historyIndex];
+
+ goBack.disabled = historyIndex == 0;
+ goForward.disabled = historyIndex == history.count-1;
+ goUp.disabled = !fstrcmp(item.path, "/");
+
+ if(!viewIsAtLocation)
+ {
+ if(item.inSearch != panelSearch.checked)
+ {
+ ToggleSearchMode(item.inSearch);
+ if(item.inSearch)
+ SearchStart();
+ }
+ if(!item.inSearch)
+ /*{
+ //SearchStart();
+ }
+ else*/
+ {
+ view.path = item.path;
+ item.holdRecordingSelection = true;
+ view.SelectMultipleByPath(item.selection);
+ }
+ }
+ if(tree.visible && !treeIsAtLocation)
+ tree.SelectLocation(item.path);
+
+ if(updateHistoryItem)
+ UpdateHistoryItem(view.selection);
+ }
+
+ void UpdateHistoryItem(FileSystemBoxSelection selection)
+ {
+ HistoryItem item = history[historyIndex];
+
+ if(!item.holdRecordingSelection)
+ {
+ if(selection.node || (selection.nodes && selection.nodes.count))
+ {
+ item.selection.Free();
+ if(selection.nodes.count)
+ {
+ for(node : selection.nodes)
+ item.selection.Add(CopyString(node.path));
+ }
+ else if(selection.node)
+ item.selection.Add(CopyString(selection.node.path));
+ }
+ }
+ else
+ item.holdRecordingSelection = false;
+ }
+
+ void SearchStart()
+ {
+ SearchStop();
+ searchThread.active = true;
+
+ searchThread.optionSubdirs = searchInSubDirs.checked == true;
+ searchThread.optionTree = view.treeBranches; //(options.subdirs.checked && options.tree.checked);
+ searchThread.optionBrowser = tree.visible; //(options.subdirs.checked && options.browser.checked);
+#ifndef __WIN32__
+ searchThread.optionNameMatchCase = inFileNameMatchCase.checked;
+#else
+ searchThread.optionNameMatchCase = false;
+#endif
+ searchThread.optionNameMatchWord = inFileNameMatchWord.checked;
+ searchThread.optionContentMatchCase = inFileContentMatchCase.checked;
+ searchThread.optionContentMatchWord = inFileContentMatchWord.checked;
+
+ strcpy(searchThread.location, view.path);
+ strcpy(searchThread.nameSearch, searchInFileName.contents);
+ strcpy(searchThread.contentSearch, searchInFileContent.contents);
+
+ //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";
+ /*{
+ char string[MAX_LOCATION + 2048];
+ sprintf(string, "%s (Searching %s)", title, view.path);
+ //PrintLn(string); //view.results.text = string;
+ text = string;
+ }*/
+ searchThread.InitResults();
+ searchThread.Create();
+ searchStop.disabled = false;
+ //Update(null);
+ }
+
+ bool SearchStop()
+ {
+ if(searchThread.active)
+ {
+ searchThread.terminate = true;
+ //searchStop.disabled = true;
+ app.Unlock();
+ searchThread.Wait();
+ app.Lock();
+ return true;
+ }
+ return false;
+ }
+