/// <summary> /// 選択中の行を行選択状態にします。 /// </summary> private static void SelectLines(TextSelection selection) { var bottom = selection.BottomLine; selection.MoveToDisplayColumn(selection.TopLine, 1, false); selection.MoveToDisplayColumn(bottom, 0, true); selection.EndOfLine(true); }
private void ChangeActiveDocument(CodeElement definingElement) { Window window = definingElement.ProjectItem.Open(EnvDTE.Constants.vsViewKindCode); window.Activate(); TextSelection currentPoint = window.Document.Selection as TextSelection; currentPoint.MoveToDisplayColumn(definingElement.StartPoint.Line, definingElement.StartPoint.DisplayColumn); }
private void ApplyInline(TextSelection selection) { var closeUndoContext = false; if (!selection.DTE.UndoContext.IsOpen) { selection.BeginUpdate("Surround With " + Name); closeUndoContext = true; } var sb = new StringBuilder(); sb.Append(_preText[0]); sb.Append(selection.Text); sb.Append(_postText[0]); var line = selection.TopLine; var col = selection.TopPoint.DisplayColumn; selection.Delete(); selection.Insert(sb.ToString()); if (_caretLine >= 0) { selection.MoveToDisplayColumn(line, col + _caretCol - 1); } else { selection.MoveToDisplayColumn(line, col, true); } if (closeUndoContext) { selection.EndUpdate(); } }
/// <summary> /// 选择当前行 /// </summary> public void SelectLine() { try { // Retrieve document selection TextSelection sel = (TextSelection)_dte.ActiveWindow.Document.Selection; // Move to line sel.MoveToDisplayColumn(sel.CurrentLine, 1, false); // Select from start to end sel.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, false); sel.EndOfLine(true); } catch (ArgumentException) { } }
public void Apply(TextSelection selection) { if (Inline) { ApplyInline(selection); return; } var closeUndoContext = false; if (!selection.DTE.UndoContext.IsOpen) { selection.BeginUpdate("Surround With " + Name); closeUndoContext = true; } if (_extendSelection) { selection.ExtendToFullLine(); } var indentSize = selection.Text.Lines().Where(l => !string.IsNullOrWhiteSpace(l)).Min(l => l.Length - l.TrimStart().Length); var content = selection.Text.Lines(); var leadingSpace = new string(' ', indentSize); var indent = new string(' ', selection.Parent.IndentSize); var sb = new StringBuilder(); foreach (var s in _preText) { sb.Append(leadingSpace).AppendLine(s); } foreach (var s in content) { if (_indentSelection) { sb.Append(indent); } sb.AppendLine(s); } foreach (var s in _postText) { sb.Append(leadingSpace).AppendLine(s); } var line = selection.TopLine; var col = selection.TopPoint.DisplayColumn; selection.Delete(); selection.Insert(sb.ToString()); if (_caretLine >= _preText.Length) { selection.MoveToLineAndOffset(line + _caretLine + content.Count, _caretCol + indentSize, false); } else if (_caretLine >= 0) { selection.MoveToLineAndOffset(line + _caretLine, _caretCol + indentSize, false); } else { selection.MoveToDisplayColumn(line, col, true); } if (closeUndoContext) { selection.EndUpdate(); } }
public static bool openSolutionFile(string fileName, string lineAndColumnNumber, Solution solution) { List <ProjectItem> files = new List <ProjectItem>(); matchProjectItems(fileName, files); ProjectItem selectedProjectItem = null; if (files.Count == 0) { MessageBox.Show("No matching files found for " + fileName, Constants.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (files.Count > 1) { FileListPicker picker = new FileListPicker(files); if (DialogResult.OK == picker.ShowDialog()) { selectedProjectItem = picker.SelectedFile; } } else { selectedProjectItem = files[0]; } if (selectedProjectItem == null) { return(false); } try { int?lineNo = null; int?columnNo = null; if (lineAndColumnNumber != null) { string lineNoStr = lineAndColumnNumber.Contains(",") ? lineAndColumnNumber.Substring(0, lineAndColumnNumber.IndexOf(',')) : lineAndColumnNumber; string columnNumberStr = lineAndColumnNumber.Contains(",") ? lineAndColumnNumber.Substring(lineAndColumnNumber.IndexOf(',') + 1) : null; lineNo = int.Parse(lineNoStr); if (columnNumberStr != null) { columnNo = int.Parse(columnNumberStr); } } Window w = selectedProjectItem.Open(DteConstants.vsViewKindCode); w.Visible = true; w.Document.Activate(); TextSelection sel = w.DTE.ActiveDocument.Selection as TextSelection; if (sel != null) { sel.SelectAll(); if (lineNo.HasValue) { // sometimes our current copy of the file is shorter than the line number that // the compiler reports for errors and bad HRESULT is returned from COM in this case. // Let's silently catch it here try { sel.MoveToDisplayColumn(lineNo.Value, columnNo.HasValue ? columnNo.Value : 0, false); sel.Cancel(); return(true); } catch (Exception e) { sel.Cancel(); PlvsUtils.showError("Unable to navigate to line " + lineNo.Value + " - no such line number in the file", e); } } else { return(true); } } else { throw new Exception("Unable to retrieve text selection for the document"); } } catch (Exception ex) { PlvsUtils.showError("Unable to open the specified file", ex); } return(false); }