public RoslynBlockTag(
     IThreadingContext threadingContext,
     ITextEditorFactoryService textEditorFactoryService,
     IProjectionBufferFactoryService projectionBufferFactoryService,
     IEditorOptionsFactoryService editorOptionsFactoryService,
     IBlockTag parent,
     ITextSnapshot snapshot,
     BlockSpan blockSpan)
     : base(
         span: blockSpan.TextSpan.ToSnapshotSpan(snapshot),
         statementSpan: blockSpan.HintSpan.ToSnapshotSpan(snapshot),
         parent: parent,
         type: blockSpan.Type,
         isCollapsible: blockSpan.IsCollapsible,
         isDefaultCollapsed: blockSpan.IsDefaultCollapsed,
         isImplementation: blockSpan.AutoCollapse,
         collapsedForm: null,
         collapsedHintForm: null)
 {
     _state = new BlockTagState(
         threadingContext,
         textEditorFactoryService, projectionBufferFactoryService,
         editorOptionsFactoryService, snapshot, blockSpan);
     Level = parent == null ? 0 : parent.Level + 1;
 }
 public VisibleBlock(IBlockTag tag, double x, double yTop, double yBottom)
 {
     this.tag     = tag;
     this.x       = x;
     this.yTop    = yTop;
     this.yBottom = yBottom;
 }
Esempio n. 3
0
 public RoslynBlockContext(
     RoslynBlockContextProvider provider,
     IBlockTag blockTag,
     ITextView textView)
 {
     _provider = provider;
     BlockTag = blockTag;
     TextView = textView;
 }
Esempio n. 4
0
 public RoslynBlockContext(
     RoslynBlockContextProvider provider,
     IBlockTag blockTag,
     ITextView textView)
 {
     _provider = provider;
     BlockTag  = blockTag;
     TextView  = textView;
 }
Esempio n. 5
0
        public bool UpdateTip(IVerticalScrollBar margin, MouseEventArgs e, ToolTip tip)
        {
            if ((!_textView.IsClosed) && (_tagger != null) && _previewEnabled)
            {
                Point pt = e.GetPosition(this);
                if ((pt.X >= 0.0) && (pt.X <= this.Width))
                {
                    SnapshotPoint position = _scrollBar.GetBufferPositionOfYCoordinate(pt.Y);

                    IBlockTag deepestTag = null;
                    var       tags       = _tagger.GetTags(new SnapshotSpan(position, 0));
                    foreach (var tagSpan in tags)
                    {
                        if (tagSpan.Tag.Type != BlockType.Unknown)
                        {
                            if ((deepestTag == null) || (tagSpan.Tag.Level > deepestTag.Level))
                            {
                                deepestTag = tagSpan.Tag;
                            }
                        }
                    }

                    if (deepestTag != null)
                    {
                        if (tip.IsOpen)
                        {
                            var existingContext = tip.Content as FrameworkElement;
                            if ((existingContext != null) && (existingContext.Tag == deepestTag))
                            {
                                // No changes from the last time we opened the tip.
                                return(true);
                            }
                        }

                        FrameworkElement context = deepestTag.Context(_coloring,
                                                                      _textView.FormattedLineSource.DefaultTextProperties);

                        context.Tag = deepestTag;

                        //The width of the view is in zoomed coordinates so factor the zoom factor into the tip window width computation.
                        double zoom = _textView.ZoomLevel / 100.0;
                        tip.MinWidth  = tip.MaxWidth = Math.Floor(Math.Max(50.0, _textView.ViewportWidth * zoom * 0.5));
                        tip.MinHeight = tip.MaxHeight = context.Height + 12.0;

                        tip.Content = context;
                        tip.IsOpen  = true;

                        StructureMarginElement.LogTipOpened("VS/PPT-Structure/MarginTipOpened", context);

                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 6
0
 public RoslynBlockContext(
     RoslynBlockContextProvider provider,
     IBlockTag blockTag,
     ITextView textView)
     : base(provider.ThreadingContext)
 {
     _provider = provider;
     BlockTag  = blockTag;
     TextView  = textView;
 }
Esempio n. 7
0
            private void AddBlockTags(List <IBlockTag> result, IBlockTag blockTag)
            {
                if (blockTag == null)
                {
                    return;
                }

                AddBlockTags(result, blockTag.Parent);
                result.Add(blockTag);
            }
Esempio n. 8
0
            public Task<IBlockContext> GetBlockContextAsync(
                IBlockTag blockTag, ITextView view, CancellationToken token)
            {
                if (blockTag is RoslynOutliningRegionTag)
                {
                    var result = new RoslynBlockContext(_provider, blockTag, view);
                    return Task.FromResult<IBlockContext>(result);
                }

                return SpecializedTasks.Default<IBlockContext>();
            }
Esempio n. 9
0
            public Task <IBlockContext> GetBlockContextAsync(
                IBlockTag blockTag, ITextView view, CancellationToken token)
            {
                if (blockTag is RoslynBlockTag)
                {
                    var result = new RoslynBlockContext(_provider, blockTag, view);
                    return(Task.FromResult <IBlockContext>(result));
                }

                return(SpecializedTasks.Default <IBlockContext>());
            }
Esempio n. 10
0
 public BlockTag(SnapshotSpan span, SnapshotSpan statementSpan, IBlockTag parent, string type, bool isCollapsible, bool isDefaultCollapsed, bool isImplementation, object collapsedForm, object collapsedHintForm)
 {
     this.Span               = span;
     this.Level              = (parent == null) ? 0 : (parent.Level + 1);
     this.StatementSpan      = statementSpan;
     this.Parent             = parent;
     this.Type               = type;
     this.IsCollapsible      = isCollapsible;
     this.IsDefaultCollapsed = isDefaultCollapsed;
     this.IsImplementation   = isImplementation;
     this.CollapsedForm      = collapsedForm;
     this.CollapsedHintForm  = collapsedHintForm;
 }
 public RoslynBlockTag(
     ITextEditorFactoryService textEditorFactoryService,
     IProjectionBufferFactoryService projectionBufferFactoryService,
     IEditorOptionsFactoryService editorOptionsFactoryService,
     IBlockTag parent,
     ITextSnapshot snapshot,
     BlockSpan blockSpan) :
     base(textEditorFactoryService,
          projectionBufferFactoryService,
          editorOptionsFactoryService,
          snapshot, blockSpan)
 {
     Parent        = parent;
     Level         = parent == null ? 0 : parent.Level + 1;
     Span          = blockSpan.TextSpan.ToSnapshotSpan(snapshot);
     StatementSpan = blockSpan.HintSpan.ToSnapshotSpan(snapshot);
 }
Esempio n. 12
0
        public Task <IBlockContext> GetBlockContextAsync(IBlockTag blockTag, ITextView view, CancellationToken token)
        {
            var       contentLines = new List <string>();
            IBlockTag tag          = blockTag;

            do
            {
                string indent = new string(' ', tag.Level * 4);
                string line   = indent + GetStatement(tag);
                contentLines.Add(line);
            }while ((tag = tag.Parent) != null);
            contentLines.Reverse();

            string content = string.Join(Environment.NewLine, contentLines);
            var    context = new BraceBlockContext(view, blockTag, content);

            return(Task.FromResult <IBlockContext>(context));
        }
        public bool UpdateTip(IOverviewMargin margin, MouseEventArgs e, ToolTip tip)
        {
            if (!this.textView.IsClosed)
            {
                Point pt = e.GetPosition(this);
                if ((pt.X >= 0.0) && (pt.X <= MarginWidth))
                {
                    SnapshotPoint position = this.scrollBar.GetBufferPositionOfYCoordinate(pt.Y);

                    IBlockTag deepestTag = null;
                    var       tags       = this.tagger.GetTags(new SnapshotSpan(position, 0));
                    foreach (var tagSpan in tags)
                    {
                        if (tagSpan.Tag.Type != BlockType.Unknown)
                        {
                            if ((deepestTag == null) || (tagSpan.Tag.Level > deepestTag.Level))
                            {
                                deepestTag = tagSpan.Tag;
                            }
                        }
                    }

                    if (deepestTag != null)
                    {
                        tip.IsOpen = true;

                        FrameworkElement context = deepestTag.Context(this.blockColoring,
                                                                      this.textView.FormattedLineSource.DefaultTextProperties.Typeface,
                                                                      this.textView.FormattedLineSource.DefaultTextProperties.FontRenderingEmSize);

                        //The width of the view is in zoomed coordinates so factor the zoom factor into the tip window width computation.
                        double zoom = this.textView.ZoomLevel / 100.0;
                        tip.MinWidth  = tip.MaxWidth = Math.Floor(Math.Max(50.0, this.textView.ViewportWidth * zoom * 0.5));
                        tip.MinHeight = tip.MaxHeight = context.Height + 12.0;

                        tip.Content = context;

                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 14
0
        private static string GetStatement(IBlockTag blockTag)
        {
            string statement       = string.Empty;
            var    snapshot        = blockTag.Span.Snapshot;
            var    braceLine       = snapshot.GetLineFromPosition(blockTag.Span.Start);
            int    braceOffset     = blockTag.Span.Start - braceLine.Start;
            string textBeforeBrace = braceLine.GetText().Substring(0, braceOffset).Trim();

            if (textBeforeBrace.Length > 0)
            {
                statement = textBeforeBrace;
            }
            else if (braceLine.LineNumber > 0)
            {
                var lastLine = snapshot.GetLineFromLineNumber(braceLine.LineNumber - 1);
                statement = lastLine.GetText().Trim();
            }
            return(statement);
        }
Esempio n. 15
0
        /// <summary>
        /// Initializes a new instance of <see cref="IBlockContext"/> with the specified block tag.
        /// </summary>
        /// <param name="blockTag">The block tag associated with the structural block.</param>
        /// <param name="view">The text view associated with the structural block.</param>
        /// <param name="content">The content, including hiearchical parent statements, to be displayed in the tooltip.</param>
        public BlockContext(IBlockTag blockTag, ITextView view, object content)
        {
            if (blockTag == null)
            {
                throw new ArgumentNullException(nameof(blockTag));
            }

            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            _blockTag = blockTag;
            _view     = view;
            _content  = content;
        }
Esempio n. 16
0
 public RoslynBlockTag(
     ITextEditorFactoryService textEditorFactoryService,
     IProjectionBufferFactoryService projectionBufferFactoryService,
     IEditorOptionsFactoryService editorOptionsFactoryService,
     IBlockTag parent,
     ITextSnapshot snapshot,
     BlockSpan blockSpan) :
     base(span: blockSpan.TextSpan.ToSnapshotSpan(snapshot),
          statementSpan: blockSpan.HintSpan.ToSnapshotSpan(snapshot),
          parent: parent,
          type: blockSpan.Type,
          isCollapsible: blockSpan.IsCollapsible,
          isDefaultCollapsed: blockSpan.IsDefaultCollapsed,
          isImplementation: blockSpan.AutoCollapse,
          collapsedForm: null,
          collapsedHintForm: null)
 {
     _state = new BlockTagState(
         textEditorFactoryService, projectionBufferFactoryService,
         editorOptionsFactoryService, snapshot, blockSpan);
     Level = parent == null ? 0 : parent.Level + 1;
 }
        private void CreateBlockAdornment(IBlockTag tag, SnapshotSpan span, double x, double yTop, double yBottom)
        {
            LineGeometry line = new LineGeometry(new Point(x, yTop), new Point(x, yBottom));

            GeometryDrawing drawing = new GeometryDrawing(null, this.blockColoring.GetPen(tag), line);

            drawing.Freeze();

            DrawingImage drawingImage = new DrawingImage(drawing);

            drawingImage.Freeze();

            Image image = new Image();

            image.Source = drawingImage;

            VisibleBlock block = new VisibleBlock(tag, x, yTop, yBottom);

            Canvas.SetLeft(image, x);
            Canvas.SetTop(image, yTop);
            this.layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, block, image, OnAdornmentRemoved);

            this.visibleBlocks.Add(block);
        }
Esempio n. 18
0
 public Color GetColor(IBlockTag tag)
 {
     return this.GetColoring(tag.Type).Color;
 }
Esempio n. 19
0
            private void AddBlockTags(List<IBlockTag> result, IBlockTag blockTag)
            {
                if (blockTag == null)
                {
                    return;
                }

                AddBlockTags(result, blockTag.Parent);
                result.Add(blockTag);
            }
Esempio n. 20
0
 public Brush GetLineBrush(IBlockTag tag)
 {
     return this.GetColoring(tag.Type).LineBrush;
 }
Esempio n. 21
0
 public Pen GetLinePen(IBlockTag tag)
 {
     return this.GetColoring(tag.Type).LinePen;
 }
Esempio n. 22
0
 public Brush GetToolTipBrush(IBlockTag tag)
 {
     return this.GetColoring(tag.Type).ToolTipBrush;
 }
Esempio n. 23
0
 public Pen GetToolTipPen(IBlockTag tag)
 {
     return this.GetColoring(tag.Type).ToolTipPen;
 }
Esempio n. 24
0
 public Color GetColor(IBlockTag tag)
 {
     return(this.GetColoring(tag.Type).Color);
 }
Esempio n. 25
0
 public Brush GetBrush(IBlockTag tag)
 {
     return(this.GetColoring(tag.Type).Brush);
 }
Esempio n. 26
0
 public Pen GetPen(IBlockTag tag)
 {
     return(this.GetColoring(tag.Type).Pen);
 }
Esempio n. 27
0
 public BraceBlockContext(ITextView textView, IBlockTag blockTag, object content)
 {
     TextView = textView;
     BlockTag = blockTag;
     Content  = content;
 }
Esempio n. 28
0
 public BraceBlockTag(SnapshotSpan span, SnapshotSpan statementSpan, IBlockTag parent) :
     base(span, statementSpan, parent, "block", true, true, true, "...", GetCollapsedFormHint(span))
 {
     _text = span.GetText();
 }