コード例 #1
0
 object GenerateTooltip(ReferenceSegment segment)
 {
     if (segment.Reference is Mono.Cecil.Cil.OpCode)
     {
         Mono.Cecil.Cil.OpCode code           = (Mono.Cecil.Cil.OpCode)segment.Reference;
         string encodedName                   = code.Code.ToString();
         string opCodeHex                     = code.Size > 1 ? string.Format("0x{0:x2}{1:x2}", code.Op1, code.Op2) : string.Format("0x{0:x2}", code.Op2);
         XmlDocumentationProvider docProvider = XmlDocLoader.MscorlibDocumentation;
         if (docProvider != null)
         {
             string documentation = docProvider.GetDocumentation("F:System.Reflection.Emit.OpCodes." + encodedName);
             if (documentation != null)
             {
                 XmlDocRenderer renderer = new XmlDocRenderer();
                 renderer.AppendText(string.Format("{0} ({1}) - ", code.Name, opCodeHex));
                 renderer.AddXmlDocumentation(documentation);
                 return(renderer.CreateTextBlock());
             }
         }
         return(string.Format("{0} ({1})", code.Name, opCodeHex));
     }
     else if (segment.Reference is MemberReference)
     {
         MemberReference mr = (MemberReference)segment.Reference;
         // if possible, resolve the reference
         if (mr is TypeReference)
         {
             mr = ((TypeReference)mr).Resolve() ?? mr;
         }
         else if (mr is MethodReference)
         {
             mr = ((MethodReference)mr).Resolve() ?? mr;
         }
         XmlDocRenderer renderer = new XmlDocRenderer();
         renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(mr));
         try {
             XmlDocumentationProvider docProvider = XmlDocLoader.LoadDocumentation(mr.Module);
             if (docProvider != null)
             {
                 string documentation = docProvider.GetDocumentation(XmlDocKeyProvider.GetKey(mr));
                 if (documentation != null)
                 {
                     renderer.AppendText(Environment.NewLine);
                     renderer.AddXmlDocumentation(documentation);
                 }
             }
         } catch (XmlException) {
             // ignore
         }
         return(renderer.CreateTextBlock());
     }
     return(null);
 }
コード例 #2
0
        /// <summary>
        /// Jumps to the definition referred to by the <see cref="ReferenceSegment"/>.
        /// </summary>
        internal void JumpToReference(ReferenceSegment referenceSegment)
        {
            object reference = referenceSegment.Reference;

            if (referenceSegment.IsLocal)
            {
                ClearLocalReferenceMarks();
                if (references != null)
                {
                    foreach (var r in references)
                    {
                        if (reference.Equals(r.Reference))
                        {
                            var mark = textMarkerService.Create(r.StartOffset, r.Length);
                            mark.BackgroundColor = r.IsLocalTarget ? Colors.LightSeaGreen : Colors.GreenYellow;
                            localReferenceMarks.Add(mark);
                        }
                    }
                }
                return;
            }
            if (definitionLookup != null)
            {
                int pos = definitionLookup.GetDefinitionPosition(reference);
                if (pos >= 0)
                {
                    textEditor.TextArea.Focus();
                    textEditor.Select(pos, 0);
                    textEditor.ScrollTo(textEditor.TextArea.Caret.Line, textEditor.TextArea.Caret.Column);
                    Dispatcher.UIThread.InvokeAsync(new Action(
                                                        delegate {
                        CaretHighlightAdorner.DisplayCaretHighlightAnimation(textEditor.TextArea);
                    }), DispatcherPriority.Background);
                    return;
                }
            }
            MainWindow.Instance.JumpToReference(reference);
        }
コード例 #3
0
        void TextViewMouseHover(object sender, PointerEventArgs e)
        {
            TextViewPosition?position = GetPositionFromMousePosition(e.Device);

            if (position == null)
            {
                return;
            }
            int offset = textEditor.Document.GetOffset(position.Value.Location);

            if (referenceElementGenerator.References == null)
            {
                return;
            }
            ReferenceSegment seg = referenceElementGenerator.References.FindSegmentsContaining(offset).FirstOrDefault();

            if (seg == null)
            {
                return;
            }
            object content = GenerateTooltip(seg);

            if (tooltip != null)
            {
                ToolTip.SetIsOpen(this, false);
            }
            //tooltip.IsOpen = false;
            if (content != null)
            {
                tooltip = new ToolTip()
                {
                    Content = content
                };
                ToolTip.SetIsOpen(this, true);
            }
        }
コード例 #4
0
 internal void JumpToReference(ReferenceSegment referenceSegment)
 {
     referenceClicked(referenceSegment);
 }
コード例 #5
0
 /// <summary>
 /// Creates a visual line text element with the specified length.
 /// It uses the <see cref="ITextRunConstructionContext.VisualLine"/> and its
 /// <see cref="VisualLineElement.RelativeTextOffset"/> to find the actual text string.
 /// </summary>
 public VisualLineReferenceText(VisualLine parentVisualLine, int length, ReferenceElementGenerator parent, ReferenceSegment referenceSegment) : base(parentVisualLine, length)
 {
     this.parent           = parent;
     this.referenceSegment = referenceSegment;
 }
コード例 #6
0
 /// <summary>
 /// Filters all ReferenceSegments that are no real links.
 /// </summary>
 bool IsLink(ReferenceSegment referenceSegment)
 {
     return(true);
 }