示例#1
0
 /// <summary>
 /// Creates an instance of ElasticTabstopsFormatter
 /// </summary>
 internal ElasticTabstopsFormatter(
     TextFormattingRunProperties textProperties,
     IFormattedLineSource formattedLineSource, double[] tabSizes)
     : base(textProperties, formattedLineSource.ColumnWidth * formattedLineSource.TabSize)
 {
     _tabSizes = tabSizes;
 }
        /// <summary>
        /// Creates an ElasticTabstopsFormatters for
        /// the provided configuration.
        /// </summary>
        public TextParagraphProperties Create(IFormattedLineSource formattedLineSource, TextFormattingRunProperties textProperties,
                                              IMappingSpan line, IMappingPoint lineStart, int lineSegment)
        {
            if (!AlwaysAlignedConfigurationService.Instance.GetConfiguration().Enabled)
            {
                return(new TextFormattingParagraphProperties(textProperties, formattedLineSource.ColumnWidth * formattedLineSource.TabSize));
            }

            IWpfTextView textView = _textBufferToViewMapService.GetViewByFormattedLineSource(formattedLineSource);

            //View is not initialized yet
            if (textView == null)
            {
                return(new TextFormattingParagraphProperties(textProperties, formattedLineSource.ColumnWidth * formattedLineSource.TabSize));
            }
            var manager = ElasticTabstopsSizeManager.Get(textView);

            ITextSnapshot textSnapshot = formattedLineSource.SourceTextSnapshot;
            ITextBuffer   textBuffer   = textSnapshot.TextBuffer;

            var normalizedspancoll        = line.GetSpans(textBuffer);
            ITextSnapshotLine currentLine = textSnapshot.GetLineFromPosition(normalizedspancoll.First().Start.Position);

            //Get tab offset calculated by ElasticTabstopsSizeManager
            double[] tabOffsets = manager.GetTabOffsets(currentLine);

            return(new ElasticTabstopsFormatter(textProperties, formattedLineSource, tabOffsets));
        }
示例#3
0
        private double CalculateLeftOfFirstChar(SnapshotPoint open, IFormattedLineSource fls)
        {
            var line  = open.GetContainingLine();
            var x     = 0d;
            var start = line.Start;
            int spacesSinceLastTab = 0;

            while (Char.IsWhiteSpace(start.GetChar()))
            {
                char ch = start.GetChar();
                if (ch == ' ')
                {
                    spacesSinceLastTab = ++spacesSinceLastTab % fls.TabSize;
                    x += fls.ColumnWidth;
                }
                else if (ch == '\t')
                {
                    x += ((fls.TabSize - spacesSinceLastTab) * fls.ColumnWidth);
                    spacesSinceLastTab = 0;
                }
                //x += start.GetChar() == '\t' ? fls.TabSize * fls.ColumnWidth : fls.ColumnWidth;
                start = start + 1;
            }
            return(x);
        }
示例#4
0
        static PhysicalLine CreatePhysicalLineNoCache(IFormattedLineSource formattedLineSource, ITextViewModel textViewModel, ITextSnapshot visualSnapshot, SnapshotPoint bufferPosition)
        {
            var visualPoint = textViewModel.GetNearestPointInVisualSnapshot(bufferPosition, visualSnapshot, PointTrackingMode.Positive);
            var lines       = formattedLineSource.FormatLineInVisualBuffer(visualPoint.GetContainingLine());

            Debug.Assert(lines.Count > 0);
            return(new PhysicalLine(bufferPosition.GetContainingLine(), lines));
        }
示例#5
0
			public bool TryUpdateState() {
				if (toXPosDictSnapshot != wpfTextView.TextSnapshot || formattedLineSource != wpfTextView.FormattedLineSource) {
					Clear();
					toXPosDictSnapshot = wpfTextView.TextSnapshot;
					formattedLineSource = wpfTextView.FormattedLineSource;
					return true;
				}
				return false;
			}
        public PowerShellTextFormattingParagraphProperties(TextFormattingRunProperties textProperties,
                                                           IFormattedLineSource formattedLineSource,
                                                           IServiceProvider serviceProvider)
            : base(textProperties)
        {
            ServiceProvider = serviceProvider;
            ColumnWidth     = formattedLineSource.ColumnWidth;
            var dte = (DTE)ServiceProvider.GetService(typeof(DTE));

            UpdateProperties(formattedLineSource, dte);
        }
        public PowerShellTextFormattingParagraphProperties( TextFormattingRunProperties textProperties,
            IFormattedLineSource formattedLineSource,
            IServiceProvider serviceProvider)
            : base(textProperties)
        {
            ServiceProvider = serviceProvider;
            ColumnWidth = formattedLineSource.ColumnWidth;
            var dte = (DTE) ServiceProvider.GetService( typeof (DTE) );

            UpdateProperties( formattedLineSource, dte );
        }
示例#8
0
        public static IWpfTextView CreateWpfTextView(ITextSnapshot snapshot = null, IFormattedLineSource formattedLineSource = null)
        {
            snapshot = snapshot ?? CreateSnapshot();
            var lineSource = formattedLineSource ?? CreateFormattedLineSource();

            var viewMock = new Mock <IWpfTextView>();

            viewMock.Setup(x => x.TextSnapshot).Returns(snapshot);
            viewMock.Setup(x => x.FormattedLineSource).Returns(lineSource);
            viewMock.Setup(x => x.TextBuffer).Returns(CreateBuffer());
            return(viewMock.Object);
        }
示例#9
0
        public void Update(IFormattedLineSource formattedLineSource)
        {
            var textBlock = Child as TextBlock;

            textBlock.Foreground = formattedLineSource.DefaultTextProperties.ForegroundBrush;
            textBlock.FontSize   = formattedLineSource.DefaultTextProperties.FontRenderingEmSize - 2;
            textBlock.FontFamily = formattedLineSource.DefaultTextProperties.Typeface.FontFamily;

            var themeColors = ThemeColors.BasedOnText(textBlock.Foreground);

            Background  = themeColors.BackgroundBrush;
            BorderBrush = themeColors.BorderBrush;
        }
示例#10
0
        private double CalculateLeftOfFirstChar(SnapshotPoint open, IFormattedLineSource fls)
        {
            var line  = open.GetContainingLine();
            var x     = 0d;
            var start = line.Start;

            while (Char.IsWhiteSpace(start.GetChar()))
            {
                x    += start.GetChar() == '\t' ? fls.TabSize * fls.ColumnWidth : fls.ColumnWidth;
                start = start + 1;
            }
            return(x);
        }
 /// <summary>
 ///   Creates a <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> for the provided configuration.
 /// </summary>
 /// <param name = "formattedLineSource">The <see cref = "T:Microsoft.VisualStudio.Text.Formatting.IFormattedLineSource" /> that's performing the formatting of the line. You can access useful properties about the ongoing formatting operation from this object.</param>
 /// <param name = "textProperties">The <see cref = "T:Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties" /> of the line for which <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> are to be provided. This paramter can be used to obtain formatting information about the textual contents of the line.</param>
 /// <param name = "line">The <see cref = "T:Microsoft.VisualStudio.Text.IMappingSpan" /> corresponding to the line that's being formatted/rendered.</param>
 /// <param name = "lineStart">The <see cref = "T:Microsoft.VisualStudio.Text.IMappingPoint" /> corresponding to the beginning of the line segment that's being formatted. This paramter is relevant for word-wrap scenarios where a single <see cref = "T:Microsoft.VisualStudio.Text.ITextSnapshotLine" /> results in multiple formatted/rendered lines on the view.</param>
 /// <param name = "lineSegment">The segment number of the line segment that's been currently formatted. This is a zero-based index and is applicable to word-wrapped lines. If a line is word-wrapped into 4 segments, you will receive 4 calls for the line with lineSegments of 0, 1, 2, and 3.</param>
 /// <returns>
 ///   A <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> to be used when the line is being formatted.
 /// </returns>
 /// <remarks>
 ///   Please note that you can return a <see cref = "T:Microsoft.VisualStudio.Text.Formatting.TextFormattingParagraphProperties" /> which has a convenient set of basic properties defined.
 /// </remarks>
 public TextParagraphProperties Create( IFormattedLineSource formattedLineSource,
     TextFormattingRunProperties textProperties,
     IMappingSpan line,
     IMappingPoint lineStart,
     int lineSegment)
 {
     if (_TextParagraphProperties == null)
     {
         _TextParagraphProperties = new PowerShellTextFormattingParagraphProperties( textProperties,
                                                                                     formattedLineSource,
                                                                                     ServiceProvider );
     }
     return TextParagraphProperties;
 }
 /// <summary>
 ///   Creates a <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> for the provided configuration.
 /// </summary>
 /// <param name = "formattedLineSource">The <see cref = "T:Microsoft.VisualStudio.Text.Formatting.IFormattedLineSource" /> that's performing the formatting of the line. You can access useful properties about the ongoing formatting operation from this object.</param>
 /// <param name = "textProperties">The <see cref = "T:Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties" /> of the line for which <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> are to be provided. This paramter can be used to obtain formatting information about the textual contents of the line.</param>
 /// <param name = "line">The <see cref = "T:Microsoft.VisualStudio.Text.IMappingSpan" /> corresponding to the line that's being formatted/rendered.</param>
 /// <param name = "lineStart">The <see cref = "T:Microsoft.VisualStudio.Text.IMappingPoint" /> corresponding to the beginning of the line segment that's being formatted. This paramter is relevant for word-wrap scenarios where a single <see cref = "T:Microsoft.VisualStudio.Text.ITextSnapshotLine" /> results in multiple formatted/rendered lines on the view.</param>
 /// <param name = "lineSegment">The segment number of the line segment that's been currently formatted. This is a zero-based index and is applicable to word-wrapped lines. If a line is word-wrapped into 4 segments, you will receive 4 calls for the line with lineSegments of 0, 1, 2, and 3.</param>
 /// <returns>
 ///   A <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> to be used when the line is being formatted.
 /// </returns>
 /// <remarks>
 ///   Please note that you can return a <see cref = "T:Microsoft.VisualStudio.Text.Formatting.TextFormattingParagraphProperties" /> which has a convenient set of basic properties defined.
 /// </remarks>
 public TextParagraphProperties Create(IFormattedLineSource formattedLineSource,
                                       TextFormattingRunProperties textProperties,
                                       IMappingSpan line,
                                       IMappingPoint lineStart,
                                       int lineSegment)
 {
     if (_TextParagraphProperties == null)
     {
         _TextParagraphProperties = new PowerShellTextFormattingParagraphProperties(textProperties,
                                                                                    formattedLineSource,
                                                                                    ServiceProvider);
     }
     return(TextParagraphProperties);
 }
        private void UpdateProperties(IFormattedLineSource formattedLineSource, DTE dte)
        {
            Properties properties = dte.Properties[LanguageConfiguration.Name, "PowerStudio"];

            if (properties == null)
            {
                InitialTabSize         = 4;
                _DefaultIncrementalTab = formattedLineSource.ColumnWidth * formattedLineSource.TabSize;
                return;
            }

            InitialTabSize = (int)properties.Item("InitialTabSize").Value;
            var normalTabSize = (int)properties.Item("NormalTabSize").Value;

            normalTabSize          = (normalTabSize != 0 ? normalTabSize : formattedLineSource.TabSize);
            _DefaultIncrementalTab = formattedLineSource.ColumnWidth * normalTabSize;
        }
			public LayoutHelper(ILineTransformProvider lineTransformProvider, double newViewportTop, HashSet<ITextViewLine> oldVisibleLines, List<PhysicalLine> oldLines, IFormattedLineSource formattedLineSource, ITextViewModel textViewModel, ITextSnapshot visualSnapshot, ITextSnapshot editSnapshot) {
				this.lineTransformProvider = lineTransformProvider;
				requestedViewportTop = newViewportTop;
				this.oldLines = oldLines;
				this.formattedLineSource = formattedLineSource;
				this.textViewModel = textViewModel;
				this.visualSnapshot = visualSnapshot;
				toPhysicalLine = new Dictionary<IFormattedLine, PhysicalLine>();
				this.oldVisibleLines = oldVisibleLines;

				Debug.Assert(oldLines.All(a => a.BufferSpan.Snapshot == editSnapshot));
				foreach (var physLine in oldLines) {
					physLine.TranslateLinesTo(visualSnapshot, editSnapshot);
					foreach (var line in physLine.Lines)
						toPhysicalLine[line] = physLine;
				}
			}
示例#15
0
        public LineNumberFormatTracker(
            IWpfTextView textView,
            IClassificationFormatMap classificationFormatMap,
            IClassificationTypeRegistryService classificationTypeRegistry)
        {
            textView = textView
                       ?? throw new ArgumentNullException(nameof(textView));

            _classificationFormatMap = classificationFormatMap
                                       ?? throw new ArgumentNullException(nameof(classificationFormatMap));

            _classificationTypeRegistry = classificationTypeRegistry
                                          ?? throw new ArgumentNullException(nameof(classificationTypeRegistry));

            _formattedLineSource = textView.FormattedLineSource;

            _classificationFormatMap.ClassificationFormatMappingChanged += (s, e) => UpdateFormat();

            UpdateFormat();
        }
            public LayoutHelper(ILineTransformProvider lineTransformProvider, double newViewportTop, HashSet <ITextViewLine> oldVisibleLines, List <PhysicalLine> oldLines, IFormattedLineSource formattedLineSource, ITextViewModel textViewModel, ITextSnapshot visualSnapshot, ITextSnapshot editSnapshot)
            {
                this.lineTransformProvider = lineTransformProvider;
                requestedViewportTop       = newViewportTop;
                this.oldLines            = oldLines;
                this.formattedLineSource = formattedLineSource;
                this.textViewModel       = textViewModel;
                this.visualSnapshot      = visualSnapshot;
                toPhysicalLine           = new Dictionary <IFormattedLine, PhysicalLine>();
                this.oldVisibleLines     = oldVisibleLines;

                Debug.Assert(oldLines.All(a => a.BufferSpan.Snapshot == editSnapshot));
                foreach (var physLine in oldLines)
                {
                    physLine.TranslateLinesTo(visualSnapshot, editSnapshot);
                    foreach (var line in physLine.Lines)
                    {
                        toPhysicalLine[line] = physLine;
                    }
                }
            }
示例#17
0
        void OnViewLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
        {
            bool fUpdatePositions = false;

            IFormattedLineSource lineSource = _view.FormattedLineSource;

            if (lineSource == null)
            {
                return;
            }

            if (_columnWidth != lineSource.ColumnWidth)
            {
                _columnWidth     = lineSource.ColumnWidth;
                fUpdatePositions = true;
            }

            if (_baseIndentation != lineSource.BaseIndentation)
            {
                _baseIndentation = lineSource.BaseIndentation;
                fUpdatePositions = true;
            }

            if (fUpdatePositions ||
                e.VerticalTranslation ||
                e.NewViewState.ViewportTop != e.OldViewState.ViewportTop ||
                e.NewViewState.ViewportBottom != e.OldViewState.ViewportBottom)
            {
                UpdatePositions();
            }

            if (!_firstLayoutDone)
            {
                AddGuidelinesToAdornmentLayer();
                _firstLayoutDone = true;
            }
        }
        private void UpdateProperties( IFormattedLineSource formattedLineSource, DTE dte )
        {
            Properties properties = dte.Properties[LanguageConfiguration.Name, "PowerStudio"];

            if ( properties == null )
            {
                InitialTabSize = 4;
                _DefaultIncrementalTab = formattedLineSource.ColumnWidth * formattedLineSource.TabSize;
                return;
            }

            InitialTabSize = (int) properties.Item( "InitialTabSize" ).Value;
            var normalTabSize = (int) properties.Item( "NormalTabSize" ).Value;
            normalTabSize = ( normalTabSize != 0 ? normalTabSize : formattedLineSource.TabSize );
            _DefaultIncrementalTab = formattedLineSource.ColumnWidth * normalTabSize;
        }
        private static void ChangedMockedLineSource(IWpfTextView textView, IFormattedLineSource newLineSource)
        {
            var mock = ((IMocked <IWpfTextView>)textView).Mock;

            mock.Setup(x => x.FormattedLineSource).Returns(newLineSource);
        }
 /// <summary>
 /// Return view that contains given IFormattedLineSource
 /// </summary>
 public IWpfTextView GetViewByFormattedLineSource(IFormattedLineSource formattedLineSource)
 {
     return(_wpfTextViewList.FirstOrDefault(view => view.FormattedLineSource == formattedLineSource));
 }
示例#21
0
        public IssueLocationAdornment(IAnalysisIssueLocationVisualization locationViz, IFormattedLineSource formattedLineSource)
        {
            // We can't store the formatted line source since it might change
            // e.g. if the user changes the font size
            LocationViz = locationViz;

            Margin          = new Thickness(3, 0, 3, 0); // Space between this UI element and the editor text
            Padding         = new Thickness(0);          // Space between the side of the control and its content
            BorderThickness = new Thickness(1);
            CornerRadius    = new CornerRadius(1);

            // Visible content of the adornment
            Child = new TextBlock
            {
                Text       = LocationViz.StepNumber.ToString(),
                FontWeight = FontWeights.SemiBold,
                Padding    = new Thickness(4, 0, 4, 0)
            };

            ToolTip = new TextBlock
            {
                Text = LocationViz.Location.Message
            };

            Update(formattedLineSource);
        }
 public void Clear()
 {
     toXPosDict.Clear();
     toXPosDictSnapshot  = null;
     formattedLineSource = null;
 }
示例#23
0
		static PhysicalLine CreatePhysicalLineNoCache(IFormattedLineSource formattedLineSource, ITextViewModel textViewModel, ITextSnapshot visualSnapshot, SnapshotPoint bufferPosition) {
			var visualPoint = textViewModel.GetNearestPointInVisualSnapshot(bufferPosition, visualSnapshot, PointTrackingMode.Positive);
			var lines = formattedLineSource.FormatLineInVisualBuffer(visualPoint.GetContainingLine());
			Debug.Assert(lines.Count > 0);
			return new PhysicalLine(bufferPosition.GetContainingLine(), lines);
		}