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);
            }
        }
        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);
            }
        }
Esempio n. 3
0
        private void OnMouseHover(object sender, MouseEventArgs e)
        {
            TextViewPosition? position;
            try
            {
                position = TextArea.TextView.GetPositionFloor(e.GetPosition(TextArea.TextView) + TextArea.TextView.ScrollOffset);
            }
            catch (ArgumentOutOfRangeException)
            {
                // TODO: check why this happens
                e.Handled = true;
                return;
            }
            var args = new ToolTipRequestEventArgs { InDocument = position.HasValue };
            if (!position.HasValue || position.Value.Location.IsEmpty)
            {
                return;
            }

            args.LogicalPosition = position.Value.Location;

            RaiseEvent(args);

            if (args.ContentToShow == null) return;

            if (_toolTip == null)
            {
                _toolTip = new ToolTip { MaxWidth = 300 };
                _toolTip.Closed += ToolTipClosed;
                ToolTipService.SetInitialShowDelay(_toolTip, 0);
            }
            _toolTip.PlacementTarget = this; // required for property inheritance

            var stringContent = args.ContentToShow as string;
            if (stringContent != null)
            {
                _toolTip.Content = new TextBlock
                {
                    Text = stringContent,
                    TextWrapping = TextWrapping.Wrap
                };
            }
            else
            {
                _toolTip.Content = args.ContentToShow;
            }

            e.Handled = true;
            _toolTip.IsOpen = true;
        }