예제 #1
0
            private DoxTokenTag FindSpanTag(System.Windows.Input.MouseEventArgs args)
            {
                try
                {
                    // find canavas
                    var    over   = System.Windows.Input.Mouse.PrimaryDevice.DirectlyOver;
                    Canvas canvas = over as Canvas;
                    if (canvas == null)
                    {
                        System.Windows.FrameworkElement elem = over as System.Windows.FrameworkElement;
                        while (elem != null && elem.Parent != null)
                        {
                            canvas = elem as Canvas;
                            if (canvas != null)
                            {
                                break;
                            }
                            elem = elem.Parent as System.Windows.FrameworkElement;
                        }
                    }
                    if (canvas == null)
                    {
                        return(null);
                    }

                    // get mouse position relative to canavas
                    System.Windows.Point pos = args.GetPosition(canvas);
                    // HitTestResult hitRes = VisualTreeHelper.HitTest(canvas, pos);

                    // find the line where the mouse hovers
                    var lines = this.WpfTextView.TextViewLines;
                    Microsoft.VisualStudio.Text.Formatting.ITextViewLine hitLine = null;
                    foreach (var line in lines)
                    {
                        if (line.Left < pos.X && line.Right > pos.X && line.Top < pos.Y && line.Bottom > pos.Y)
                        {
                            hitLine = line;
                            break;
                        }
                    }
                    if (hitLine == null)
                    {
                        return(null);
                    }

                    // find the positon in the line where the mouse hovers
                    SnapshotPoint?snapPt = hitLine.GetBufferPositionFromXCoordinate(pos.X);
                    if (snapPt == null)
                    {
                        return(null);
                    }

                    // find doxygen tag
                    DoxTokenTag spanInfo = DoxTokenTaggerHelper.TagHitTest(this.Aggregator, this.WpfTextView.TextSnapshot, snapPt.Value);
                    return(spanInfo);
                }
                catch { }
                return(null);
            }
예제 #2
0
        // \brief generqte list of tags from the text buffer
        void ReParse()
        {
            SnapshotSpan        bufferSpan   = new SnapshotSpan(Buffer.CurrentSnapshot, new Span(0, Buffer.CurrentSnapshot.Length));
            List <SnapshotSpan> testSpanList = new List <SnapshotSpan>();

            testSpanList.Add(bufferSpan);
            try
            {
                doxTags_ = DoxTokenTaggerHelper.GenerateTags(testSpanList);
            }
            catch
            {
                doxTags_ = null;
            }
        }
        //! \brief create Quickinfo content
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> qiContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            DoxUtil.CManager manager = DoxUtil.CManager.Manager;
            if (manager == null)
            {
                return;
            }

            // Map the trigger point down to our buffer.
            SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(SubjectBuffer.CurrentSnapshot);

            if (!subjectTriggerPoint.HasValue)
            {
                return;
            }

            ITextSnapshot currentSnapshot = subjectTriggerPoint.Value.Snapshot;
            DoxTokenTag   spanInfo        = DoxTokenTaggerHelper.TagHitTest(this.Aggregator, currentSnapshot, subjectTriggerPoint.Value);

            if (spanInfo == null)
            {
                return;
            }

            bool   isCmdKnown = spanInfo.Type != DoxTokenType.Cmd || spanInfo.WellKnown;
            string cmdName    = spanInfo.Name;

            if (spanInfo.Name.Length > 0 && (spanInfo.Name[0] == '@' || spanInfo.Name[0] == '\\'))
            {
                cmdName = spanInfo.Name.Substring(1);
            }

            var opt     = manager.Options;
            var colDflt = Color.FromRgb(128, 128, 128);
            var colCmd  = CmdClassifications.CmdColor;
            var colHRef = CmdClassifications.RefColor;
            var colInc  = CmdClassifications.IncludeColor;

            /*
             * try
             * {
             *      var cmdClassify = ClassificationRegistry.GetClassificationType(CmdClassifications.DoxCommand);
             *      if (cmdClassify!=null)
             *      {
             *
             *      }
             * }
             * catch { }
             */

            if (opt.GeneralQT)
            {
                // C# String Formatting Dictionary Intellisence
                // [http://stackoverflow.com/questions/39524387/c-sharp-string-formatting-dictionary-intellisence]
                var textBlock = new System.Windows.Controls.TextBlock {
                    TextWrapping = System.Windows.TextWrapping.NoWrap
                };
                if (isCmdKnown)
                {
                    AddText(textBlock, colDflt, false, false, "Doxygen Special Command  ");
                    AddText(textBlock, colCmd, true, false, "@" + cmdName);
                    AddText(textBlock, colDflt, false, false, "  [");
                    AddText(textBlock, colHRef, false, true, manager.Options.DoxCommadsHelpURL + "#cmd" + cmdName);
                    AddText(textBlock, colDflt, false, false, "]");
                }
                else
                {
                    AddText(textBlock, colDflt, false, false, "Unknown Doxygen Special Command  ");
                    AddText(textBlock, colDflt, true, false, "@" + cmdName);
                    AddText(textBlock, colDflt, false, false, ", see [");
                    AddText(textBlock, colHRef, false, true, manager.Options.DoxCommadsHelpURL);
                    AddText(textBlock, colDflt, false, false, "] for more information");
                }
                qiContent.Add(textBlock);
            }

            switch (spanInfo.Type)
            {
            case DoxTokenType.Cmd:
                // nothing to do
                break;

            case DoxTokenType.Ref:
                if (opt.RefQT)
                {
                    var refTextBlock = new System.Windows.Controls.TextBlock {
                        TextWrapping = System.Windows.TextWrapping.NoWrap
                    };
                    if (spanInfo.WellKnown)
                    {
                        AddText(refTextBlock, colDflt, false, false, "[");
                        AddText(refTextBlock, colHRef, false, true, spanInfo.Argument);
                        AddText(refTextBlock, colDflt, false, false, "]");
                    }
                    else
                    {
                        AddText(refTextBlock, colDflt, false, false, "unknown doxgen reference  ");
                        AddText(refTextBlock, colDflt, true, false, "spanInfo.Argument");
                    }
                    qiContent.Add(refTextBlock);
                }
                break;

            case DoxTokenType.Image:
                if (opt.ImageQT)
                {
                    if (spanInfo.WellKnown)
                    {
                        var imagePath = spanInfo.Argument;
                        AddImage(qiContent, imagePath);

                        qiContent.Add(CreateTextBlockHRef(colDflt, colHRef, "image file", "file:///" + imagePath));
                    }
                    else
                    {
                        var imgTextBlock = new System.Windows.Controls.TextBlock {
                            TextWrapping = System.Windows.TextWrapping.NoWrap
                        };
                        AddText(imgTextBlock, colDflt, false, false, "unknown image file  ");
                        AddText(imgTextBlock, colDflt, true, false, spanInfo.Argument);
                        qiContent.Add(imgTextBlock);
                        //var hlpURL = manager.FindDoxygenLink(DoxUtil.CManager.DoxRefAddImage, false);
                        //if (hlpURL != "")
                        //	qiContent.Add(CreateTextBlockHRef(colDflt, colHRef, "How to add an image to source code documentation", hlpURL));
                    }
                }
                break;

            case DoxTokenType.Dot:
                if (opt.DotQT)
                {
                    // create preview
                    string dotContent = spanInfo.ContentSpan.GetText();
                    var    previewImg = manager.GenerateDotGraphPreview(dotContent);
                    if (previewImg != null)
                    {
                        qiContent.Add(previewImg);
                    }

                    // add help URL
                    qiContent.Add(CreateTextBlockHRef(colDflt, colHRef, "Graphviz - Graph Visualization Software", DoxUtil.CManager.GraphvizHelpURL));
                }
                break;

            case DoxTokenType.DotFile:
                if (opt.DotQT)
                {
                    var dotTextBlock = new System.Windows.Controls.TextBlock {
                        TextWrapping = System.Windows.TextWrapping.NoWrap
                    };
                    if (spanInfo.WellKnown)
                    {
                        var dotPath    = spanInfo.Argument;
                        var previewImg = manager.GenerateDotFileGraphPreview(dotPath);
                        if (previewImg != null)
                        {
                            qiContent.Add(previewImg);
                        }
                    }
                    else
                    {
                        AddText(dotTextBlock, colDflt, false, false, "unknown dot graph file  ");
                        AddText(dotTextBlock, colDflt, true, false, spanInfo.Argument);
                    }
                    qiContent.Add(dotTextBlock);
                }
                break;

            case DoxTokenType.Msc:
                if (opt.MscQT)
                {
                    // create preview
                    string mscContent = spanInfo.ContentSpan.GetText();
                    var    previewImg = manager.GenerateMscGraphPreview("msc {\n" + mscContent + "\n}\n");
                    if (previewImg != null)
                    {
                        qiContent.Add(previewImg);
                    }

                    // add help URL
                    qiContent.Add(CreateTextBlockHRef(colDflt, colHRef, "Mscgen", DoxUtil.CManager.MscgenHelpURL));
                }
                break;

            case DoxTokenType.MscFile:
                if (opt.MscQT)
                {
                    var mscTextBlock = new System.Windows.Controls.TextBlock {
                        TextWrapping = System.Windows.TextWrapping.NoWrap
                    };
                    if (spanInfo.WellKnown)
                    {
                        var mscPath    = spanInfo.Argument;
                        var previewImg = manager.GenerateMscFileGraphPreview(mscPath);
                        if (previewImg != null)
                        {
                            qiContent.Add(previewImg);
                        }
                    }
                    else
                    {
                        AddText(mscTextBlock, colDflt, false, false, "unknown dot graph file  ");
                        AddText(mscTextBlock, colDflt, true, false, spanInfo.Argument);
                    }
                    qiContent.Add(mscTextBlock);
                }
                break;

            case DoxTokenType.DiaFile:
                // TODO $$$ not yet implemented
                break;

            case DoxTokenType.Uml:
                if (opt.PlantUmlQT)
                {
                    // create preview
                    string umlContent = spanInfo.ContentSpan.GetText();
                    var    previewImg = manager.GeneratePlatUMLPreview("@startuml\n" + umlContent + "\n@enduml");
                    if (previewImg != null)
                    {
                        qiContent.Add(previewImg);
                    }

                    // add help URL
                    qiContent.Add(CreateTextBlockHRef(colDflt, colHRef, "PlantUML in a nutshell", DoxUtil.CManager.PlanUMLHelpURL));
                }
                break;

            case DoxTokenType.LatexFormula:
                if (opt.LatexFormulaQT)
                {
                    // create preview
                    string latexFormula = spanInfo.ContentSpan.GetText();
                    var    previewImg   = manager.GenerateLatexFormulaPreview(latexFormula);
                    if (previewImg != null)
                    {
                        qiContent.Add(previewImg);
                    }

                    // add help URL
                    qiContent.Add(CreateTextBlockHRef(colDflt, colHRef, "LaTeX/Mathematics", DoxUtil.CManager.LatexHelpURL));
                }
                break;
            }

            if (qiContent.Count > 0)
            {
                applicableToSpan = currentSnapshot.CreateTrackingSpan(spanInfo.Span, SpanTrackingMode.EdgeInclusive);
            }
        }