예제 #1
0
        public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            if (Keyboard.Modifiers != ModifierKeys.Control)
            {
                return(new QuickInfoItem(null, QuickInfoOverrider.CreateOverrider(session).Control));
            }
            return(null);
        }
예제 #2
0
 public void AugmentQuickInfoSession(IQuickInfoSession session, IList <Object> qiContent, out ITrackingSpan applicableToSpan)
 {
     if ((Config.Instance.QuickInfoMaxWidth > 0 || Config.Instance.QuickInfoMaxHeight > 0) &&
         System.Windows.Input.Keyboard.Modifiers != System.Windows.Input.ModifierKeys.Control
         )
     {
         QuickInfoOverrider.CreateOverrider(qiContent)
         .LimitQuickInfoItemSize(qiContent);
     }
     applicableToSpan = null;
 }
예제 #3
0
            /// <summary>Hack into the default QuickInfo panel and provides click and go feature for symbols.</summary>
            public void ApplyClickAndGo(ISymbol symbol)
            {
                if (symbol == null)
                {
                    return;
                }
                var description = MainDesciption;

                if (description == null)
                {
                    return;
                }
                if (symbol.IsImplicitlyDeclared)
                {
                    symbol = symbol.ContainingType;
                }
                QuickInfoOverrider.ApplyClickAndGo(symbol, description);
            }
예제 #4
0
                void FixQuickInfo(StackPanel infoPanel)
                {
                    var doc = infoPanel.GetFirstVisualChild <StackPanel>();

                    if (doc == null)
                    {
                        return;
                    }
                    var titlePanel = infoPanel.GetFirstVisualChild <WrapPanel>();

                    if (titlePanel == null)
                    {
                        return;
                    }
                    titlePanel.HorizontalAlignment = HorizontalAlignment.Stretch;
                    doc.HorizontalAlignment        = HorizontalAlignment.Stretch;

                    var icon      = infoPanel.GetFirstVisualChild <CrispImage>();
                    var signature = infoPanel.GetFirstVisualChild <TextBlock>();

                    // beautify the title panel
                    if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.AlternativeStyle))
                    {
                        var b = doc.GetParent <Border>();
                        if (b != null && icon != null && signature != null)
                        {
                            b.Margin              = __DocPanelBorderMargin;
                            titlePanel.Margin     = __TitlePanelMargin;
                            titlePanel.Background = ThemeHelper.ToolWindowBackgroundBrush.Alpha(0.5);
                            doc.Margin            = __DocMargin;
                            icon.Margin           = __IconMargin;
                            signature.Margin      = __SignatureMargin;
                        }
                    }

                    // replace the default XML doc
                    var items = doc.Children;

                    if (DocElement != null)
                    {
                        try {
                            // sequence of items in default XML Doc panel:
                            // 1. summary
                            // 2. type parameter
                            // 3. usage
                            // 4. exception
                            if (items.Count > 1 && items[1] is TextBlock)
                            {
                                items.RemoveAt(1);
                                items.Insert(1, DocElement);
                            }
                            else
                            {
                                items.Add(DocElement);
                            }
                        }
                        catch (InvalidOperationException) {
                            // ignore exception: doc.Children was changed by another thread
                        }
                    }
                    if (ExceptionDoc != null)
                    {
                        try {
                            if (items.Count > 1 && items[items.Count - 1] is TextBlock)
                            {
                                items.RemoveAt(items.Count - 1);
                            }
                            items.Add(ExceptionDoc);
                        }
                        catch (InvalidOperationException) {
                            // ignore exception: doc.Children was changed by another thread
                        }
                    }

                    if (icon != null && signature != null)
                    {
                        // apply click and go feature
                        if (ClickAndGoSymbol != null)
                        {
                            QuickInfoOverrider.ApplyClickAndGo(ClickAndGoSymbol, signature);
                        }
                        // fix the width of the signature part to prevent it from falling down to the next row
                        if (Config.Instance.QuickInfoMaxWidth > 0)
                        {
                            //wrapPanel.MaxWidth = Config.Instance.QuickInfoMaxWidth;
                            //signature.HorizontalAlignment = HorizontalAlignment.Left;
                            signature.MaxWidth = Config.Instance.QuickInfoMaxWidth - icon.Width - 30;
                        }
                    }
                }
예제 #5
0
                void FixQuickInfo(StackPanel infoPanel)
                {
                    var titlePanel = infoPanel.GetFirstVisualChild <WrapPanel>();

                    if (titlePanel == null)
                    {
                        return;
                    }
                    var doc = titlePanel.GetParent <StackPanel>();

                    if (doc == null)
                    {
                        return;
                    }
                    var v16_1orLater = titlePanel.GetParent <ItemsControl>().GetParent <ItemsControl>() != null;

                    titlePanel.HorizontalAlignment = HorizontalAlignment.Stretch;
                    doc.HorizontalAlignment        = HorizontalAlignment.Stretch;

                    var icon      = infoPanel.GetFirstVisualChild <CrispImage>();
                    var signature = infoPanel.GetFirstVisualChild <TextBlock>();

                    // beautify the title panel
                    if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.AlternativeStyle))
                    {
                        if (icon != null)
                        {
                            infoPanel.GetParent <Border>().Background = new VisualBrush(CreateEnlargedIcon(icon))
                            {
                                Opacity    = 0.3,
                                AlignmentX = AlignmentX.Right,
                                AlignmentY = AlignmentY.Bottom,
                                TileMode   = TileMode.None,
                                Stretch    = Stretch.None
                            };
                            icon.Visibility = Visibility.Collapsed;
                        }
                        if (signature != null)
                        {
                            var list = (IList)signature.Inlines;
                            for (var i = 0; i < list.Count; i++)
                            {
                                if (list[i] is Hyperlink link)
                                {
                                    var r = link.Inlines.FirstInline as Run;
                                    if (r != null)
                                    {
                                        list[i] = new Run {
                                            Text = r.Text, Foreground = r.Foreground, Background = r.Background
                                        };
                                    }
                                }
                            }
                        }
                        var c = infoPanel.GetParent <Border>();
                        c.Margin          = __DocPanelBorderMargin;
                        c.Padding         = __DocPanelBorderPadding;
                        c.MinHeight       = 50;
                        titlePanel.Margin = __TitlePanelMargin;
                    }

                    #region Override documentation
                    // https://github.com/dotnet/roslyn/blob/version-3.0.0/src/Features/Core/Portable/QuickInfo/CommonSemanticQuickInfoProvider.cs
                    // replace the default XML doc
                    // sequence of items in default XML Doc panel:
                    // 1. summary
                    // 2. generic type parameter
                    // 3. anonymous types
                    // 4. availability warning
                    // 5. usage
                    // 6. exception
                    // 7. captured variables
                    var items = doc.IsItemsHost ? (IList)doc.GetParent <ItemsControl>().Items : doc.Children;
                    if (KeepBuiltInXmlDoc == false)
                    {
                        ClearDefaultDocumentationItems(doc, v16_1orLater, items);
                    }
                    if (DocElement != null)
                    {
                        OverrideDocElement(doc, v16_1orLater, items);
                    }
                    if (ExceptionDoc != null)
                    {
                        OverrideExceptionDocElement(doc, v16_1orLater, items);
                    }
                    #endregion

                    if (icon != null && signature != null)
                    {
                        // apply click and go feature
                        if (ClickAndGoSymbol != null)
                        {
                            QuickInfoOverrider.ApplyClickAndGo(ClickAndGoSymbol, TextBuffer, signature, QuickInfoSession);
                        }
                        // fix the width of the signature part to prevent it from falling down to the next row
                        if (Config.Instance.QuickInfoMaxWidth >= 100)
                        {
                            signature.MaxWidth = Config.Instance.QuickInfoMaxWidth - icon.Width - 30;
                        }
                    }
                }
예제 #6
0
                void FixQuickInfo(StackPanel infoPanel)
                {
                    var doc = infoPanel.GetFirstVisualChild <StackPanel>();

                    if (doc == null)
                    {
                        return;
                    }
                    var wrapPanel = infoPanel.GetFirstVisualChild <WrapPanel>();

                    if (wrapPanel == null)
                    {
                        return;
                    }
                    var icon      = infoPanel.GetFirstVisualChild <Microsoft.VisualStudio.Imaging.CrispImage>();
                    var signature = infoPanel.GetFirstVisualChild <TextBlock>();

                    // replace the default XML doc
                    if (DocElement != null)
                    {
                        // todo: apply decoratives lines between doc and other parts with a WPF template
                        //DocElement = new StackPanel {
                        //	Children = {
                        //		CreateDecorativeLine(doc),
                        //		DocElement,
                        //		CreateDecorativeLine(doc)
                        //	}
                        //};
                        try {
                            if (doc.Children.Count > 1 && doc.Children[1] is TextBlock)
                            {
                                doc.Children.RemoveAt(1);
                                doc.Children.Insert(1, DocElement);
                            }
                            else
                            {
                                doc.Children.Add(DocElement);
                            }
                        }
                        catch (InvalidOperationException) {
                            // ignore exception: doc.Children was changed by another thread
                        }
                    }


                    if (icon != null && signature != null)
                    {
                        // apply click and go feature
                        if (ClickAndGoSymbol != null)
                        {
                            QuickInfoOverrider.ApplyClickAndGo(ClickAndGoSymbol, signature);
                        }

                        // fix the width of the signature part to prevent it from falling down to the next row
                        if (Config.Instance.QuickInfoMaxWidth > 0)
                        {
                            wrapPanel.MaxWidth = Config.Instance.QuickInfoMaxWidth;
                            signature.MaxWidth = Config.Instance.QuickInfoMaxWidth - icon.Width - 10;
                        }
                    }
                    System.Windows.Shapes.Line CreateDecorativeLine(StackPanel docPanel)
                    {
                        return(new System.Windows.Shapes.Line {
                            Stroke = ThemeHelper.MenuGlyphBackgroundBrush,
                            StrokeThickness = 1,
                            StrokeDashArray = new DoubleCollection {
                                4, 2
                            },
                            X1 = 0,
                            X2 = docPanel.DesiredSize.Width,
                            Y1 = 3,
                            Y2 = 3,
                            Height = 5,
                            MaxWidth = Config.Instance.QuickInfoMaxWidth
                        });
                    }
                }
예제 #7
0
                void FixQuickInfo(StackPanel infoPanel)
                {
                    var titlePanel = infoPanel.GetFirstVisualChild <WrapPanel>();

                    if (titlePanel == null)
                    {
                        return;
                    }
                    var doc = titlePanel.GetParent <StackPanel>();

                    if (doc == null)
                    {
                        return;
                    }
                    var v16_1orLater = titlePanel.GetParent <ItemsControl>().GetParent <ItemsControl>() != null;

                    titlePanel.HorizontalAlignment = HorizontalAlignment.Stretch;
                    doc.HorizontalAlignment        = HorizontalAlignment.Stretch;

                    var icon      = infoPanel.GetFirstVisualChild <CrispImage>();
                    var signature = infoPanel.GetFirstVisualChild <TextBlock>();

                    // beautify the title panel
                    if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.AlternativeStyle))
                    {
                        if (icon != null)
                        {
                            var bgIcon = CreateEnlargedIcon(icon);
                            infoPanel.GetParent <Border>().Background = new VisualBrush(bgIcon)
                            {
                                Opacity    = 0.3,
                                AlignmentX = AlignmentX.Right,
                                AlignmentY = AlignmentY.Bottom,
                                TileMode   = TileMode.None,
                                Stretch    = Stretch.None
                            };
                            icon.Visibility = Visibility.Collapsed;
                        }
                        var c = infoPanel.GetParent <Border>();
                        c.Margin          = __DocPanelBorderMargin;
                        c.Padding         = __DocPanelBorderPadding;
                        c.MinHeight       = 50;
                        titlePanel.Margin = __TitlePanelMargin;
                    }

                    // replace the default XML doc
                    // sequence of items in default XML Doc panel:
                    // 1. summary
                    // 2. type parameter
                    // 3. usage
                    // 4. exception
                    var items = doc.IsItemsHost ? (System.Collections.IList)doc.GetParent <ItemsControl>().Items : doc.Children;

                    if (DocElement != null)
                    {
                        try {
                            if (items.Count > 1 && items[1] is TextBlock)
                            {
                                items.RemoveAt(1);
                                items.Insert(1, DocElement);
                            }
                            else
                            {
                                items.Add(DocElement);
                            }
                            var myDoc = DocElement as ThemedTipDocument;
                            if (myDoc != null)
                            {
                                items = doc.GetParent <ItemsControl>()?.Items;
                                if (v16_1orLater && items != null && myDoc.Tag is int)
                                {
                                    // used the value from XmlDocRenderer.ParagraphCount to remove builtin paragraphs
                                    for (int i = (int)myDoc.Tag - 1; i >= 0; i--)
                                    {
                                        items.RemoveAt(1);
                                    }
                                }
                                myDoc.ApplySizeLimit();
                            }
                        }
                        catch (InvalidOperationException) {
                            // ignore exception: doc.Children was changed by another thread
                        }
                    }
                    if (ExceptionDoc != null)
                    {
                        if (v16_1orLater)
                        {
                            items = doc.GetParent <ItemsControl>().Items;
                        }
                        try {
                            if (items.Count > 1 &&
                                (v16_1orLater && items[items.Count - 1] is StackPanel || items[items.Count - 1] is TextBlock))
                            {
                                items.RemoveAt(items.Count - 1);
                            }
                            items.Add(ExceptionDoc);
                            //todo move this to ApplySizeLimit
                            (ExceptionDoc as ThemedTipDocument)?.ApplySizeLimit();
                        }
                        catch (InvalidOperationException) {
                            // ignore exception: doc.Children was changed by another thread
                        }
                    }

                    if (icon != null && signature != null)
                    {
                        // apply click and go feature
                        if (ClickAndGoSymbol != null)
                        {
                            QuickInfoOverrider.ApplyClickAndGo(ClickAndGoSymbol, signature);
                        }
                        // fix the width of the signature part to prevent it from falling down to the next row
                        if (Config.Instance.QuickInfoMaxWidth > 0)
                        {
                            signature.MaxWidth = Config.Instance.QuickInfoMaxWidth - icon.Width - 30;
                        }
                    }
                }