Example #1
0
        private double CalculateMarginWidth()
        {
            var settings = Settings.Load();

            if (settings.ShowTimeStamps == false)
            {
                return(0);
            }
            var pixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip;

            var timeFormat = TimeStampFormatter.FormatTime(new TimeSpan(0), _cultureInfo, ShowHoursInTimeStamps);
            var text       = new FormattedText(
                ShowTimeStampOnEveryLine ? timeFormat : $"{timeFormat} ({timeFormat})",
                CultureInfo.InvariantCulture,
                FlowDirection.LeftToRight,
                _textRunProperties.Typeface,
                _textRunProperties.FontRenderingEmSize,
                Brushes.Black,
                pixelsPerDip);

            return(text.Width + 3);
        }
Example #2
0
        private void Update()
        {
            var hashSet = new HashSet <object>();

            foreach (var textViewLine in _textView.TextViewLines.Where(textViewLine => textViewLine.IsFirstTextViewLineForSnapshotLine))
            {
                hashSet.Add(textViewLine.IdentityTag);
            }

            var dictionary = new Dictionary <object, TimeStampVisual>();
            var list1      = new List <int>();

            for (var index = _translatedCanvas.Children.Count - 1; index >= 0; --index)
            {
                var timeStampVisual = _translatedCanvas.Children[index] as TimeStampVisual;
                if (timeStampVisual != null)
                {
                    if (hashSet.Contains(timeStampVisual.LineTag))
                    {
                        dictionary.Add(timeStampVisual.LineTag, timeStampVisual);
                    }
                    else
                    {
                        list1.Add(index);
                    }
                }
            }

            var list2 = new List <TimeStampVisual>();

            foreach (var line in _textView.TextViewLines)
            {
                if (ShowTimeStampOnEveryLine || line.IsFirstTextViewLineForSnapshotLine)
                {
                    var lineNumber = line.Start.GetContainingLine().LineNumber;
                    if (lineNumber < _lineTimeStamps.Count)
                    {
                        var             timeStamp         = _lineTimeStamps[lineNumber];
                        var             previousTimeStamp = _lineTimeStamps[Math.Max(lineNumber - 1, 0)];
                        TimeStampVisual timeStampVisual;
                        if (!dictionary.TryGetValue(line.IdentityTag, out timeStampVisual))
                        {
                            var index = list1.Count - 1;
                            if (index < 0)
                            {
                                timeStampVisual = new TimeStampVisual();
                                list2.Add(timeStampVisual);
                            }
                            else
                            {
                                timeStampVisual = _translatedCanvas.Children[list1[index]] as TimeStampVisual;
                                list1.RemoveAt(index);
                            }
                        }

                        if (timeStampVisual != null)
                        {
                            var startDiff = timeStamp - BuildEventsProvider.BuildEvents.DebugStartTime;
                            var text      = "";
                            if (ShowTimeStampOnEveryLine)
                            {
                                text = TimeStampFormatter.FormatTime(startDiff, _cultureInfo, ShowHoursInTimeStamps);
                            }
                            else
                            {
                                var lastDiff = timeStamp - previousTimeStamp;
                                if (lineNumber == 0 || lastDiff != TimeSpan.Zero)
                                {
                                    text = TimeStampFormatter.FormatTime(startDiff, _cultureInfo, ShowHoursInTimeStamps) +
                                           $" ({TimeStampFormatter.FormatTime(lastDiff, _cultureInfo, ShowHoursInTimeStamps)})";
                                }
                            }

                            timeStampVisual.Update(text, line, _textView, _textRunProperties, MinWidth, _oldViewportTop);
                        }
                    }
                }
            }

            foreach (var index in list1)
            {
                _translatedCanvas.Children.RemoveAt(index);
            }
            foreach (var element in list2)
            {
                _translatedCanvas.Children.Add(element);
            }
        }