public IFindInFilesWindow Open(IFindInFilesItem item) { TextEditorWindow window = TextEditorWindow.GetWindowForLoadHelper(); window.LoadFile(item.GetPath()); window.Show(); return window; }
public IFindInFilesWindow Open(IFindInFilesItem item) { Form window; if (FindNearestViableActivator(item, out window) == null) { Debug.Assert(false); throw new ArgumentException(); } // This is a bit of a hack for HighlightLine() below. Most editors set the IP to the beginning of the // main body edit field in the OnShow() handler. This is going to happen during event processing of // MessageBox.Show() below, which blows away the result of HighlightLine(). Unless we do this to get // that event dealt with first. Application.DoEvents(); return(new FindInFilesWindow(window, this)); }
public IFindInFilesItemActivator FindNearestViableActivator(IFindInFilesItem item, out Form window) { window = null; IFindInFilesItemActivator activator = (IFindInFilesItemActivator)item; while (activator != null) { try { window = mainWindow.CreateAndShowEditor(activator.DataObject); break; } catch (ArgumentException) { activator = activator.Parent; } } return(activator); }
public void SetSelection(IFindInFilesItem item, int startLine, int startChar, int endLine, int endCharPlusOne) { IFindInFilesItemActivator activator = (IFindInFilesItemActivator)item; if (activator.DataObject is NoteObjectRec) { // special case for track elements Form window; if (application.FindNearestViableActivator(item, out window) == null) { Debug.Assert(false); throw new ArgumentException(); } TrackWindow trackWindow = (TrackWindow)window; trackWindow.Edit.View.TrackViewTrySingleNoteOrCommandSelection((NoteObjectRec)activator.DataObject); } else { Control edit = FindControl(window.Controls, activator.Property); if (edit != null) { if (edit is TextEditControl) { ((TextEditControl)edit).SetSelection(startLine, startChar, endLine, endCharPlusOne); } else if (edit is TextBox) { TextBox textBox = (TextBox)edit; int start = textBox.GetFirstCharIndexFromLine(startLine) + startChar; int end = textBox.GetFirstCharIndexFromLine(endLine) + endCharPlusOne; textBox.SelectionStart = start; textBox.SelectionLength = end - start; } edit.Focus(); } } }
public IFindInFilesItem[] GetFiles() { string[] files = Directory.GetFiles(root); IFindInFilesItem[] nodes = new IFindInFilesItem[files.Length]; for (int i = 0; i < nodes.Length; i++) { nodes[i] = new FindInFilesItem(files[i]); } return nodes; }
private void TestFile(IFindInFilesItem item, string relativeRoot) { string displayPath = Path.Combine(relativeRoot, item.GetFileName()); const string Prefix = @".\"; if (displayPath.StartsWith(Prefix)) { displayPath = displayPath.Substring(Prefix.Length); } try { using (Stream stream = item.Open()) { using (TextReader reader = new StreamReader(stream, true/*detectEncoding*/)) { int lineNumber = 0; string line; while ((line = reader.ReadLine()) != null) { lineNumber++; int i = -1; do { i = line.IndexOf(pattern, i + 1, caseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase); bool skip = false; if (matchWholeWords && (i >= 0)) { if (Char.IsLetterOrDigit(pattern[0])) { if ((i - 1 >= 0) && Char.IsLetterOrDigit(line[i - 1])) { skip = true; } } if (Char.IsLetterOrDigit(pattern[pattern.Length - 1])) { if ((i + pattern.Length < line.Length) && Char.IsLetterOrDigit(line[i + pattern.Length])) { skip = true; } } } if ((i >= 0) && !skip) { SendResult(new FindInFilesEntry(item, displayPath, line, lineNumber, i, i + pattern.Length)); } } while (i >= 0); } } } } catch (Exception exception) { SendResult(new FindInFilesEntry(item, displayPath, String.Format("Unable to open: {0}", exception.Message), 0, 0, 0)); } if (lastFlush.AddMilliseconds(250) < DateTime.UtcNow) { Flush(); } }
public FindInFilesEntry(IFindInFilesItem item, string displayPath, string line, int lineNumber, int startChar, int endCharP1) { this.item = item; this.displayPath = displayPath; this.line = line; this.lineNumber = lineNumber; this.startChar = startChar; this.endCharP1 = endCharP1; }
public void SetSelection(IFindInFilesItem item, int startLine, int startChar, int endLine, int endCharP1) { SetSelection(startLine, startChar, endLine, endCharP1); }