Exemplo n.º 1
0
        public void HandleToolTipRequest(ToolTipRequestEventArgs args)
        {
            if (args.InDocument)
            {
                int offset = args.Editor.Document.GetOffset(args.LogicalPosition);

                FoldingManager foldings = args.Editor.GetService(typeof(FoldingManager)) as FoldingManager;
                if (foldings != null)
                {
                    var            foldingsAtOffset = foldings.GetFoldingsAt(offset);
                    FoldingSection collapsedSection = foldingsAtOffset.FirstOrDefault(section => section.IsFolded);

                    if (collapsedSection != null)
                    {
                        args.SetToolTip(GetTooltipTextForCollapsedSection(args, collapsedSection));
                    }
                }

                TextMarkerService textMarkerService = args.Editor.GetService(typeof(ITextMarkerService)) as TextMarkerService;
                if (textMarkerService != null)
                {
                    var         markersAtOffset   = textMarkerService.GetMarkersAtOffset(offset);
                    ITextMarker markerWithToolTip = markersAtOffset.FirstOrDefault(marker => marker.ToolTip != null);

                    if (markerWithToolTip != null)
                    {
                        args.SetToolTip(markerWithToolTip.ToolTip);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void HandleToolTipRequest(ToolTipRequestEventArgs e)
        {
            if (!(IsDebugging && CurrentProcess.IsPaused))
            {
                return;
            }
            if (CurrentStackFrame == null)
            {
                return;
            }
            if (!e.InDocument)
            {
                return;
            }
            var resolveResult = SD.ParserService.Resolve(e.Editor, e.LogicalPosition, CurrentStackFrame.AppDomain.Compilation);

            if (resolveResult == null)
            {
                return;
            }
            if (resolveResult is LocalResolveResult || resolveResult is MemberResolveResult)
            {
                string       text     = ResolveResultPrettyPrinter.Print(resolveResult);
                Func <Value> getValue = delegate {
                    ExpressionEvaluationVisitor eval = new ExpressionEvaluationVisitor(CurrentStackFrame, EvalThread, CurrentStackFrame.AppDomain.Compilation);
                    return(eval.Convert(resolveResult));
                };
                try {
                    var rootNode = new ValueNode(ClassBrowserIconService.LocalVariable, text, getValue);
                    e.SetToolTip(new DebuggerTooltipControl(rootNode));
                } catch (InvalidOperationException ex) {
                    SD.Log.Warn(ex);
                }
            }
        }
Exemplo n.º 3
0
        public void HandleToolTipRequest(ToolTipRequestEventArgs args)
        {
            if (!args.InDocument)
            {
                return;
            }
            var offset = _editor.Document.GetOffset(args.LogicalPosition);

            //FoldingManager foldings = _editor.GetService(typeof(FoldingManager)) as FoldingManager;
            //if (foldings != null)
            //{
            //    var foldingsAtOffset = foldings.GetFoldingsAt(offset);
            //    FoldingSection collapsedSection = foldingsAtOffset.FirstOrDefault(section => section.IsFolded);

            //    if (collapsedSection != null)
            //    {
            //        args.SetToolTip(GetTooltipTextForCollapsedSection(args, collapsedSection));
            //    }
            //}

            var markersAtOffset   = _textMarkerService.GetMarkersAtOffset(offset);
            var markerWithToolTip = markersAtOffset.FirstOrDefault(marker => marker.ToolTip != null);

            if (markerWithToolTip != null)
            {
                args.SetToolTip(markerWithToolTip.ToolTip);
            }
        }
Exemplo n.º 4
0
        private async Task AsyncToolTipRequest(ToolTipRequestEventArgs arg)
        {
            // TODO: consider invoking this with a delay, then showing the tool-tip without one
            var document = _roslynHost.GetDocument(_viewModel.DocumentId);
            var info     = await _quickInfoProvider.GetItemAsync(document, arg.Position, CancellationToken.None).ConfigureAwait(true);

            if (info != null)
            {
                arg.SetToolTip(info.Create());
            }
        }
        public void HandleToolTipRequest(ToolTipRequestEventArgs e)
        {
            if (e.ResolveResult == null)
            {
                return;
            }
            TypeResolveResult   trr = e.ResolveResult as TypeResolveResult;
            MemberResolveResult mrr = e.ResolveResult as MemberResolveResult;
            LocalResolveResult  lrr = e.ResolveResult as LocalResolveResult;

            if (trr != null && trr.Type.GetDefinition() != null)
            {
                e.SetToolTip(CreateTooltip(trr.Type));
            }
            else if (mrr != null)
            {
                e.SetToolTip(CreateTooltip(mrr.Member));
            }
            else if (lrr != null)
            {
                e.SetToolTip(new FlowDocumentTooltip(XmlDocFormatter.CreateTooltip(lrr.Variable)));
            }
        }
        public void HandleToolTipRequest(ToolTipRequestEventArgs e)
        {
            if (!e.InDocument)
            {
                return;
            }

            Location  logicPos = e.LogicalPosition;
            IDocument doc      = e.Editor.Document;

            if (logicPos.X > doc.GetLine(logicPos.Y).Length)
            {
                return;
            }

            ResourceResolveResult result = ResourceResolverService.Resolve(e.Editor.FileName, doc, logicPos.Y - 1, logicPos.X - 1, null);

            if (result != null && result.ResourceFileContent != null)
            {
                e.SetToolTip(ResourceResolverService.FormatResourceDescription(result.ResourceFileContent, result.Key));
            }
        }
Exemplo n.º 7
0
        private void EditorOnToolTipRequest(object sender, ToolTipRequestEventArgs args)
        {
            var offset = _document.GetOffset(args.LogicalPosition);

            //FoldingManager foldings = _editor.GetService(typeof(FoldingManager)) as FoldingManager;
            //if (foldings != null)
            //{
            //    var foldingsAtOffset = foldings.GetFoldingsAt(offset);
            //    FoldingSection collapsedSection = foldingsAtOffset.FirstOrDefault(section => section.IsFolded);

            //    if (collapsedSection != null)
            //    {
            //        args.SetToolTip(GetTooltipTextForCollapsedSection(args, collapsedSection));
            //    }
            //}

            var markersAtOffset   = GetMarkersAtOffset(offset);
            var markerWithToolTip = markersAtOffset.FirstOrDefault(marker => marker.ToolTip != null);

            if (markerWithToolTip != null)
            {
                args.SetToolTip(markerWithToolTip.ToolTip);
            }
        }
Exemplo n.º 8
0
        void TextEditorMouseHover(object sender, MouseEventArgs e)
        {
            Debug.Assert(sender == this);
            ToolTipRequestEventArgs args = new ToolTipRequestEventArgs(this.Adapter);
            var pos = GetPositionFromPoint(e.GetPosition(this));

            args.InDocument = pos.HasValue;
            if (pos.HasValue)
            {
                args.LogicalPosition = AvalonEditDocumentAdapter.ToLocation(pos.Value);
            }

            TextMarkerService textMarkerService = this.Adapter.GetService(typeof(ITextMarkerService)) as TextMarkerService;

            if (args.InDocument && textMarkerService != null)
            {
                var markersAtOffset = textMarkerService.GetMarkersAtOffset(args.Editor.Document.PositionToOffset(args.LogicalPosition.Line, args.LogicalPosition.Column));

                ITextMarker markerWithToolTip = markersAtOffset.FirstOrDefault(marker => marker.ToolTip != null);

                if (markerWithToolTip != null)
                {
                    args.SetToolTip(markerWithToolTip.ToolTip);
                }
            }

            if (!args.Handled)
            {
                // if request wasn't handled by a marker, pass it to the ToolTipRequestService
                ToolTipRequestService.RequestToolTip(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 popup was only first level, hovering somewhere else closes it
                    if (TryCloseExistingPopup(false))
                    {
                        // when popup content decides to close, close the popup
                        contentToShowITooltip.Closed += (closedSender, closedArgs) => { popup.IsOpen = false; };
                        popup.Child = (UIElement)args.ContentToShow;
                        //ICSharpCode.SharpDevelop.Debugging.DebuggerService.CurrentDebugger.IsProcessRunningChanged
                        SetPopupPosition(popup, e);
                        popup.IsOpen = true;
                    }
                    e.Handled = true;
                }
                else
                {
                    if (toolTip == null)
                    {
                        toolTip         = new ToolTip();
                        toolTip.Closed += ToolTipClosed;
                    }
                    toolTip.PlacementTarget = this;                     // required for property inheritance

                    if (args.ContentToShow is string)
                    {
                        toolTip.Content = new TextBlock
                        {
                            Text         = args.ContentToShow as string,
                            TextWrapping = TextWrapping.Wrap
                        };
                    }
                    else
                    {
                        toolTip.Content = args.ContentToShow;
                    }

                    toolTip.IsOpen = true;
                    e.Handled      = true;
                }
            }
            else
            {
                // close popup if mouse hovered over empty area
                if (popup != null)
                {
                    e.Handled = true;
                }
                TryCloseExistingPopup(false);
            }
        }
Exemplo n.º 9
0
        /// <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>
        internal static void HandleToolTipRequest(ToolTipRequestEventArgs e)
        {
            if (!e.InDocument)
            {
                return;
            }
            Location logicPos = e.LogicalPosition;
            var      doc      = e.Editor.Document;
            FileName fileName = e.Editor.FileName;

            IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(fileName);

            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.PositionToOffset(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, 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
            }
        }