private void SearchPowerPoint(Stream stream, string file, string searchPattern, GrepSearchOption searchOptions, SearchDelegates.DoSearch searchMethod, List <GrepSearchResult> searchResults) { try { var slides = PowerPointReader.ExtractPowerPointText(stream); foreach (var slide in slides) { var lines = searchMethod(-1, 0, slide.Item2, searchPattern, searchOptions, true); if (lines.Count > 0) { GrepSearchResult result = new GrepSearchResult(file, searchPattern, lines, Encoding.Default) { AdditionalInformation = " " + TranslationSource.Format(Resources.Main_PowerPointSlideNumber, slide.Item1) }; using (StringReader reader = new StringReader(slide.Item2)) { result.SearchResults = Utils.GetLinesEx(reader, result.Matches, initParams.LinesBefore, initParams.LinesAfter); } result.ReadOnly = true; searchResults.Add(result); } } } catch (Exception ex) { logger.Error(ex, string.Format("Failed to search inside PowerPoint file '{0}'", file)); } }
public override void OpenFile(OpenFileArgs args) { SevenZipExtractor extractor = new SevenZipExtractor(args.SearchResult.FileNameReal); string tempFolder = Utils.FixFolderName(Utils.GetTempFolder()) + "dnGREP-Archive\\" + Utils.GetHash(args.SearchResult.FileNameReal) + "\\"; if (!Directory.Exists(tempFolder)) { Directory.CreateDirectory(tempFolder); try { extractor.ExtractArchive(tempFolder); } catch { args.UseBaseEngine = true; } } GrepSearchResult newResult = new GrepSearchResult(); newResult.FileNameReal = args.SearchResult.FileNameReal; newResult.FileNameDisplayed = args.SearchResult.FileNameDisplayed; OpenFileArgs newArgs = new OpenFileArgs(newResult, args.Pattern, args.LineNumber, args.UseCustomEditor, args.CustomEditor, args.CustomEditorArgs); newArgs.SearchResult.FileNameDisplayed = tempFolder + args.SearchResult.FileNameDisplayed.Substring(args.SearchResult.FileNameReal.Length + 1); Utils.OpenFile(newArgs); }
public FormattedGrepResult(GrepSearchResult result, string folderPath) { GrepResult = result; searchFolderPath = folderPath; bool isFileReadOnly = SetLabel(); if (isFileReadOnly) { GrepResult.ReadOnly = true; Style = "ReadOnly"; } if (!GrepResult.IsSuccess) { Style = "Error"; } if (!string.IsNullOrEmpty(GrepResult.FileInfo.ErrorMsg)) { Style = "Error"; } FormattedLines = new LazyResultsList(result, this); FormattedLines.LineNumberColumnWidthChanged += FormattedLines_PropertyChanged; FormattedLines.LoadFinished += FormattedLines_LoadFinished; }
private void SearchExcel(Stream stream, string file, string searchPattern, GrepSearchOption searchOptions, SearchDelegates.DoSearch searchMethod, List <GrepSearchResult> searchResults) { try { var sheets = ExcelReader.ExtractExcelText(stream); foreach (var kvPair in sheets) { var lines = searchMethod(-1, 0, kvPair.Value, searchPattern, searchOptions, true); if (lines.Count > 0) { GrepSearchResult result = new GrepSearchResult(file, searchPattern, lines, Encoding.Default) { AdditionalInformation = " " + TranslationSource.Format(Resources.Main_ExcelSheetName, kvPair.Key) }; using (StringReader reader = new StringReader(kvPair.Value)) { result.SearchResults = Utils.GetLinesEx(reader, result.Matches, initParams.LinesBefore, initParams.LinesAfter); } result.ReadOnly = true; searchResults.Add(result); } } } catch (Exception ex) { logger.Error(ex, string.Format("Failed to search inside Excel file '{0}'", file)); } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode selectedNode = tvSearchResult.SelectedNode; if (selectedNode != null) { // Line was selected int lineNumber = 0; if (selectedNode.Parent != null) { if (selectedNode.Tag != null && selectedNode.Tag is int) { lineNumber = (int)selectedNode.Tag; } selectedNode = selectedNode.Parent; } if (selectedNode != null && selectedNode.Tag != null) { GrepSearchResult result = (GrepSearchResult)selectedNode.Tag; OpenFileArgs fileArg = new OpenFileArgs(result, lineNumber, Properties.Settings.Default.UseCustomEditor, Properties.Settings.Default.CustomEditor, Properties.Settings.Default.CustomEditorArgs); dnGREP.Engines.GrepEngineFactory.GetSearchEngine(result.FileNameReal, false, 0, 0).OpenFile(fileArg); if (fileArg.UseBaseEngine) { Utils.OpenFile(new OpenFileArgs(result, lineNumber, Properties.Settings.Default.UseCustomEditor, Properties.Settings.Default.CustomEditor, Properties.Settings.Default.CustomEditorArgs)); } } } }
public FormattedGrepResult(GrepSearchResult result, string folderPath) { grepResult = result; fileInfo = new FileInfo(grepResult.FileNameReal); bool isFileReadOnly = Utils.IsReadOnly(grepResult); bool isSuccess = grepResult.IsSuccess; string basePath = Utils.GetBaseFolder(folderPath).TrimEnd('\\'); string displayedName = Path.GetFileName(grepResult.FileNameDisplayed); if (GrepSettings.Instance.Get <bool>(GrepSettings.Key.ShowFilePathInResults) && grepResult.FileNameDisplayed.Contains(basePath)) { displayedName = grepResult.FileNameDisplayed.Substring(basePath.Length + 1).TrimStart('\\'); } int matchCount = (grepResult.Matches == null ? 0 : grepResult.Matches.Count); if (matchCount > 0) { if (GrepSettings.Instance.Get <bool>(GrepSettings.Key.ShowVerboseMatchCount)) { var lineCount = grepResult.Matches.Where(r => r.LineNumber > 0) .Select(r => r.LineNumber).Distinct().Count(); displayedName = string.Format("{0} ({1} matches on {2} lines)", displayedName, matchCount, lineCount); } else { displayedName = string.Format("{0} ({1})", displayedName, matchCount); } } if (isFileReadOnly) { result.ReadOnly = true; displayedName = displayedName + " [read-only]"; } label = displayedName; if (isFileReadOnly) { style = "ReadOnly"; } if (!isSuccess) { style = "Error"; } formattedLines = new LazyResultsList(result, this); formattedLines.LineNumberColumnWidthChanged += formattedLines_PropertyChanged; formattedLines.LoadFinished += formattedLines_LoadFinished; if (GrepSettings.Instance.Get <bool>(GrepSettings.Key.ExpandResults)) { IsExpanded = true; } }
public override void OpenFile(OpenFileArgs args) { string tempFolder = Path.Combine(Utils.GetTempFolder(), "dnGREP-Archive", Utils.GetHash(args.SearchResult.FileNameReal)); string innerFileName = args.SearchResult.FileNameDisplayed.Substring(args.SearchResult.FileNameReal.Length).TrimStart(Path.DirectorySeparatorChar); string filePath = Path.Combine(tempFolder, innerFileName); if (!File.Exists(filePath)) { // use the directory name to also include folders within the archive string directory = Path.GetDirectoryName(filePath); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string zipFile = args.SearchResult.FileNameReal; if (zipFile.Length > 260 && !zipFile.StartsWith(@"\\?\")) { zipFile = @"\\?\" + zipFile; } using (SevenZipExtractor extractor = new SevenZipExtractor(zipFile)) { if (extractor.ArchiveFileData.Where(r => r.FileName == innerFileName && !r.IsDirectory).Any()) { using (FileStream stream = File.Open(filePath, FileMode.Create, FileAccess.Write, FileShare.None)) { try { extractor.ExtractFile(innerFileName, stream); } catch { args.UseBaseEngine = true; } } } } } if (Utils.IsPdfFile(filePath) || Utils.IsWordFile(filePath) || Utils.IsExcelFile(filePath)) { args.UseCustomEditor = false; } GrepSearchResult newResult = new GrepSearchResult { FileNameReal = args.SearchResult.FileNameReal, FileNameDisplayed = args.SearchResult.FileNameDisplayed }; OpenFileArgs newArgs = new OpenFileArgs(newResult, args.Pattern, args.LineNumber, args.FirstMatch, args.ColumnNumber, args.UseCustomEditor, args.CustomEditor, args.CustomEditorArgs); newArgs.SearchResult.FileNameDisplayed = filePath; Utils.OpenFile(newArgs); }
public OpenFileArgs(GrepSearchResult searchResult, string pattern, int line, bool useCustomEditor, string customEditor, string customEditorArgs) : base() { this.searchResult = searchResult; this.lineNumber = line; this.useCustomEditor = useCustomEditor; this.customEditor = customEditor; this.customEditorArgs = customEditorArgs; this.useBaseEngine = false; this.pattern = pattern; }
public LazyResultsList(GrepSearchResult result, FormattedGrepResult formattedResult) { this.result = result; this.formattedResult = formattedResult; if ((result.Matches != null && result.Matches.Count > 0) || !result.IsSuccess) { GrepSearchResult.GrepLine emptyLine = new GrepSearchResult.GrepLine(-1, "", true, null); var dummyLine = new FormattedGrepLine(emptyLine, formattedResult, 30, false); this.Add(dummyLine); isLoaded = false; } }
public FormattedGrepResult(GrepSearchResult result, string folderPath) { grepResult = result; fileInfo = new FileInfo(grepResult.FileNameReal); bool isFileReadOnly = Utils.IsReadOnly(grepResult); bool isSuccess = grepResult.IsSuccess; string displayedName = Path.GetFileName(grepResult.FileNameDisplayed); if (GrepSettings.Instance.Get <bool>(GrepSettings.Key.ShowFilePathInResults) && grepResult.FileNameDisplayed.Contains(Utils.GetBaseFolder(folderPath) + "\\")) { displayedName = grepResult.FileNameDisplayed.Substring(Utils.GetBaseFolder(folderPath).Length + 1); } int lineCount = (grepResult.Matches == null ? 0 : grepResult.Matches.Count); if (lineCount > 0) { displayedName = string.Format("{0} ({1})", displayedName, lineCount); } if (isFileReadOnly) { result.ReadOnly = true; displayedName = displayedName + " [read-only]"; } label = displayedName; if (isFileReadOnly) { style = "ReadOnly"; } if (!isSuccess) { style = "Error"; } formattedLines = new LazyResultsList(result, this); formattedLines.LineNumberColumnWidthChanged += formattedLines_PropertyChanged; formattedLines.LoadFinished += formattedLines_LoadFinished; if (GrepSettings.Instance.Get <bool>(GrepSettings.Key.ExpandResults)) { IsExpanded = true; } }
private List <GrepSearchResult> searchMultiline(string file, string searchPattern, GrepSearchOption searchOptions, SearchDelegates.DoSearch searchMethod) { List <GrepSearchResult> searchResults = new List <GrepSearchResult>(); try { // Open a given Word document as readonly object wordDocument = openDocument(file, true); if (wordDocument != null) { // Get Selection Property wordSelection = wordApplication.GetType().InvokeMember("Selection", BindingFlags.GetProperty, null, wordApplication, null); // create range and find objects object range = getProperty(wordDocument, "Content"); // create text object text = getProperty(range, "Text"); var lines = searchMethod(-1, Utils.CleanLineBreaks(text.ToString()), searchPattern, searchOptions, true); if (lines.Count > 0) { GrepSearchResult result = new GrepSearchResult(file, searchPattern, lines, Encoding.Default); using (StringReader reader = new StringReader(text.ToString())) { result.SearchResults = Utils.GetLinesEx(reader, result.Matches, linesBefore, linesAfter); } result.ReadOnly = true; searchResults.Add(result); } closeDocument(wordDocument); } } catch (Exception ex) { logger.Log <Exception>(LogLevel.Error, "Failed to search inside Word file", ex); } finally { releaseSelection(); } return(searchResults); }
public string ExtractToTempFile(GrepSearchResult searchResult) { string tempFolder = Path.Combine(Utils.GetTempFolder(), "dnGREP-Archive", Utils.GetHash(searchResult.FileNameReal)); string innerFileName = searchResult.FileNameDisplayed.Substring(searchResult.FileNameReal.Length).TrimStart(Path.DirectorySeparatorChar); string filePath = Path.Combine(tempFolder, innerFileName); if (!File.Exists(filePath)) { // use the directory name to also include folders within the archive string directory = Path.GetDirectoryName(filePath); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string zipFile = searchResult.FileNameReal; if (zipFile.Length > 260 && !zipFile.StartsWith(@"\\?\")) { zipFile = @"\\?\" + zipFile; } using (SevenZipExtractor extractor = new SevenZipExtractor(zipFile)) { if (extractor.ArchiveFileData.Where(r => r.FileName == innerFileName && !r.IsDirectory).Any()) { using (FileStream stream = File.Open(filePath, FileMode.Create, FileAccess.Write, FileShare.None)) { try { extractor.ExtractFile(innerFileName, stream); } catch (Exception ex) { logger.Log <Exception>(LogLevel.Error, string.Format("Failed extract file {0} from archive '{1}'", innerFileName, searchResult.FileNameReal), ex); } } } } } return(filePath); }
private void SearchWord(Stream stream, string file, string searchPattern, GrepSearchOption searchOptions, SearchDelegates.DoSearch searchMethod, List <GrepSearchResult> searchResults) { try { var text = WordReader.ExtractWordText(stream); var lines = searchMethod(-1, 0, text, searchPattern, searchOptions, true); if (lines.Count > 0) { GrepSearchResult result = new GrepSearchResult(file, searchPattern, lines, Encoding.Default); using (StringReader reader = new StringReader(text)) { result.SearchResults = Utils.GetLinesEx(reader, result.Matches, initParams.LinesBefore, initParams.LinesAfter); } result.ReadOnly = true; searchResults.Add(result); } } catch (Exception ex) { logger.Error(ex, string.Format("Failed to search inside Word file '{0}'", file)); } }
private List <GrepSearchResult> SearchMultiline(string file, string searchPattern, GrepSearchOption searchOptions, SearchDelegates.DoSearch searchMethod) { List <GrepSearchResult> searchResults = new List <GrepSearchResult>(); try { // Open a given Word document as readonly object wordDocument = OpenDocument(file, true); if (wordDocument != null) { // create range and find objects object range = GetProperty(wordDocument, "Content"); // create text object text = GetProperty(range, "Text"); string docText = Utils.CleanLineBreaks(text.ToString()); var lines = searchMethod(-1, 0, docText, searchPattern, searchOptions, true); if (lines.Count > 0) { GrepSearchResult result = new GrepSearchResult(file, searchPattern, lines, Encoding.Default); using (StringReader reader = new StringReader(docText)) { result.SearchResults = Utils.GetLinesEx(reader, result.Matches, initParams.LinesBefore, initParams.LinesAfter); } result.ReadOnly = true; searchResults.Add(result); } CloseDocument(wordDocument); } } catch (Exception ex) { logger.Error(ex, "Failed to search inside Word file"); } return(searchResults); }
private List<GrepSearchResult> searchMultiline(string file, string searchPattern, GrepSearchOption searchOptions, SearchDelegates.DoSearch searchMethod) { List<GrepSearchResult> searchResults = new List<GrepSearchResult>(); try { // Open a given Word document as readonly object wordDocument = openDocument(file, true); // Get Selection Property wordSelection = wordApplication.GetType().InvokeMember("Selection", BindingFlags.GetProperty, null, wordApplication, null); // create range and find objects object range = getProperty(wordDocument, "Content"); // create text object text = getProperty(range, "Text"); var lines = searchMethod(Utils.CleanLineBreaks(text.ToString()), searchPattern, searchOptions, true); if (lines.Count > 0) { GrepSearchResult result = new GrepSearchResult(file, searchPattern, lines); using (StringReader reader = new StringReader(text.ToString())) { result.SearchResults = Utils.GetLinesEx(reader, result.Matches, linesBefore, linesAfter); } result.ReadOnly = true; searchResults.Add(result); } closeDocument(wordDocument); } catch (Exception ex) { logger.LogException(LogLevel.Error, "Failed to search inside Word file", ex); } finally { releaseSelection(); } return searchResults; }
private void appendResults(GrepSearchResult result) { if (result == null) { return; } // Populate icon list string ext = Path.GetExtension(result.FileNameDisplayed); if (!treeViewExtensionList.Contains(ext)) { treeViewExtensionList.Add(ext); FileIcons.LoadImageList(treeViewExtensionList.ToArray()); tvSearchResult.ImageList = FileIcons.SmallIconList; } bool isFileReadOnly = Utils.IsReadOnly(result); string displayedName = Path.GetFileName(result.FileNameDisplayed); if (Properties.Settings.Default.ShowFilePathInResults && result.FileNameDisplayed.Contains(Utils.GetBaseFolder(tbFolderName.Text) + "\\")) { displayedName = result.FileNameDisplayed.Substring(Utils.GetBaseFolder(tbFolderName.Text).Length + 1); } int lineCount = Utils.MatchCount(result); if (lineCount > 0) { displayedName = string.Format("{0} ({1})", displayedName, lineCount); } if (isFileReadOnly) { displayedName = displayedName + " [read-only]"; } TreeNode node = new TreeNode(displayedName); node.Tag = result; tvSearchResult.Nodes.Add(node); node.ImageKey = ext; node.SelectedImageKey = node.ImageKey; node.StateImageKey = node.ImageKey; if (isFileReadOnly) { node.ForeColor = Color.DarkGray; } if (result.SearchResults != null) { for (int i = 0; i < result.SearchResults.Count; i++) { GrepSearchResult.GrepLine line = result.SearchResults[i]; string lineSummary = line.LineText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim(); if (lineSummary.Length == 0) { lineSummary = " "; } else if (lineSummary.Length > 100) { lineSummary = lineSummary.Substring(0, 100) + "..."; } string lineNumber = (line.LineNumber == -1 ? "" : line.LineNumber + ": "); TreeNode lineNode = new TreeNode(lineNumber + lineSummary); lineNode.ImageKey = "%line%"; lineNode.SelectedImageKey = lineNode.ImageKey; lineNode.StateImageKey = lineNode.ImageKey; lineNode.Tag = line.LineNumber; if (!line.IsContext && Properties.Settings.Default.ShowLinesInContext) { lineNode.ForeColor = Color.Red; } node.Nodes.Add(lineNode); } } }
private void previewFile(string filePath, GrepSearchResult result, int line, RectangleF parentWindow) { if (PreviewFileContent) { if (previewModel == null) { previewModel = new PreviewViewModel(); } if (preview == null) { preview = new PreviewView(); preview.DataContext = previewModel; System.Drawing.Rectangle bounds = settings.Get<System.Drawing.Rectangle>(GrepSettings.Key.PreviewWindowSize); if (bounds.Left == 0 && bounds.Right == 0) { preview.Height = parentWindow.Height; preview.Left = parentWindow.Left + parentWindow.Width; preview.Width = parentWindow.Width; preview.Top = parentWindow.Top; } else { var stickyDir = GrepSettings.Instance.Get<StickyWindow.StickDir>(GrepSettings.Key.PreviewWindowPosition); bounds = StickyWindow.PositionRelativeTo(stickyWindow.OriginalForm, stickyDir, bounds); preview.Height = bounds.Height; preview.Left = bounds.Left; preview.Width = bounds.Width; preview.Top = bounds.Top; } } previewModel.GrepResult = result; previewModel.LineNumber = line; previewModel.FilePath = filePath; preview.Show(); } }
public PreviewHighlighter(GrepSearchResult result, int[] lineNumbers = null) { this.result = result; this.lineNumbers = lineNumbers; }
public CodeSnippet(int[] lines, string text, GrepSearchResult result) { lineNumbers = lines; this.text = text; this.result = result; }
public FormattedGrepResult(GrepSearchResult result, string folderPath) { GrepResult = result; bool isFileReadOnly = Utils.IsReadOnly(GrepResult); bool isSuccess = GrepResult.IsSuccess; string basePath = string.IsNullOrWhiteSpace(folderPath) ? string.Empty : folderPath.TrimEnd('\\'); string displayedName = Path.GetFileName(GrepResult.FileNameDisplayed); if (GrepSettings.Instance.Get <bool>(GrepSettings.Key.ShowFilePathInResults) && GrepResult.FileNameDisplayed.Contains(basePath, StringComparison.CurrentCultureIgnoreCase)) { if (!string.IsNullOrWhiteSpace(basePath)) { displayedName = GrepResult.FileNameDisplayed.Substring(basePath.Length + 1).TrimStart('\\'); } else { displayedName = GrepResult.FileNameDisplayed; } } if (!string.IsNullOrWhiteSpace(GrepResult.AdditionalInformation)) { displayedName += " " + GrepResult.AdditionalInformation + " "; } int matchCount = (GrepResult.Matches == null ? 0 : GrepResult.Matches.Count); if (matchCount > 0) { if (GrepSettings.Instance.Get <bool>(GrepSettings.Key.ShowVerboseMatchCount)) { var lineCount = GrepResult.Matches.Where(r => r.LineNumber > 0) .Select(r => r.LineNumber).Distinct().Count(); displayedName = string.Format("{0} ({1} matches on {2} lines)", displayedName, matchCount, lineCount); } else { displayedName = string.Format("{0} ({1})", displayedName, matchCount); } } if (isFileReadOnly) { result.ReadOnly = true; displayedName = displayedName + " [read-only]"; } Label = displayedName; if (isFileReadOnly) { Style = "ReadOnly"; } if (!isSuccess) { Style = "Error"; } FormattedLines = new LazyResultsList(result, this); FormattedLines.LineNumberColumnWidthChanged += FormattedLines_PropertyChanged; FormattedLines.LoadFinished += FormattedLines_LoadFinished; }
public ReplaceViewHighlighter(GrepSearchResult result) { this.result = result; }
private InlineCollection formatLine(GrepSearchResult.GrepLine line) { Paragraph paragraph = new Paragraph(); var font = new FontFamily("Consolas"); if (line.Matches.Count == 0) { Run mainRun = new Run(line.LineText); paragraph.Inlines.Add(mainRun); } else { int counter = 0; string fullLine = line.LineText; GrepSearchResult.GrepMatch[] lineMatches = new GrepSearchResult.GrepMatch[line.Matches.Count]; line.Matches.CopyTo(lineMatches); foreach (GrepSearchResult.GrepMatch m in lineMatches) { try { string regLine = null; string fmtLine = null; if (fullLine.Length < m.StartLocation + m.Length) { regLine = fullLine; } else { regLine = fullLine.Substring(counter, m.StartLocation - counter); fmtLine = fullLine.Substring(m.StartLocation, m.Length); } Run regularRun = new Run(regLine); regularRun.FontFamily = font; paragraph.Inlines.Add(regularRun); if (fmtLine != null) { Run highlightedRun = new Run(fmtLine); highlightedRun.FontFamily = font; highlightedRun.Background = Brushes.Yellow; paragraph.Inlines.Add(highlightedRun); } else { break; } } catch { Run regularRun = new Run(fullLine); regularRun.FontFamily = font; paragraph.Inlines.Add(regularRun); } finally { counter = m.StartLocation + m.Length; } } if (counter < fullLine.Length) { try { string regLine = fullLine.Substring(counter); Run regularRun = new Run(regLine); regularRun.FontFamily = font; paragraph.Inlines.Add(regularRun); } catch { Run regularRun = new Run(fullLine); regularRun.FontFamily = font; paragraph.Inlines.Add(regularRun); } } } return paragraph.Inlines; }
private void appendResults(GrepSearchResult result) { if (result == null) return; // Populate icon list string ext = Path.GetExtension(result.FileNameDisplayed); if (!treeViewExtensionList.Contains(ext)) { treeViewExtensionList.Add(ext); FileIcons.LoadImageList(treeViewExtensionList.ToArray()); tvSearchResult.ImageList = FileIcons.SmallIconList; } bool isFileReadOnly = Utils.IsReadOnly(result); string displayedName = Path.GetFileName(result.FileNameDisplayed); if (Properties.Settings.Default.ShowFilePathInResults && result.FileNameDisplayed.Contains(Utils.GetBaseFolder(tbFolderName.Text) + "\\")) { displayedName = result.FileNameDisplayed.Substring(Utils.GetBaseFolder(tbFolderName.Text).Length + 1); } int lineCount = Utils.MatchCount(result); if (lineCount > 0) displayedName = string.Format("{0} ({1})", displayedName, lineCount); if (isFileReadOnly) displayedName = displayedName + " [read-only]"; TreeNode node = new TreeNode(displayedName); node.Tag = result; tvSearchResult.Nodes.Add(node); node.ImageKey = ext; node.SelectedImageKey = node.ImageKey; node.StateImageKey = node.ImageKey; if (isFileReadOnly) { node.ForeColor = Color.DarkGray; } if (result.SearchResults != null) { for (int i = 0; i < result.SearchResults.Count; i++ ) { GrepSearchResult.GrepLine line = result.SearchResults[i]; string lineSummary = line.LineText.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim(); if (lineSummary.Length == 0) lineSummary = " "; else if (lineSummary.Length > 100) lineSummary = lineSummary.Substring(0, 100) + "..."; string lineNumber = (line.LineNumber == -1 ? "" : line.LineNumber + ": "); TreeNode lineNode = new TreeNode(lineNumber + lineSummary); lineNode.ImageKey = "%line%"; lineNode.SelectedImageKey = lineNode.ImageKey; lineNode.StateImageKey = lineNode.ImageKey; lineNode.Tag = line.LineNumber; if (!line.IsContext && Properties.Settings.Default.ShowLinesInContext) { lineNode.ForeColor = Color.Red; } node.Nodes.Add(lineNode); } } }