private void btnOpenFile_Click(object sender, RoutedEventArgs e) { if (tvSearchResult.SelectedItem is FormattedGrepLine) { inputData.OpenFile(tvSearchResult.SelectedItem as FormattedGrepLine, false); } else if (tvSearchResult.SelectedItem is FormattedGrepResult) { inputData.OpenFile(tvSearchResult.SelectedItem as FormattedGrepResult, false); } }
private void OpenFiles(bool useCustomEditor) { // get the unique set of file names to open from the selections // keep the first record from each file to use when opening the file // prefer to open by line, if any line is selected; otherwise by file List <string> fileNames = new List <string>(); List <FormattedGrepLine> lines = new List <FormattedGrepLine>(); List <FormattedGrepResult> files = new List <FormattedGrepResult>(); foreach (var item in inputData.SelectedItems) { var lineNode = item as FormattedGrepLine; if (lineNode != null) { string name = lineNode.Parent.GrepResult.FileNameReal; if (!fileNames.Contains(name)) { fileNames.Add(name); lines.Add(lineNode); } } } foreach (var item in inputData.SelectedItems) { var fileNode = item as FormattedGrepResult; if (fileNode != null) { string name = fileNode.GrepResult.FileNameReal; if (!fileNames.Contains(name)) { fileNames.Add(name); files.Add(fileNode); } } } foreach (var item in lines) { inputData.OpenFile(item, useCustomEditor); } foreach (var item in files) { inputData.OpenFile(item, useCustomEditor); } }