/// <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 activeDocumentPath = GetActiveDocumentFilePath(ServiceProvider); ShowAddDocumentationWindow(activeDocumentPath, selection); }
private void ShowAddDocumentationWindow(string activeDocumentPath, TextViewSelection selection) { var documentationControl = new AddDocumentationWindow(); documentationControl.DataContext = new EditDocumentationViewModel(activeDocumentPath, selection); documentationControl.ShowDialog(); }
/// <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(); string activeDocumentPath = GetActiveDocumentFilePath(); ShowAddDocumentationWindow(activeDocumentPath, selection); }
private TextViewSelection GetSelection() { 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 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 void ShowAddDocumentationWindow(string documentPath, TextViewSelection seletion) { var documentationControl = new AddDocumentationWindow(); documentationControl.ShowDialog(); }
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 var hiddenTextManager = serviceProvider.GetService(typeof(SVsTextManager)) as IVsHiddenTextManager; IVsHiddenTextSession hiddenSession = null; IVsTextLines lines = null; IVsEnumHiddenRegions[] hiddenRegions = null; view.GetBuffer(out lines); int hRetVal = hiddenTextManager.GetHiddenTextSession( lines, out hiddenSession); if (hRetVal != 0) { hRetVal = hiddenTextManager.CreateHiddenTextSession( 0, lines, null, out hiddenSession); //if (hRetVal != 0) // return null; } if (hiddenSession != null) { var hidRegion = new NewHiddenRegion() { dwBehavior = (uint)HIDDEN_REGION_BEHAVIOR.hrbClientControlled, dwState = (uint)HIDDEN_REGION_STATE.hrsDefault, iType = (int)HIDDEN_REGION_TYPE.hrtConcealed, pszBanner = "Testing!!", tsHiddenText = new TextSpan() { iStartLine = startLine, iStartIndex = startColumn, iEndLine = endLine, iEndIndex = endColumn } }; hiddenSession.AddHiddenRegions(0, 1, new[] { hidRegion }, hiddenRegions); } 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); }