void OnMouseHover(MouseEventArgs e) { ToolTipRequestEventArgs args = new ToolTipRequestEventArgs(editor); var pos = editor.GetPositionFromPoint(e.GetPosition(editor)); args.InDocument = pos.HasValue; if (pos.HasValue) { args.LogicalPosition = new TextLocation(pos.Value.Line, pos.Value.Column); } else { return; } DebuggerService.HandleToolTipRequest(args); if (args.ContentToShow != null) { var contentToShowITooltip = args.ContentToShow as ITooltip; if (contentToShowITooltip != null && contentToShowITooltip.ShowAsPopup) { if (!(args.ContentToShow is UIElement)) { throw new NotSupportedException("Content to show in Popup must be UIElement: " + args.ContentToShow); } if (popup == null) { popup = CreatePopup(); } if (TryCloseExistingPopup(false)) { // when popup content decides to close, close the popup contentToShowITooltip.Closed += delegate { popup.IsOpen = false; }; popup.Child = (UIElement)args.ContentToShow; //ICSharpCode.SharpDevelop.Debugging.DebuggerService.CurrentDebugger.IsProcessRunningChanged SetPopupPosition(popup, e); popup.IsOpen = true; } e.Handled = true; } } else { // close popup if mouse hovered over empty area if (popup != null) { e.Handled = true; } TryCloseExistingPopup(false); } }
/// <summary> /// Gets debugger tooltip information for the specified position. /// A descriptive string for the element or a DebuggerTooltipControl /// showing its current value (when in debugging mode) can be returned /// through the ToolTipRequestEventArgs.SetTooltip() method. /// </summary> public static void HandleToolTipRequest(ToolTipRequestEventArgs e) { if (!e.InDocument) return; var logicPos = e.LogicalPosition; var doc = (TextDocument)e.Editor.Document; var line = doc.GetLineByNumber(logicPos.Line); if (line.Offset + logicPos.Column >= doc.TextLength) return; var c = doc.GetText(line.Offset + logicPos.Column, 1); if (string.IsNullOrEmpty(c) || c == "\n" || c == "\t") return; string variable = ParserService.SimpleParseAt(doc.Text, doc.GetOffset(new TextLocation(logicPos.Line, logicPos.Column))); if (currentDebugger == null || !currentDebugger.IsDebugging || !currentDebugger.CanEvaluate) { e.ContentToShow = null; } else { try { e.ContentToShow = currentDebugger.GetTooltipControl(e.LogicalPosition, variable); } catch { return; } } // FIXME Do proper parsing // // using (var sr = new StringReader(doc.Text)) // { // var parser = new CSharpParser(); // parser.Parse(sr); // // IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(); // if (expressionFinder == null) // return; // var currentLine = doc.GetLine(logicPos.Y); // if (logicPos.X > currentLine.Length) // return; // string textContent = doc.Text; // ExpressionResult expressionResult = expressionFinder.FindFullExpression(textContent, doc.GetOffset(new TextLocation(logicPos.Line, logicPos.Column))); // string expression = (expressionResult.Expression ?? "").Trim(); // if (expression.Length > 0) { // // Look if it is variable // ResolveResult result = ParserService.Resolve(expressionResult, logicPos.Y, logicPos.X, e.Editor.FileName, textContent); // bool debuggerCanShowValue; // string toolTipText = GetText(result, expression, out debuggerCanShowValue); // if (Control.ModifierKeys == Keys.Control) { // toolTipText = "expr: " + expressionResult.ToString() + "\n" + toolTipText; // debuggerCanShowValue = false; // } // if (toolTipText != null) { // if (debuggerCanShowValue && currentDebugger != null) { // object toolTip = currentDebugger.GetTooltipControl(e.LogicalPosition, expressionResult.Expression); // if (toolTip != null) // e.SetToolTip(toolTip); // else // e.SetToolTip(toolTipText); // } else { // e.SetToolTip(toolTipText); // } // } // } // else { // #if DEBUG // if (Control.ModifierKeys == Keys.Control) { // e.SetToolTip("no expr: " + expressionResult.ToString()); // } // #endif // } // } }
/// <summary> /// Gets debugger tooltip information for the specified position. /// A descriptive string for the element or a DebuggerTooltipControl /// showing its current value (when in debugging mode) can be returned /// through the ToolTipRequestEventArgs.SetTooltip() method. /// </summary> public static void HandleToolTipRequest(ToolTipRequestEventArgs e) { if (!e.InDocument) return; var logicPos = e.LogicalPosition; var doc = (TextDocument)e.Editor.Document; var line = doc.GetLineByNumber(logicPos.Line); if (line.Offset + logicPos.Column >= doc.TextLength) return; var c = doc.GetText(line.Offset + logicPos.Column, 1); if (string.IsNullOrEmpty(c) || c == "\n" || c == "\t") return; string variable = ParserService.SimpleParseAt(doc.Text, doc.GetOffset(new TextLocation(logicPos.Line, logicPos.Column))); if (currentDebugger == null || !currentDebugger.IsDebugging || !currentDebugger.CanEvaluate) { e.ContentToShow = null; } else { try { e.ContentToShow = currentDebugger.GetTooltipControl(e.LogicalPosition, variable); } catch { return; } } }