/// <summary> /// The SendEmailTo. /// </summary> /// <param name="activeDocument">The activeDocument<see cref="Document" />.</param> /// <param name="selection">The selection<see cref="TextViewSelection" />.</param> private void SendEmailTo(Document activeDocument, TextViewSelection selection) { ThreadHelper.ThrowIfNotOnUIThread(); var selectionText = string.Empty; if (selection.Text.Length == 0) { selectionText = File.ReadAllText(activeDocument.FullName); } else { selectionText = selection.Text; } if (selectionText?.Length > 18000) { selectionText = "-- Content is trimmed due to large size -- \n\n" + selectionText.Substring(0, 18000); } string command = string.Format("mailto:?subject={0}&body={1}", Uri.EscapeDataString("Check this Code Snippet : " + activeDocument.Name), Uri.EscapeDataString(selectionText)); System.Diagnostics.Process.Start(command); }
/// <summary> /// 获取在获得文档中选中的位置和内容 /// </summary> /// <param name="serviceProvider"></param> /// <returns></returns> public static Du.VS.Core.TextViewSelection GetSelection(this IServiceProvider serviceProvider) { var ServiceResult = serviceProvider.GetService(typeof(SVsTextManager)); // service.Wait(); var textManager = ServiceResult as IVsTextManager2; IVsTextView view; int result = textManager.GetActiveView2(1, null, (uint)_VIEWFRAMETYPE.vftCodeWindow, out view); //获取缓存视图 IVsTextLines lines; view.GetBuffer(out lines); //获取选中位置 view.GetSelection(out int startLine, out int startColumn, out int endLine, out int endColumn);//end could be before beginning lines.GetPositionOfLineIndex(startLine, startColumn, out int StartPostion); lines.GetPositionOfLineIndex(endLine, endColumn, out int EndPostion); var start = new TextViewPosition(startLine, startColumn, StartPostion); var end = new TextViewPosition(endLine, endColumn, EndPostion); view.GetSelectedText(out string selectedText); TextViewSelection selection = new TextViewSelection(start, end, selectedText); return(selection); }
private void codeProvider_Apply(object sender, ApplyContentEventArgs ea) { //select the entire block that belongs to the active element. _activeElement.SelectFullBlock(); //_fullBlockText = Environment.NewLine + CodeRush.Selection.Text; //CodeRush.Selection.Delete(); _activeBlock = CodeRush.TextViews.Active.Selection; //get the document for the parent class and activate it. Document parentDocument = CodeRush.Documents.Get(_parentClass.FileNode.Name); CodeRush.Documents.Activate(parentDocument); //now select the target location in the parent class' document. if(_parentClass.FirstChild == null) { //this is temporary. i would like to use the "cc" command in the dxcore but dont know how... actionHint.Color = Color.Orange; actionHint.Text = "Add a constructor first.."; actionHint.PointTo(_parentClass.NameRange.End.Line, _parentClass.NameRange.End.Offset); _activeBlock.Clear(); } else { targetPicker.Start(_parentClass.View as TextView,_parentClass.FirstChild); } }
private void ShowAddTestWindow(MethodsInspector methodsInspector, TextViewSelection selection) { var documentationControl = new AddTestWindow(methodsInspector); documentationControl.DataContext = new EditViewModel(selection); documentationControl.ShowDialog(); }
private void codeProvider_Apply(object sender, ApplyContentEventArgs ea) { //select the entire block that belongs to the active element. _activeElement.SelectFullBlock(); //_fullBlockText = Environment.NewLine + CodeRush.Selection.Text; //CodeRush.Selection.Delete(); _activeBlock = CodeRush.TextViews.Active.Selection; //get the document for the parent class and activate it. Document parentDocument = CodeRush.Documents.Get(_parentClass.FileNode.Name); CodeRush.Documents.Activate(parentDocument); //now select the target location in the parent class' document. if (_parentClass.FirstChild == null) { //this is temporary. i would like to use the "cc" command in the dxcore but dont know how... actionHint.Color = Color.Orange; actionHint.Text = "Add a constructor first.."; actionHint.PointTo(_parentClass.NameRange.End.Line, _parentClass.NameRange.End.Offset); _activeBlock.Clear(); } else { targetPicker.Start(_parentClass.View as TextView, _parentClass.FirstChild); } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); TextViewSelection selection = GetSelection(ServiceProvider); var activeDocument = GetActiveFile(ServiceProvider); SendEmailTo(activeDocument, selection); }
private bool IsValidSelection(LanguageElement element, TextViewSelection selection, SourceRange signatureRange) { if ((element == null) || (selection == null)) { return(false); } return(!selection.Exists || (element.Range.Equals(selection.Range) || ((element.Range.Start.Equals(selection.Range.End) && element.Range.End.Equals(selection.Range.Start)) || (signatureRange.Equals(selection.Range) || (signatureRange.Start.Equals(selection.Range.End) && signatureRange.End.Equals(selection.Range.Start)))))); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { TextViewSelection selection = GetSelection(ServiceProvider); string activeDocumentName = GetActiveDocumentFileName(ServiceProvider); var activeDllPath = GetActiveDocumentAssemblyPath(ServiceProvider); var methodInspector = new MethodsInspector(activeDocumentName, selection.Text, activeDllPath); methodInspector.SolutionFilePath = GetSolutionFilePath(ServiceProvider); ShowAddTestWindow(methodInspector, selection); }
protected override bool IsValidSelection(LanguageElement element, TextViewSelection selection) { if ((element == null) || (selection == null)) return false; if (selection.Exists) return false; var creationExpression = element.Parent as ObjectCreationExpression; return creationExpression != null && element.GetDeclaration() == null; }
private bool IsValidSelection(LanguageElement member, TextViewSelection selection, SourcePoint caret) { if ((member == null) || (selection == null)) { return(false); } if (selection.Exists) { return(false); } return(member.NameRange.Contains(caret) || CodeRush.Source.GetStartWordRange(member).Contains(caret)); }
private bool IsValidSelection(LanguageElement member, TextViewSelection selection, SourcePoint caret) { if ((member == null) || (selection == null)) { return false; } if (selection.Exists) { return false; } return (member.NameRange.Contains(caret) || CodeRush.Source.GetStartWordRange(member).Contains(caret)); }
protected override bool IsValidSelection(LanguageElement element, TextViewSelection selection) { if ((element == null) || (selection == null)) { return(false); } if (selection.Exists) { return(false); } var creationExpression = element.Parent as ObjectCreationExpression; return(creationExpression != null && element.GetDeclaration() == null); }
/// <summary> /// The GetSelection. /// </summary> /// <param name="serviceProvider">The serviceProvider<see cref="IServiceProvider" />.</param> /// <returns> /// The <see cref="TextViewSelection" />. /// </returns> private TextViewSelection GetSelection(IServiceProvider serviceProvider) { var service = serviceProvider.GetService(typeof(SVsTextManager)); var textManager = service as IVsTextManager2; IVsTextView view; textManager.GetActiveView2(1, null, (uint)_VIEWFRAMETYPE.vftCodeWindow, out view); view.GetSelection(out int startLine, out int startColumn, out int endLine, out int endColumn);//end could be before beginning var start = new TextViewPosition(startLine, startColumn); var end = new TextViewPosition(endLine, endColumn); view.GetSelectedText(out string selectedText); TextViewSelection selection = new TextViewSelection(start, end, selectedText); return(selection); }
private TextViewSelection GetSelection(IServiceProvider serviceProvider) { var service = serviceProvider.GetService(typeof(SVsTextManager)); var textManager = service as IVsTextManager2; IVsTextView view; int result = textManager.GetActiveView2(1, null, (uint)_VIEWFRAMETYPE.vftCodeWindow, out view); view.GetSelection(out int startLine, out int startColumn, out int endLine, out int endColumn);//end could be before beginning int ok = view.GetNearestPosition(startLine, startColumn, out int position1, out int piVirtualSpaces); ok = view.GetNearestPosition(endLine, endColumn, out int position2, out piVirtualSpaces); var startPosition = Math.Min(position1, position2); var endPosition = Math.Max(position1, position2); view.GetSelectedText(out string selectedText); TextViewSelection selection = new TextViewSelection(startPosition, endPosition, selectedText); return(selection); }
private bool GetAvailability(LanguageElement element, TextViewSelection selection, bool lineUp, TextView view) { HtmlElement activeHtmlElement = GetActiveHtmlElement(element, false); if ((activeHtmlElement == null) || !activeHtmlElement.HasAttributes) { return(false); } SourcePoint start = activeHtmlElement.Range.Start; SourcePoint end = activeHtmlElement.Range.End; if (activeHtmlElement.HasCloseTag && !(activeHtmlElement is AspDirective)) { end = activeHtmlElement.InnerRange.Start; } SourceRange signatureRange = new SourceRange(start, end); if (!selection.Exists && !signatureRange.Contains(CodeRush.Caret.SourcePoint)) { return(false); } if (((selection != null) && selection.Exists) && !IsValidSelection(activeHtmlElement, selection, signatureRange)) { return(false); } if ((element.HasErrors || HasErrorsInParent(element)) || HasErrorsInChildren(element)) { return(false); } return(GetBreakApartAvailability(activeHtmlElement, Options.KeepFirstAttribute, view)); }
protected abstract bool IsValidSelection(LanguageElement element, TextViewSelection selection);
public EditViewModel(TextViewSelection selection) : this() { this._selection = selection; }
private bool GetAvailability(LanguageElement element, TextViewSelection selection, bool lineUp, TextView view) { HtmlElement activeHtmlElement = GetActiveHtmlElement(element, false); if ((activeHtmlElement == null) || !activeHtmlElement.HasAttributes) { return false; } SourcePoint start = activeHtmlElement.Range.Start; SourcePoint end = activeHtmlElement.Range.End; if (activeHtmlElement.HasCloseTag && !(activeHtmlElement is AspDirective)) { end = activeHtmlElement.InnerRange.Start; } SourceRange signatureRange = new SourceRange(start, end); if (!selection.Exists && !signatureRange.Contains(CodeRush.Caret.SourcePoint)) { return false; } if (((selection != null) && selection.Exists) && !IsValidSelection(activeHtmlElement, selection, signatureRange)) { return false; } if ((element.HasErrors || HasErrorsInParent(element)) || HasErrorsInChildren(element)) { return false; } return GetBreakApartAvailability(activeHtmlElement, Options.KeepFirstAttribute, view); }
private bool IsValidSelection(LanguageElement element, TextViewSelection selection, SourceRange signatureRange) { if ((element == null) || (selection == null)) { return false; } return (!selection.Exists || (element.Range.Equals(selection.Range) || ((element.Range.Start.Equals(selection.Range.End) && element.Range.End.Equals(selection.Range.Start)) || (signatureRange.Equals(selection.Range) || (signatureRange.Start.Equals(selection.Range.End) && signatureRange.End.Equals(selection.Range.Start)))))); }
public EditDocumentationViewModel(string documentPath, TextViewSelection selection) : this() { this._documentPath = documentPath; this._selection = selection; }