public static void ShowContextMenu(ContextMenuStrip contextMenu, DTE dte) { try { var serviceProvider = new ServiceProvider(dte as IServiceProvider); IVsUIShellOpenDocument sod = (IVsUIShellOpenDocument)serviceProvider.GetService(typeof(SVsUIShellOpenDocument)); IVsUIHierarchy targetHier; uint[] targetId = new uint[1]; IVsWindowFrame targetFrame; int isOpen; Guid viewId = new Guid(LogicalViewID.Primary); sod.IsDocumentOpen(null, 0, dte.ActiveWindow.Document.FullName, ref viewId, 0, out targetHier, targetId, out targetFrame, out isOpen); IVsTextView textView = VsShellUtilities.GetTextView(targetFrame); TextSelection selection = (TextSelection)dte.ActiveWindow.Document.Selection; Microsoft.VisualStudio.OLE.Interop.POINT[] interopPoint = new Microsoft.VisualStudio.OLE.Interop.POINT[1]; textView.GetPointOfLineColumn(selection.ActivePoint.Line, selection.ActivePoint.LineCharOffset, interopPoint); POINT p = new POINT(interopPoint[0].x, interopPoint[0].y); ClientToScreen(textView.GetWindowHandle(), p); contextMenu.Show(new Point(p.x, p.y)); } catch (Exception) { contextMenu.Show(); } }
public static bool GetActiveDocumentCursorScreenPos(out System.Windows.Point oPoint, bool bNextLine) { IVsTextManager oTextMgr = (IVsTextManager)((IServiceProvider)Common.Instance.Package).GetService(typeof(SVsTextManager)); if (oTextMgr != null) { IVsTextView oTextViewCurrent; oTextMgr.GetActiveView(1, null, out oTextViewCurrent); int iLine, iCol; oTextViewCurrent.GetCaretPos(out iLine, out iCol); if (bNextLine) { ++iLine; } Microsoft.VisualStudio.OLE.Interop.POINT[] pts = new Microsoft.VisualStudio.OLE.Interop.POINT[1]; oTextViewCurrent.GetPointOfLineColumn(iLine, iCol, pts); RECT oViewRect = new RECT(); GetWindowRect(oTextViewCurrent.GetWindowHandle(), ref oViewRect); oPoint = new System.Windows.Point(oViewRect.Left + pts[0].x, oViewRect.Top + pts[0].y); return(true); } oPoint = new System.Windows.Point(); return(false); }
// Available on Visual Studio 2015 void RequestCalloutDisplay(Guid clientId, Guid calloutId, string title, string message, bool isPermanentlyDismissible, Microsoft.VisualStudio.OLE.Interop.POINT anchor, Guid vsCommandGroupId, uint vsCommandId) { var tippingService = serviceProvider.GetService(typeof(SVsTippingService)); if (tippingService == null) { log.Error("Can't find {ServiceType}", typeof(SVsTippingService)); return; } Assumes.Present(tippingService); var parameterTypes = new Type[] { typeof(Guid), typeof(Guid), typeof(string), typeof(string), typeof(bool), typeof(Microsoft.VisualStudio.OLE.Interop.POINT), typeof(Guid), typeof(uint) }; var tippingServiceType = tippingService.GetType(); var method = tippingServiceType.GetInterfaces() .FirstOrDefault(i => i.GUID == IVsTippingServiceGuid)?.GetMethod("RequestCalloutDisplay", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, null, parameterTypes, null); if (method == null) { log.Error("Couldn't find method on {Type} with parameters {Parameters}", tippingServiceType, parameterTypes); return; } var arguments = new object[] { clientId, calloutId, title, message, isPermanentlyDismissible, anchor, vsCommandGroupId, vsCommandId }; method.Invoke(tippingService, arguments); }
public Point GetScreenPoint(int line, int column) { long pointKey = ((_visibleSpan.iStartLine & 0xFFFFL) << 32) | ((line & 0xFFFFL) << 16) | (column & 0xFFFFL); var screenPoint = Point.Empty; lock (_pointCacheSync) { if (_pointCache.ContainsKey(pointKey)) { screenPoint = _pointCache[pointKey]; } else { var p = new Microsoft.VisualStudio.OLE.Interop.POINT[1]; _view.GetPointOfLineColumn(line, column, p); screenPoint.X = p[0].x; screenPoint.Y = p[0].y; _pointCache.Add(pointKey, screenPoint); } } return(screenPoint); }
public void RequestCalloutDisplay(Guid calloutId, string title, string message, bool isPermanentlyDismissible, FrameworkElement targetElement, Guid vsCommandGroupId, uint vsCommandId) { var screenPoint = targetElement.PointToScreen(new Point(targetElement.ActualWidth / 2, 0)); var point = new Microsoft.VisualStudio.OLE.Interop.POINT { x = (int)screenPoint.X, y = (int)screenPoint.Y }; RequestCalloutDisplay(ClientId, calloutId, title, message, isPermanentlyDismissible, point, vsCommandGroupId, vsCommandId); }
// Available on Visual Studio 2015 void RequestCalloutDisplay(Guid clientId, Guid calloutId, string title, string message, bool isPermanentlyDismissible, Microsoft.VisualStudio.OLE.Interop.POINT anchor, Guid vsCommandGroupId, uint vsCommandId) { var tippingService = serviceProvider.GetService(typeof(SVsTippingService)); Assumes.Present(tippingService); var currentMethod = MethodBase.GetCurrentMethod(); var parameterTypes = currentMethod.GetParameters().Select(p => p.ParameterType).ToArray(); var method = tippingService.GetType().GetMethod(currentMethod.Name, parameterTypes); var arguments = new object[] { clientId, calloutId, title, message, isPermanentlyDismissible, anchor, vsCommandGroupId, vsCommandId }; method.Invoke(tippingService, arguments); }
public bool ShowHint(IVsTextView view, TextSpan hintSpan, Func <string, string> getHintContent, string hintText) { if (!IsHintsEnabled) { return(false); } var hWnd = view.GetWindowHandle(); int lineHeight; ErrorHelper.ThrowOnFailure(view.GetLineHeight(out lineHeight)); var ptStart = new Microsoft.VisualStudio.OLE.Interop.POINT[1]; var ptEnd = new Microsoft.VisualStudio.OLE.Interop.POINT[1]; ErrorHelper.ThrowOnFailure(view.GetPointOfLineColumn(hintSpan.iStartLine, hintSpan.iStartIndex, ptStart)); ErrorHelper.ThrowOnFailure(view.GetPointOfLineColumn(hintSpan.iEndLine, hintSpan.iEndIndex, ptEnd)); NemerleNativeMethods.ClientToScreen(hWnd, ref ptStart[0]); NemerleNativeMethods.ClientToScreen(hWnd, ref ptEnd[0]); var hintXml = "<hint>" + hintText.Replace("<unknown>", "<unknown>").Replace("\r", "") .Replace("\n", "<lb/>") + "</hint>"; var rect = new Rect(new Point(ptStart[0].x, ptStart[0].y), new Point(ptEnd[0].x, ptEnd[0].y + lineHeight)); if (Hint.IsOpen) { if (Hint.PlacementRect == rect) { Hint.Text = hintXml; return(true); } Hint.Close(); } // Prevent a hint showing when SmartTag is showed. if (IsIntersectedWithSmartTag(view, rect)) { return(true); } Hint.Show(hWnd, rect, getHintContent, hintXml); return(true); }
public bool ShowHint(IVsTextView view, TextSpan hintSpan, Func<string, string> getHintContent, string hintText) { if (ContextMenuActive) return false; var hWnd = view.GetWindowHandle(); int lineHeight; ErrorHelper.ThrowOnFailure(view.GetLineHeight(out lineHeight)); var ptStart = new Microsoft.VisualStudio.OLE.Interop.POINT[1]; var ptEnd = new Microsoft.VisualStudio.OLE.Interop.POINT[1]; ErrorHelper.ThrowOnFailure(view.GetPointOfLineColumn(hintSpan.iStartLine, hintSpan.iStartIndex, ptStart)); ErrorHelper.ThrowOnFailure(view.GetPointOfLineColumn(hintSpan.iEndLine, hintSpan.iEndIndex, ptEnd)); NemerleNativeMethods.ClientToScreen(hWnd, ref ptStart[0]); NemerleNativeMethods.ClientToScreen(hWnd, ref ptEnd[0]); var hintXml = "<hint>" + hintText.Replace("<unknown>", "<unknown>").Replace("\r", "") .Replace("\n", "<lb/>") + "</hint>"; var rect = new Rect(new Point(ptStart[0].x, ptStart[0].y), new Point(ptEnd[0].x, ptEnd[0].y + lineHeight)); if (Hint.IsOpen) { if (Hint.PlacementRect == rect) { Hint.Text = hintXml; return true; } Hint.Close(); } Hint.Show(hWnd, rect, getHintContent, hintXml); return true; }
public Point GetScreenPoint(int line, int column) { long pointKey = ((_visibleSpan.iStartLine & 0xFFFFL) << 32) | ((line & 0xFFFFL) << 16) | (column & 0xFFFFL); var screenPoint = Point.Empty; lock (_pointCacheSync) { if (_pointCache.ContainsKey(pointKey)) { screenPoint = _pointCache[pointKey]; } else { var p = new Microsoft.VisualStudio.OLE.Interop.POINT[1]; _view.GetPointOfLineColumn(line, column, p); screenPoint.X = p[0].x; screenPoint.Y = p[0].y; _pointCache.Add(pointKey, screenPoint); } } return screenPoint; }