protected FileSearchManagement(FileSearchManagement original) { escapedSearchStr = original.escapedSearchStr; translatedSearchStr = original.translatedSearchStr; escapedReplaceStr = original.escapedReplaceStr; translatedReplaceStr = original.translatedReplaceStr; CurrentSearchLocation = original.CurrentSearchLocation; SearchOptions = original.SearchOptions; currentFile = original.currentFile; startOffset = original.startOffset; currentOffset = original.currentOffset; stopOffset = original.stopOffset; somethingFound = false; }
void MatchAll(bool replace = false) { var searcher = new FileSearchManagement(this); if(SearchOptions.HasFlag(SearchFlags.Upward)) searcher.SearchOptions ^= SearchFlags.Upward; // "Search upward" isn't necessary in bulk mode, and could cause subtle bugs. searcher.ResetSearch(false); var matches = new LinkedList<SearchResult>(); string haystack = null; while ((haystack = searcher.NextMatch(haystack)) != null) { if (replace) { var ed = WorkbenchLogic.Instance.OpenFile(searcher.currentFile, searcher.currentOffset) as EditorDocument; ed.Editor.Document.Replace(searcher.currentOffset, TranslatedSearchStr.Length, TranslatedReplaceStr); haystack = ed.Editor.Document.Text; } int lineEnd = 0; int line = 0; int column = 0; while (lineEnd < haystack.Length) { if (haystack[lineEnd] == '\n') { ++line; if (lineEnd >= searcher.currentOffset) break; column = 0; } ++lineEnd; ++column; } int lineStart = lineEnd - column; string context = haystack.Substring(lineStart, column).Trim(); column = searcher.currentOffset - lineStart; matches.AddLast(new SearchResult { File = searcher.currentFile, Offset = searcher.currentOffset, Line = line, Column = column, CodeSnippet = context }); } var pan = IDEManager.Instance.MainWindow.SearchResultPanel; pan.SearchString = replace? TranslatedReplaceStr : TranslatedSearchStr; pan.Results = matches; pan.Show(); }
void MatchAll(bool replace = false) { var searcher = new FileSearchManagement(this); if (SearchOptions.HasFlag(SearchFlags.Upward)) { searcher.SearchOptions ^= SearchFlags.Upward; // "Search upward" isn't necessary in bulk mode, and could cause subtle bugs. } searcher.ResetSearch(false); var matches = new LinkedList <SearchResult>(); string haystack = null; while ((haystack = searcher.NextMatch(haystack)) != null) { if (replace) { var ed = WorkbenchLogic.Instance.OpenFile(searcher.currentFile, searcher.currentOffset) as EditorDocument; ed.Editor.Document.Replace(searcher.currentOffset, TranslatedSearchStr.Length, TranslatedReplaceStr); haystack = ed.Editor.Document.Text; } int lineEnd = 0; int line = 0; int column = 0; while (lineEnd < haystack.Length) { if (haystack[lineEnd] == '\n') { ++line; if (lineEnd >= searcher.currentOffset) { break; } column = 0; } ++lineEnd; ++column; } int lineStart = lineEnd - column; string context = haystack.Substring(lineStart, column).Trim(); column = searcher.currentOffset - lineStart; matches.AddLast(new SearchResult { File = searcher.currentFile, Offset = searcher.currentOffset, Line = line, Column = column, CodeSnippet = context }); } var pan = IDEManager.Instance.MainWindow.SearchResultPanel; pan.SearchString = replace? TranslatedReplaceStr : TranslatedSearchStr; pan.Results = matches; pan.Show(); }