Ejemplo n.º 1
0
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            // Ensure we can draw a glyph for this marker.
            if (tag == null || !(tag is ClippyTag))
            {
                return(null);
            }



            var clippy = tag as ClippyTag;
            //    Debug.WriteLine("Creating Glyph: " + clippy.GetDefinition().Line);
            //Debug.WriteLine("Drawing Glyph: {0} - {1}", clippy.GetDefinition().Line, clippy.GetDefinition().Type);

            var grid = clippy.GetEllipses();

            //grid.SetValue(Grid.ZIndexProperty, 999);
            ////grid.AddHandler(new RoutedEvent().HandlerType == )
            //grid.AddHandler(Grid.ContextMenuOpeningEvent, new RoutedEventHandler(OnOpen));
            //grid.AddHandler(Grid.PreviewMouseRightButtonUpEvent, new RoutedEventHandler(OnOpen));



            return(grid);
        }
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            var docTag         = tag as DocumentationTag;
            var documentedText = (docTag.TrackingSpan.GetText(docTag.TextBuffer.CurrentSnapshot));
            var numOfLines     = documentedText.Split('\n').Count();

            var lineHeight = line.Height;
            var grid       = new System.Windows.Controls.Grid()
            {
                Width  = lineHeight,
                Height = lineHeight * numOfLines
            };
            var rectangle = new Rectangle()
            {
                Fill   = new SolidColorBrush(Color.FromRgb(240, 222, 2)),
                Stroke = Brushes.Gray,
                Width  = lineHeight / 3,
                Height = lineHeight * numOfLines,
                HorizontalAlignment = HorizontalAlignment.Right
            };

            grid.Children.Add(rectangle);

            return(grid);
        }
Ejemplo n.º 3
0
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            ScoreGlyphTag scoreTag = tag as ScoreGlyphTag;

            if (scoreTag == null)
            {
                return(null);
            }

            var lineHeight = line.Height;
            var grid       = new System.Windows.Controls.Grid()
            {
                Width  = lineHeight,
                Height = lineHeight
            };

            grid.Children.Add(new Rectangle()
            {
                Fill   = Common.Colors.GetSeverityBrush(scoreTag.Value.Severity),
                Width  = lineHeight / 3,
                Height = lineHeight,
                HorizontalAlignment = HorizontalAlignment.Right
            });

            return(grid);
        }
Ejemplo n.º 4
0
 public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
 {
     try
     {
         // Ensure we can draw a glyph for this marker.)
         if (tag == null || !(tag is RiskTag))
         {
             return(null);
         }
         var             riskTag = tag as RiskTag;
         MarginUIElement element;
         if (riskTag.Signature.StringSignature == null)
         {
             return(null);
         }
         if (cache.TryGetValue(riskTag.Signature.StringSignature, out element))
         {
             element.Detach();
         }
         var g = new MarginUIElement(riskTag, line);
         g.Height = _glyphSize;
         g.Width  = _glyphSize;
         g.SetUIElements();
         cache.Remove(riskTag.Signature.StringSignature);
         cache.Add(riskTag.Signature.StringSignature, g);
         return(g);
     }
     catch (Exception exception)
     {
         Logger.Write("RiskGlyphFactory Exception");
         Logger.Write(exception);
         return(null);
     }
 }
Ejemplo n.º 5
0
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            if (tag == null || !(tag is ToDoTag))
            {
                return(null);
            }

            ToDoTag tags = tag as ToDoTag;

            if (tags.HightText == "todo")
            {
                return(new Ellipse {
                    Fill = Brushes.Orange,
                    StrokeThickness = 1.2,
                    Stroke = Brushes.OrangeRed,
                    Height = _height,
                    Width = _width
                });
            }
            else
            {
                return(new Rectangle
                {
                    //Fill = new SolidColorBrush(Colors.GreenYellow),
                    Fill = new SolidColorBrush(Colors.DarkOrchid),
                    StrokeThickness = 1.0,
                    Stroke = Brushes.Black,
                    Height = _height,
                    Width = _width
                });
            }
        }
        protected override bool Execute(uint commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            int              position = TextView.Caret.Position.BufferPosition.Position;
            SnapshotPoint    point    = new SnapshotPoint(TextView.TextBuffer.CurrentSnapshot, position);
            IWpfTextViewLine line     = TextView.GetTextViewLineContainingBufferPosition(point);

            string text = TextView.TextBuffer.CurrentSnapshot.GetText(line.Start, line.Length);

            Match match = _indent.Match(text);

            if (match.Success)
            {
                try
                {
                    EditorExtensionsPackage.DTE.UndoContext.Open("Smart Indent");
                    TextView.TextBuffer.Insert(position, Environment.NewLine + match.Value);
                }
                finally
                {
                    EditorExtensionsPackage.DTE.UndoContext.Close();
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
        private void InnerSelect(VirtualSnapshotPoint anchorPoint, VirtualSnapshotPoint activePoint)
        {
            bool isEmpty = this.IsEmpty;

            this.ActivationTracksFocus = true;
            this._anchorPoint          = anchorPoint;
            this._activePoint          = activePoint;
            VirtualSnapshotPoint bufferPosition1 = this._anchorPoint;
            VirtualSnapshotPoint bufferPosition2 = this._activePoint;

            if (this._anchorPoint > this._activePoint)
            {
                bufferPosition1 = this._activePoint;
                bufferPosition2 = this._anchorPoint;
            }
            if (this.Mode == TextSelectionMode.Box)
            {
                IWpfTextViewLine containingBufferPosition1 = this._wpfTextView.GetTextViewLineContainingBufferPosition(bufferPosition1.Position);
                IWpfTextViewLine containingBufferPosition2 = this._wpfTextView.GetTextViewLineContainingBufferPosition(bufferPosition2.Position);
                TextBounds       extendedCharacterBounds   = containingBufferPosition1.GetExtendedCharacterBounds(bufferPosition1);
                this._leftX             = extendedCharacterBounds.Leading;
                extendedCharacterBounds = containingBufferPosition2.GetExtendedCharacterBounds(bufferPosition2);
                this._rightX            = extendedCharacterBounds.Leading;
                if (this._rightX < this._leftX)
                {
                    double leftX = this._leftX;
                    this._leftX  = this._rightX;
                    this._rightX = leftX;
                }
            }
            //TODO: this.RaiseChangedEvent(isEmpty, this.IsEmpty, true);
        }
Ejemplo n.º 8
0
        private void PlaceCaret(ElementNode element, int position)
        {
            SnapshotPoint point = new SnapshotPoint(TextView.TextBuffer.CurrentSnapshot, TextView.Caret.Position.BufferPosition.Position);

            if (element.EndTag.Start == point.Position)
            {
                string text = element.GetText(element.InnerRange);

                for (int i = text.Length - 1; i > -1; i--)
                {
                    if (!char.IsWhiteSpace(text[i]))
                    {
                        TextView.Caret.MoveTo(new SnapshotPoint(TextView.TextBuffer.CurrentSnapshot, element.InnerRange.Start + i + 1));
                        break;
                    }
                }
            }
            else
            {
                IWpfTextViewLine line = TextView.GetTextViewLineContainingBufferPosition(point);
                string           text = TextView.TextBuffer.CurrentSnapshot.GetText(line.Start.Position, line.Length);

                for (int i = 0; i < text.Length; i++)
                {
                    if (!char.IsWhiteSpace(text[i]))
                    {
                        TextView.Caret.MoveTo(new SnapshotPoint(TextView.TextBuffer.CurrentSnapshot, line.Start.Position + i));
                        break;
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            NumberedBookmarkTag nTag = tag as NumberedBookmarkTag;

            // Ensure we can draw a glyph for this marker.
            if (nTag == null)
            {
                return(null);
            }
            Border b = new Border();

            b.Background      = Brushes.LightBlue;
            b.CornerRadius    = new CornerRadius(4);
            b.BorderThickness = new Thickness(1.0);
            b.BorderBrush     = Brushes.DarkBlue;
            b.Width           = 12;
            b.Height          = m_glyphSize;
            b.Child           = new TextBlock()
            {
                Text = nTag.Numbers.First().ToString(), HorizontalAlignment = HorizontalAlignment.Center
            };
            //if more than one number on same line, add a shadow
            if (nTag.Numbers.Length > 1)
            {
                var effect = new DropShadowEffect();
                effect.BlurRadius  = 3;
                effect.Direction   = 0;
                effect.ShadowDepth = 3;
                effect.Color       = Colors.LightBlue;
                b.Effect           = effect;
                b.ToolTip          = string.Format("There is several bookmarks at this line : {0}", string.Join("..", nTag.Numbers.Select(x => x.ToString())));
            }
            return(b);
        }
Ejemplo n.º 10
0
        internal IGlyphTextMarkerImpl[] GetSortedGlyphTextMarkers(IWpfTextViewLine line)
        {
            List <IGlyphTextMarkerImpl> markers = null;

            var spans = new NormalizedSnapshotSpanCollection(line.Extent);

            foreach (var info in GetMarkers(spans, true))
            {
                if (markers == null)
                {
                    markers = new List <IGlyphTextMarkerImpl>();
                }
                markers.Add(info.Marker);
            }
            if (markers != null)
            {
                if (markers.Count == 1)
                {
                    return new[] { markers[0] }
                }
                ;
                return(markers.OrderBy(a => a.ZIndex).Reverse().ToArray());
            }

            return(Array.Empty <IGlyphTextMarkerImpl>());
        }
        /// <summary>
        /// Create the glyph element.
        /// </summary>
        /// <param name="line">Editor line to create the glyph for.</param>
        /// <param name="tag">The corresponding tag.</param>
        /// <returns></returns>
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            // get the coverage info for the current line
            LineCoverageState state = GetLineCoverageState(line);

            // no coverage info found -> exit here
            if (state == LineCoverageState.Unknown)
                return null;

            var brush = GetBrushForState(state);

            if (brush == null)
                return null;

            System.Windows.Shapes.Ellipse ellipse = new Ellipse();
            ellipse.Fill = brush;
            ellipse.Height = _glyphSize;
            ellipse.Width = _glyphSize;

            ellipse.ToolTip = GetToolTipText(state);

            if (state == LineCoverageState.Partly)
            {
                ellipse.MouseEnter += OnGlyphMouseEnter;
                ellipse.MouseLeave += OnGlyphMouseLeave;
                ellipse.Tag = line;
            }

            return ellipse;
        }            
Ejemplo n.º 12
0
        public UIElement GenerateGlyph(IWpfTextViewLine line, GlyphTextMarkerGlyphTag glyphTag)
        {
            if (line == null)
            {
                throw new ArgumentNullException(nameof(line));
            }
            if (glyphTag == null)
            {
                throw new ArgumentNullException(nameof(glyphTag));
            }
            Debug.Assert(glyphTag.ImageReference.Assembly != null && glyphTag.ImageReference.Name != null);
            if (glyphTag.ImageReference.Assembly == null || glyphTag.ImageReference.Name == null)
            {
                return(null);
            }

            var          source = glyphTextMarkerServiceImpl.ImageManager.GetImage(glyphTag.ImageReference, BackgroundType.GlyphMargin);
            const double DEFAULT_IMAGE_LENGTH = 16;
            const double EXTRA_LENGTH         = 2;
            double       imageLength          = Math.Min(DEFAULT_IMAGE_LENGTH, line.Height + EXTRA_LENGTH);
            var          image = new Image {
                Width  = imageLength,
                Height = imageLength,
                Source = source,
            };

            Panel.SetZIndex(image, glyphTag.ZIndex);
            return(image);
        }
Ejemplo n.º 13
0
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            if (tag == null || !(tag is Tag))
            {
                return(null);
            }

            var digit = new TextBlock();

            digit.Text                = (tag as Tag).Number.ToString();
            digit.FontFamily          = new FontFamily("Verdana");
            digit.FontSize            = 12;
            digit.FontWeight          = FontWeights.ExtraBold;
            digit.HorizontalAlignment = HorizontalAlignment.Center;
            digit.VerticalAlignment   = VerticalAlignment.Center;
            digit.Width               = _GlyphSize;
            digit.Height              = _GlyphSize;
            digit.Foreground          = new SolidColorBrush(GetCurrentThemeColor());

            VSColorTheme.ThemeChanged += (e) => {
                digit.Foreground = new SolidColorBrush(GetCurrentThemeColor());
            };

            return(digit);
        }
Ejemplo n.º 14
0
 public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
 {
     try
     {
         // Ensure we can draw a glyph for this marker.)
         if (tag == null || !(tag is RiskTag))
         {
             return null;
         }
         var riskTag = tag as RiskTag;
         MarginUIElement element;
         if (riskTag.Signature.StringSignature == null) return null;
         if (cache.TryGetValue(riskTag.Signature.StringSignature, out element))
         {
             element.Detach();
         }
         var g = new MarginUIElement(riskTag, line);
         g.Height = _glyphSize;
         g.Width = _glyphSize;
         g.SetUIElements();
         cache.Remove(riskTag.Signature.StringSignature);
         cache.Add(riskTag.Signature.StringSignature, g);
         return g;
     }
     catch (Exception exception)
     {
         Logger.Write("RiskGlyphFactory Exception");
         Logger.Write(exception);
         return null;
     }
 }
 public GlyphTextMarkerMouseProcessorContext(IWpfTextViewHost host, IWpfTextViewMargin margin, IWpfTextViewLine line, IGlyphTextMarker[] markers)
 {
     Host    = host;
     Margin  = margin;
     Line    = line;
     Markers = markers;
 }
Ejemplo n.º 16
0
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            ErrorGlyphTag errorDetails = tag as ErrorGlyphTag;

            if (errorDetails == null)
            {
                return(null);
            }

            BitmapImage glyphImage = null;

            switch (errorDetails.ErrorLevel)
            {
            case vsBuildErrorLevel.vsBuildErrorLevelHigh:
                glyphImage = _errorIcon;
                break;

            case vsBuildErrorLevel.vsBuildErrorLevelMedium:
                glyphImage = _warningIcon;
                break;

            case vsBuildErrorLevel.vsBuildErrorLevelLow:
                glyphImage = _infoIcon;
                break;
            }

            Image glyphIcon = new Image();

            glyphIcon.Width  = 16;
            glyphIcon.Height = 16;
            glyphIcon.Source = glyphImage;

            return(glyphIcon);
        }
Ejemplo n.º 17
0
        public UIElement?GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            if (tag is not InheritanceMarginTag inheritanceMarginTag)
            {
                return(null);
            }

            // The life cycle of the glyphs in Indicator Margin is controlled by the editor,
            // so in order to get the glyphs removed when FeatureOnOffOptions.InheritanceMarginCombinedWithIndicatorMargin is off,
            // we need
            // 1. Generate tags when this option changes.
            // 2. Always return null here to force the editor to remove the glyphs.
            if (!_globalOptions.GetOption(FeatureOnOffOptions.InheritanceMarginCombinedWithIndicatorMargin))
            {
                return(null);
            }

            if (_textView.TextBuffer.GetWorkspace() == null)
            {
                return(null);
            }

            var membersOnLine = inheritanceMarginTag.MembersOnLine;

            Contract.ThrowIfTrue(membersOnLine.IsEmpty);
            return(new InheritanceMarginGlyph(
                       _threadingContext,
                       _streamingFindUsagesPresenter,
                       _classificationTypeMap,
                       _classificationFormatMap,
                       _operationExecutor,
                       inheritanceMarginTag,
                       _textView,
                       _listener));
        }
Ejemplo n.º 18
0
        public UIElement GenerateGlyph(IWpfTextViewLine line, GlyphTextMarkerGlyphTag glyphTag)
        {
            if (line == null)
            {
                throw new ArgumentNullException(nameof(line));
            }
            if (glyphTag == null)
            {
                throw new ArgumentNullException(nameof(glyphTag));
            }
            Debug.Assert(!glyphTag.ImageReference.IsDefault);
            if (glyphTag.ImageReference.IsDefault)
            {
                return(null);
            }

            const double DEFAULT_IMAGE_LENGTH = 16;
            const double EXTRA_LENGTH         = 2;
            double       imageLength          = Math.Min(DEFAULT_IMAGE_LENGTH, line.Height + EXTRA_LENGTH);

            var image = new DsImage {
                Width          = imageLength,
                Height         = imageLength,
                ImageReference = glyphTag.ImageReference,
            };

            Panel.SetZIndex(image, glyphTag.ZIndex);
            return(image);
        }
        /// <summary>
        /// Create the glyph element.
        /// </summary>
        /// <param name="line">Editor line to create the glyph for.</param>
        /// <param name="tag">The corresponding tag.</param>
        /// <returns></returns>
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            // get the coverage info for the current line
            LineCoverageState state = GetLineCoverageState(line);

            // no coverage info found -> exit here
            if (state == LineCoverageState.Unknown)
            {
                return(null);
            }

            var brush = GetBrushForState(state);

            if (brush == null)
            {
                return(null);
            }

            System.Windows.Shapes.Ellipse ellipse = new Ellipse();
            ellipse.Fill   = brush;
            ellipse.Height = _glyphSize;
            ellipse.Width  = _glyphSize;

            ellipse.ToolTip = GetToolTipText(state);

            if (state == LineCoverageState.Partly)
            {
                ellipse.MouseEnter += OnGlyphMouseEnter;
                ellipse.MouseLeave += OnGlyphMouseLeave;
                ellipse.Tag         = line;
            }

            return(ellipse);
        }
 public GlyphTextMarkerHandlerContext(IWpfTextViewHost host, IWpfTextViewMargin margin, IWpfTextViewLine line, IGlyphTextMarkerSpanProvider spanProvider)
 {
     Host         = host;
     Margin       = margin;
     Line         = line;
     SpanProvider = spanProvider;
 }
Ejemplo n.º 21
0
 private bool ShouldHighlightEntireLine(IWpfTextViewLine line) {
     if (_contanedLanguageHandler != null) {
         return _contanedLanguageHandler.GetCodeBlockOfLocation(line.Start.Position) != null ||
                _contanedLanguageHandler.GetCodeBlockOfLocation(line.End.Position) != null;
     }
     return false;
 }
Ejemplo n.º 22
0
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            
            // Ensure we can draw a glyph for this marker. 
            if (tag == null || !(tag is ClippyTag))
            {
                return null;
            }

            
            
            var clippy = tag as ClippyTag;
        //    Debug.WriteLine("Creating Glyph: " + clippy.GetDefinition().Line);
            //Debug.WriteLine("Drawing Glyph: {0} - {1}", clippy.GetDefinition().Line, clippy.GetDefinition().Type);
            
            var grid = clippy.GetEllipses();
            //grid.SetValue(Grid.ZIndexProperty, 999);
            ////grid.AddHandler(new RoutedEvent().HandlerType == )
            //grid.AddHandler(Grid.ContextMenuOpeningEvent, new RoutedEventHandler(OnOpen));
            //grid.AddHandler(Grid.PreviewMouseRightButtonUpEvent, new RoutedEventHandler(OnOpen));

            

            return grid;

        }
Ejemplo n.º 23
0
        protected override bool Execute(VSConstants.VSStd2KCmdID commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (_tree == null || _broker.IsCompletionActive(TextView) || !IsValidTextBuffer() || !WESettings.Instance.Html.EnableEnterFormat)
            {
                return(false);
            }

            int              position = TextView.Caret.Position.BufferPosition.Position;
            SnapshotPoint    point    = new SnapshotPoint(TextView.TextBuffer.CurrentSnapshot, position);
            IWpfTextViewLine line     = TextView.GetTextViewLineContainingBufferPosition(point);

            ElementNode   element = null;
            AttributeNode attr    = null;

            _tree.GetPositionElement(position, out element, out attr);

            if (element == null ||
                _tree.IsDirty ||
                element.Parent == null ||
                element.StartTag.Contains(position) ||
                line.End.Position == position || // caret at end of line (TODO: add ignore whitespace logic)
                TextView.TextBuffer.CurrentSnapshot.GetText(element.InnerRange.Start, element.InnerRange.Length).Trim().Length == 0)
            {
                return(false);
            }

            UpdateTextBuffer(element);

            return(false);
        }
        void UpdateToolTipContent(IWpfTextViewLine line)
        {
            IGlyphTextMarkerHandlerContext glyphTextMarkerHandlerContext = null;

            foreach (var marker in glyphTextViewMarkerService.GetSortedGlyphTextMarkers(line))
            {
                if (glyphTextMarkerHandlerContext == null)
                {
                    glyphTextMarkerHandlerContext = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line);
                }
                var toolTipContent = marker.Handler.GetToolTipContent(glyphTextMarkerHandlerContext, marker);
                if (toolTipContent != null)
                {
                    Debug.Assert(toolTip == null);
                    toolTipMarker = marker;
                    toolTip       = new ToolTip();
                    toolTip.SetResourceReference(FrameworkElement.StyleProperty, "GlyphTextMarkerToolTipStyle");
                    ToolTipHelper.SetScaleTransform(wpfTextViewHost.TextView, toolTip);
                    toolTip.Content = new TextBlock {
                        Text         = toolTipContent,
                        TextWrapping = TextWrapping.Wrap,
                    };
                    toolTip.Placement        = PlacementMode.Relative;
                    toolTip.PlacementTarget  = margin.VisualElement;
                    toolTip.HorizontalOffset = 0;
                    toolTip.VerticalOffset   = toolTipLine.TextBottom - wpfTextViewHost.TextView.ViewportTop + 1;
                    toolTip.IsOpen           = true;
                    return;
                }
            }
        }
Ejemplo n.º 25
0
 private void CreateVisuals(IWpfTextViewLine line) {
     if (ShouldHighlightEntireLine(line)) {
         IWpfTextViewLineCollection textViewLines = _view.TextViewLines;
         var g = new RectangleGeometry(new Rect(0, line.TextTop, _lastWidth, (double)(int)(line.Height + 0.5)));
         SnapshotSpan span = new SnapshotSpan(line.Snapshot, new Span(line.Start, line.Length));
         CreateHighlight(line, g, span);
     }
 }
Ejemplo n.º 26
0
        public static Rect?GetViewSpanRect(IWpfTextView wpfTextView, SnapshotSpan span)
        {
            var nullable = new Rect?();

            if (span.Length > 0)
            {
                double num1   = double.MaxValue;
                double num2   = double.MaxValue;
                double val1_1 = double.MinValue;
                double val1_2 = double.MinValue;
                foreach (TextBounds textBounds in wpfTextView.TextViewLines.GetNormalizedTextBounds(span))
                {
                    num1   = Math.Min(num1, textBounds.Left);
                    num2   = Math.Min(num2, textBounds.TextTop);
                    val1_1 = Math.Max(val1_1, textBounds.Right);
                    val1_2 = Math.Max(val1_2, textBounds.TextBottom + 1.0);
                }
                IWpfTextViewLine containingBufferPosition = wpfTextView.TextViewLines.GetTextViewLineContainingBufferPosition(span.Start);
                if (containingBufferPosition != null)
                {
                    TextBounds extendedCharacterBounds = containingBufferPosition.GetExtendedCharacterBounds(span.Start);
                    if (extendedCharacterBounds.Left < val1_1 && extendedCharacterBounds.Left >= wpfTextView.ViewportLeft && extendedCharacterBounds.Left < wpfTextView.ViewportRight)
                    {
                        num1 = extendedCharacterBounds.Left;
                    }
                }
                ITextViewLine textViewLine = wpfTextView.TextViewLines.GetTextViewLineContainingBufferPosition(span.End);
                if (textViewLine != null && textViewLine.Start == span.End)
                {
                    val1_2 = Math.Max(val1_2, textViewLine.TextBottom + 1.0);
                }
                if (num1 < val1_1)
                {
                    nullable = new Rect(num1, num2, val1_1 - num1, val1_2 - num2);
                }
            }
            else
            {
                ITextViewLine textViewLine = wpfTextView.TextViewLines.GetTextViewLineContainingBufferPosition(span.Start);
                if (textViewLine != null)
                {
                    TextBounds characterBounds = textViewLine.GetCharacterBounds(span.Start);
                    nullable = new Rect(characterBounds.Left, characterBounds.TextTop, 0.0, characterBounds.TextHeight + 1.0);
                }
            }
            if (!nullable.HasValue || nullable.Value.IsEmpty)
            {
                return(null);
            }
            Rect rect1 = new Rect(wpfTextView.ViewportLeft, wpfTextView.ViewportTop, wpfTextView.ViewportWidth, wpfTextView.ViewportHeight);
            Rect rect2 = nullable.Value;

            rect2.Intersect(rect1);
            var point1 = GetScreenPointFromTextXY(wpfTextView, rect2.Left, rect2.Top);
            var point2 = GetScreenPointFromTextXY(wpfTextView, rect2.Right, rect2.Bottom);

            return(new Rect(point1, point2));
        }
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            InheritanceTag inheritanceTag = tag as InheritanceTag;

            if (inheritanceTag == null)
            {
                return(null);
            }

            string imageName;

            switch (inheritanceTag.Glyph)
            {
            case InheritanceGlyph.HasImplementations:
                imageName = "has-implementations";
                break;

            case InheritanceGlyph.Implements:
                imageName = "implements";
                break;

            case InheritanceGlyph.ImplementsAndHasImplementations:
                imageName = "override-is-overridden-combined";
                break;

            case InheritanceGlyph.ImplementsAndOverridden:
                imageName = "override-is-overridden-combined";
                break;

            case InheritanceGlyph.Overridden:
                imageName = "is-overridden";
                break;

            case InheritanceGlyph.Overrides:
                imageName = "overrides";
                break;

            case InheritanceGlyph.OverridesAndOverridden:
                imageName = "override-is-overridden-combined";
                break;

            default:
                return(null);
            }

            BitmapSource source = new BitmapImage(new Uri("pack://application:,,,/Tvl.VisualStudio.InheritanceMargin;component/Resources/" + imageName + ".png"));
            Image        image  = new Image()
            {
                Source = source
            };

            image.CommandBindings.Add(new CommandBinding(InheritanceMarginPackage.InheritanceTargetsList, inheritanceTag.HandleExecutedInheritanceTargetsList, inheritanceTag.HandleCanExecuteInheritanceTargetsList));

            inheritanceTag.MarginGlyph = image;

            return(image);
        }
        /// <summary>
        /// Generates a new glyph visual for the given line.
        /// </summary>
        /// <param name="line">The line that this glyph will be placed on.</param><param name="tag">Information about the glyph for which the visual is being generated.</param>
        /// <returns>
        /// The visual element for the given tag.
        /// </returns>
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            if (tag == null || !(tag is TestTag))
            {
                return null;
            }

            return new MarginTestGlyph() { Width = 16, Height = 16 };
        }
Ejemplo n.º 29
0
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            if (tag == null || !(tag is PlayGlyphTag))
            {
                return null;
            }

            return new PlayGlyph();
        }
Ejemplo n.º 30
0
 public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
 {
     return(new Button()
     {
         Width = 16,
         Height = 16,
         Content = 1
     });
 }
Ejemplo n.º 31
0
 public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
 {
     // Ensure we can draw a glyph for this marker.
     if (tag == null || !(tag is TodoTag))
     {
         return(null);
     }
     return(new TodoGlyph());
 }
Ejemplo n.º 32
0
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            if (tag == null || !(tag is PlayGlyphTag))
            {
                return(null);
            }

            return(new PlayGlyph());
        }
Ejemplo n.º 33
0
        private List <IconInfo> CreateIconInfos(IWpfTextViewLine line)
        {
            var icons = new List <IconInfo>();

            try {
                foreach (var mappingSpan in _tagAggregator.GetTags(line.ExtentAsMappingSpan))
                {
                    var tag = mappingSpan.Tag;
                    if (tag == null)
                    {
                        Log.Verbose("Tag is null");
                        continue;
                    }

                    // Fails if someone forgot to Export(typeof(IGlyphFactoryProvider)) with the correct tag types
                    var tagType = tag.GetType();
                    var b       = _glyphFactories.TryGetValue(tag.GetType(), out var factoryInfo);
                    if (!b)
                    {
                        Log.Verbose($"Could not find glyph factory for {tagType}");
                        continue;
                    }

                    foreach (var span in mappingSpan.Span.GetSpans(_wpfTextViewHost.TextView.TextSnapshot))
                    {
                        if (!line.IntersectsBufferSpan(span))
                        {
                            continue;
                        }

                        var elem = factoryInfo.Factory.GenerateGlyph(line, tag);
                        if (elem == null)
                        {
                            continue;
                        }

                        elem.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                        var iconInfo = new IconInfo(factoryInfo.Order, elem);
                        icons.Add(iconInfo);

                        // ActualWidth isn't always valid when we're here so use the constant
                        SetLeft(elem, (DefaultMarginWidth - elem.DesiredSize.Width) / 2);
                        SetTop(elem, iconInfo.BaseTopValue + line.TextTop);
                    }
                }
            }
            catch (ObjectDisposedException ex) {
                Log.Error(ex, nameof(CreateIconInfos) + " " + nameof(ObjectDisposedException) + $" AgentReady={ _sessionService?.IsAgentReady} IsReady={_sessionService?.IsReady} _isDisposed={_isDisposed}");
            }

            catch (Exception ex) {
                Log.Error(ex, nameof(CreateIconInfos));
            }

            return(icons);
        }
Ejemplo n.º 34
0
 public MarginUIElement(RiskTag riskTag, IWpfTextViewLine line)
 {
     this.riskTag = riskTag;
     _line = line;
     entry = EntryCache.GetRiskEntryFor(riskTag.Signature.StringSignature);
     entry.Changed += Refresh;
     entry.Invalidated += CheckUpdate;
     IsVisibleChanged += MarginUIElement_IsVisibleChanged;
     SetUIElements();
 }
        /// <summary>
        /// Shows the line colors
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnGlyphMouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            IWpfTextViewLine line   = (IWpfTextViewLine)((System.Windows.Shapes.Ellipse)sender).Tag;
            TextTagger       tagger = TextTagger.GetTagger(_textView);

            if (tagger != null)
            {
                tagger.ShowForLine(line);
            }
        }
Ejemplo n.º 36
0
 public MarginUIElement(RiskTag riskTag, IWpfTextViewLine line)
 {
     this.riskTag       = riskTag;
     _line              = line;
     entry              = EntryCache.GetRiskEntryFor(riskTag.Signature.StringSignature);
     entry.Changed     += Refresh;
     entry.Invalidated += CheckUpdate;
     IsVisibleChanged  += MarginUIElement_IsVisibleChanged;
     SetUIElements();
 }
Ejemplo n.º 37
0
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            if (tag == null || !(tag is MarkerTag))
            {
                return null;
            }

            return new Image()
            {
                Source = new BitmapImage(new Uri(LogoResource))
            };
        }
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            InheritanceTag inheritanceTag = tag as InheritanceTag;
            if (inheritanceTag == null)
                return null;

            string imageName;
            switch (inheritanceTag.Glyph)
            {
            case InheritanceGlyph.HasImplementations:
                imageName = "has-implementations";
                break;

            case InheritanceGlyph.Implements:
                imageName = "implements";
                break;

            case InheritanceGlyph.ImplementsAndHasImplementations:
                imageName = "override-is-overridden-combined";
                break;

            case InheritanceGlyph.ImplementsAndOverridden:
                imageName = "override-is-overridden-combined";
                break;

            case InheritanceGlyph.Overridden:
                imageName = "is-overridden";
                break;

            case InheritanceGlyph.Overrides:
                imageName = "overrides";
                break;

            case InheritanceGlyph.OverridesAndOverridden:
                imageName = "override-is-overridden-combined";
                break;

            default:
                return null;
            }

            BitmapSource source = new BitmapImage(new Uri("pack://application:,,,/Tvl.VisualStudio.InheritanceMargin;component/Resources/" + imageName + ".png"));
            Image image = new Image()
                {
                    Source = source
                };
            image.CommandBindings.Add(new CommandBinding(InheritanceMarginPackage.InheritanceTargetsList, inheritanceTag.HandleExecutedInheritanceTargetsList, inheritanceTag.HandleCanExecuteInheritanceTargetsList));

            inheritanceTag.MarginGlyph = image;

            return image;
        }
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            if (tag == null || !(tag is NugetPackageTag))
            {
                return null;
            }

            var glyphIcon = new Image();
            glyphIcon.Width = GlyphSize;
            glyphIcon.Height = GlyphSize;
            glyphIcon.Source = ImageHelper.GetImageSource(KnownMonikers.NuGet);

            return glyphIcon;
        }
Ejemplo n.º 40
0
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            const double m_glyphSize = 16.0;

            System.Windows.Shapes.Polygon polygon = new Polygon();
            polygon.Fill = Brushes.Blue;
            polygon.StrokeThickness = 0;
            polygon.Points.Add(new Point(0, 5));
            polygon.Points.Add(new Point(12, 5));
            polygon.Points.Add(new Point(16, 8));
            polygon.Points.Add(new Point(12, 11));
            polygon.Points.Add(new Point(0, 11));

            polygon.Width = m_glyphSize;
            polygon.Height = m_glyphSize;

            return polygon;
        }
        /// <summary>
        /// The generate glyph.
        /// </summary>
        /// <param name="line">
        /// The line.
        /// </param>
        /// <param name="tag">
        /// The tag.
        /// </param>
        /// <returns>
        /// The System.Windows.UIElement.
        /// </returns>
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            if (tag == null || !(tag is SonarGlyphTag))
            {
                return null;
            }

            var ellipse = new Rectangle
                              {
                                  Fill = Brushes.Green,
                                  StrokeThickness = 1,
                                  Stroke = Brushes.Red,
                                  Height = GlyphSize,
                                  Width = GlyphSize
                              };

            return ellipse;
        }
        public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
        {
            // Ensure a glyph can be drawn for this marker
            if (tag == null || !(tag is AccentBoxOccurrences))
            {
                return null;
            }

            IEditorFormatMap map = FormatMapService.GetEditorFormatMap(View);
            ResourceDictionary dict = map.GetProperties(Constants.GLYPH_FORMAT_NAME);

            System.Windows.Shapes.Ellipse ellipse = new Ellipse();
            ellipse.Fill = (SolidColorBrush)dict[EditorFormatDefinition.BackgroundBrushId];
            ellipse.StrokeThickness = 2;
            ellipse.Stroke = (SolidColorBrush)dict[EditorFormatDefinition.ForegroundBrushId];
            ellipse.Height = glyphSize;
            ellipse.Width = glyphSize;

            return ellipse;
        }
			public GlyphTextMarkerMouseProcessorContext(IWpfTextViewHost host, IWpfTextViewMargin margin, IWpfTextViewLine line, IGlyphTextMarker[] markers) {
				Host = host;
				Margin = margin;
				Line = line;
				Markers = markers;
			}
 public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
 {
     OutliningGlyphTag ourTag = tag as OutliningGlyphTag;
     if ( ourTag == null ) {
       return null;
     }
     const double minSize = 16.0;
     double size = line != null
       ? Math.Min(minSize, line.TextHeight)
       : minSize;
     TextBlock tb = CreateGlyphElement(minSize);
     return tb;
 }
Ejemplo n.º 45
0
		public UIElement GenerateGlyph(IWpfTextViewLine line, GlyphTextMarkerGlyphTag glyphTag) {
			if (line == null)
				throw new ArgumentNullException(nameof(line));
			if (glyphTag == null)
				throw new ArgumentNullException(nameof(glyphTag));
			Debug.Assert(!glyphTag.ImageReference.IsDefault);
			if (glyphTag.ImageReference.IsDefault)
				return null;

			const double DEFAULT_IMAGE_LENGTH = 16;
			const double EXTRA_LENGTH = 2;
			double imageLength = Math.Min(DEFAULT_IMAGE_LENGTH, line.Height + EXTRA_LENGTH);

			var image = new DsImage {
				Width = imageLength,
				Height = imageLength,
				ImageReference = glyphTag.ImageReference,
			};
			Panel.SetZIndex(image, glyphTag.ZIndex);
			return image;
		}
Ejemplo n.º 46
0
		internal IGlyphTextMarkerImpl[] GetSortedGlyphTextMarkers(IWpfTextViewLine line) {
			List<IGlyphTextMarkerImpl> markers = null;

			if (markerAndSpanCollection.CountInDocument != 0) {
				var spans = new NormalizedSnapshotSpanCollection(line.Extent);
				foreach (var info in GetMarkers(spans, true)) {
					if (markers == null)
						markers = new List<IGlyphTextMarkerImpl>();
					markers.Add(info.Marker);
				}
			}
			if (markers != null) {
				if (markers.Count == 1)
					return new[] { markers[0] };
				return markers.OrderByDescending(a => a.ZIndex).ToArray();
			}

			return Array.Empty<IGlyphTextMarkerImpl>();
		}
Ejemplo n.º 47
0
 private static bool IsHunkFullyVisible(IWpfTextViewLine topLine, IWpfTextViewLine bottomLine)
 {
     return topLine.VisibilityState == VisibilityState.FullyVisible && bottomLine.VisibilityState == VisibilityState.FullyVisible;
 }
Ejemplo n.º 48
0
 private void CreateVisuals(IWpfTextViewLine line) {
     if (ShouldHighlightEntireLine(line)) {
         IWpfTextViewLineCollection textViewLines = _view.TextViewLines;
         var g = new RectangleGeometry(new Rect(0, line.TextTop, _lastWidth, (double)(int)(line.Height + 0.5)));
         SnapshotSpan span = new SnapshotSpan(line.Snapshot, new Span(line.Start, line.Length));
         CreateHighlight(line, g, span);
     }
 }
Ejemplo n.º 49
0
        private void CreateHighlight(IWpfTextViewLine line, Geometry g, SnapshotSpan span) {
            if (g != null) {
                var uiElement = new Rectangle();

                uiElement.Width = g.Bounds.Width;
                uiElement.Height = g.Bounds.Height;
                uiElement.Fill = _backgroudColorBrush;

                //Align the image with the top of the bounds of the text geometry
                Canvas.SetLeft(uiElement, g.Bounds.Left);
                Canvas.SetTop(uiElement, g.Bounds.Top);

                _layer.RemoveAdornmentsByTag(line);
                _layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, line, uiElement, null);
            }
        }
Ejemplo n.º 50
0
 private bool ShouldHighlightEntireLine(IWpfTextViewLine line) {
     return _contanedLanguageHandler.GetCodeBlockOfLocation(line.Start.Position) != null ||
            _contanedLanguageHandler.GetCodeBlockOfLocation(line.End.Position) != null;
 }
		void UpdateToolTipContent(IWpfTextViewLine line) {
			IGlyphTextMarkerHandlerContext glyphTextMarkerHandlerContext = null;
			foreach (var marker in glyphTextViewMarkerService.GetSortedGlyphTextMarkers(line)) {
				if (glyphTextMarkerHandlerContext == null)
					glyphTextMarkerHandlerContext = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line);
				var toolTipInfo = marker.Handler.GetToolTipContent(glyphTextMarkerHandlerContext, marker);
				if (toolTipInfo != null) {
					Debug.Assert(toolTip == null);
					toolTipMarker = marker;
					toolTip = new ToolTip();
					PopupHelper.SetScaleTransform(wpfTextViewHost.TextView, toolTip);

					var toolTipContentString = toolTipInfo.Content as string;
					if (toolTipContentString != null) {
						toolTip.Content = new TextBlock {
							Text = toolTipContentString,
							TextWrapping = TextWrapping.Wrap,
						};
					}
					else
						toolTip.Content = toolTipInfo.Content;

					var toolTipStyle = toolTipInfo.Style as Style;
					if (toolTipStyle != null)
						toolTip.Style = toolTipStyle;
					else
						toolTip.SetResourceReference(FrameworkElement.StyleProperty, toolTipInfo.Style ?? "GlyphTextMarkerToolTipStyle");

					toolTip.Placement = PlacementMode.Relative;
					toolTip.PlacementTarget = margin.VisualElement;
					toolTip.HorizontalOffset = 0;
					toolTip.VerticalOffset = toolTipLine.TextBottom - wpfTextViewHost.TextView.ViewportTop + 1;
					toolTip.IsOpen = true;
					return;
				}
			}
		}
			public GlyphTextMarkerHandlerContext(IWpfTextViewHost host, IWpfTextViewMargin margin, IWpfTextViewLine line) {
				Host = host;
				Margin = margin;
				Line = line;
			}
		void UpdatePopupContent(IWpfTextViewLine line) {
			IGlyphTextMarkerHandlerContext glyphTextMarkerHandlerContext = null;
			foreach (var marker in glyphTextViewMarkerService.GetSortedGlyphTextMarkers(line)) {
				if (glyphTextMarkerHandlerContext == null)
					glyphTextMarkerHandlerContext = new GlyphTextMarkerHandlerContext(wpfTextViewHost, margin, line);
				var popupContent = marker.Handler.GetPopupContent(glyphTextMarkerHandlerContext, marker);
				if (popupContent != null) {
					AddPopupContent(line, marker, popupContent);
					return;
				}
			}
		}
		void AddPopupContent(IWpfTextViewLine line, IGlyphTextMarker marker, FrameworkElement popupContent) {
			// We must close it or it refuses to use the new scale transform
			popup.IsOpen = false;
			popupTopViewLinePosition = wpfTextViewHost.TextView.TextViewLines.FirstVisibleLine.Start.Position;
			popupMarker = marker;
			popup.Child = popupContent;
			popup.Placement = PlacementMode.Relative;
			popup.PlacementTarget = margin.VisualElement;
			popup.HorizontalOffset = margin.VisualElement.Width - 1;
			var popupContentHeight = popupContent.Height;
			Debug.Assert(!double.IsNaN(popupContentHeight), "You must initialize the Height property of the popup content!");
			if (double.IsNaN(popupContentHeight))
				popupContentHeight = 0;
			popup.VerticalOffset = line.TextTop - wpfTextViewHost.TextView.ViewportTop + 1 - popupContentHeight;
			popup.Visibility = Visibility.Visible;
			PopupHelper.SetScaleTransform(wpfTextViewHost.TextView, popup);
			popup.IsOpen = true;
		}
Ejemplo n.º 55
0
 public UIElement GenerateGlyph(IWpfTextViewLine line, IGlyphTag tag)
 {
     return new TodoGlyph();
 }
Ejemplo n.º 56
0
		List<IconInfo> CreateIconInfos(IWpfTextViewLine line) {
			var icons = new List<IconInfo>();
			foreach (var mappingSpan in tagAggregator.GetTags(line.ExtentAsMappingSpan)) {
				var tag = mappingSpan.Tag;
				Debug.Assert(tag != null);
				if (tag == null)
					continue;
				GlyphFactoryInfo factoryInfo;
				// Fails if someone forgot to Export(typeof(IGlyphFactoryProvider)) with the correct tag types
				bool b = glyphFactories.TryGetValue(tag.GetType(), out factoryInfo);
				Debug.Assert(b);
				if (!b)
					continue;
				foreach (var span in mappingSpan.Span.GetSpans(wpfTextViewHost.TextView.TextSnapshot)) {
					if (!line.IntersectsBufferSpan(span))
						continue;
					var elem = factoryInfo.Factory.GenerateGlyph(line, tag);
					if (elem == null)
						continue;
					elem.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
					var iconInfo = new IconInfo(factoryInfo.Order, elem);
					icons.Add(iconInfo);
					// ActualWidth isn't always valid when we're here so use the constant
					SetLeft(elem, (MARGIN_WIDTH - elem.DesiredSize.Width) / 2);
					SetTop(elem, iconInfo.BaseTopValue + line.TextTop);
				}
			}
			return icons;
		}
Ejemplo n.º 57
0
		void Update(IWpfTextViewLine line) {
			Debug.Assert(line.VisibilityState != VisibilityState.Unattached);
			LineInfo info;
			if (!lineInfos.TryGetValue(line.IdentityTag, out info))
				return;
			lineInfos.Remove(line.IdentityTag);
			foreach (var iconInfo in info.Icons)
				childCanvases[iconInfo.Order].Children.Remove(iconInfo.Element);
			AddLine(lineInfos, line);
		}