Skip to content

Commit

Permalink
#47 Add options for timestamp formats
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-ward committed Dec 6, 2019
1 parent 09a21aa commit 6bde466
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
42 changes: 36 additions & 6 deletions VSColorOutput/Output/TimeStamp/TimeStampMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public sealed class TimeStampMargin : Canvas, IWpfTextViewMargin
private readonly Canvas _translatedCanvas = new Canvas();
private readonly List<DateTime> _lineTimeStamps = new List<DateTime>();

private string _elapsedTimeFormat = Settings.DefaultTimeStampFormat;
private string _differenceTimeFormat = Settings.DefaultTimeStampFormat;

private bool _disposed;
private TextRunProperties _textRunProperties;
private double _oldViewportTop = double.MinValue;
Expand Down Expand Up @@ -155,12 +158,18 @@ private void Update()
{
var startDiff = timeStamp - BuildEventsProvider.BuildEvents.DebugStartTime;
var lastDiff = timeStamp - previousTimeStamp;
var text = string.Empty;

var text = lineNumber == 0 || lastDiff != TimeSpan.Zero
? $"{startDiff.Minutes:D2}:{startDiff.Seconds:D2}.{startDiff.Milliseconds:D3} " +
$"({lastDiff.Minutes:D2}:{lastDiff.Seconds:D2}.{lastDiff.Milliseconds:D3})"
: "";

try
{
text = lineNumber == 0 || lastDiff != TimeSpan.Zero
? TimeText(startDiff, lastDiff)
: "";
}
catch (Exception ex)
{
text = ex.Message;
}
timeStampVisual.Update(text, line, _textView, _textRunProperties, MinWidth, _oldViewportTop);
}
}
Expand Down Expand Up @@ -188,14 +197,35 @@ private void UpdateFormatMap()
Update();
}

private string TimeText(TimeSpan elapsed, TimeSpan difference)
{
try
{
var elapsedText = string.IsNullOrWhiteSpace(_elapsedTimeFormat) ? string.Empty : elapsed.ToString(_elapsedTimeFormat);
var differenceText = string.IsNullOrWhiteSpace(_differenceTimeFormat) ? string.Empty : elapsed.ToString(_differenceTimeFormat);

return elapsedText
+ (string.IsNullOrWhiteSpace(differenceText) ? string.Empty : $" {differenceText}");

This comment has been minimized.

Copy link
@kyle-seongwoo-jun

kyle-seongwoo-jun Dec 11, 2019

How about $" ({differenceText})", not $" {differenceText}" ?

image

After updating to 2.7, parentheses are missing.

}
catch (Exception)
{
return "invalid timespan format";
}
}

private double CalculateMarginWidth()
{
var settings = Settings.Load();
if (settings.ShowTimeStamps == false) return 0;
_elapsedTimeFormat = settings.TimeStampElapsed;
_differenceTimeFormat = settings.TimeStampDifference;
var pixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip;

var timespan = TimeSpan.FromHours(12.123);
var sampleTimeText = TimeText(timespan, timespan);

var text = new FormattedText(
"00:00:000 (00:00:000)",
sampleTimeText,
CultureInfo.InvariantCulture,
FlowDirection.LeftToRight,
_textRunProperties.Typeface,
Expand Down
7 changes: 7 additions & 0 deletions VSColorOutput/State/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace VSColorOutput.State
[DataContract]
public class Settings
{
public const string DefaultTimeStampFormat = "mm':'ss':'fff";
public const string RegistryPath = @"DialogPage\BlueOnionSoftware.VsColorOutputOptions";

[DataMember(Order = 0)]
Expand Down Expand Up @@ -72,6 +73,12 @@ public class Settings
[DataMember(Order = 19)]
public Color TimeStampColor { get; set; } = Color.CornflowerBlue;

[DataMember(Order = 20)]
public String TimeStampElapsed { get; set; } = DefaultTimeStampFormat;

[DataMember(Order = 21)]
public String TimeStampDifference { get; set; } = DefaultTimeStampFormat;

private static readonly string ProgramDataFolder;
private static readonly string SettingsFile;

Expand Down
18 changes: 17 additions & 1 deletion VSColorOutput/State/VsColorOutputOptionsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class VsColorOutputOptionsDialog : DialogPage
public const string SubCategory = "General";

private const string PatternsSubCategory = "Classifier Patterns";

// --------------------------------------------------------------------------

[Category(PatternsSubCategory)]
Expand Down Expand Up @@ -124,6 +124,16 @@ public class VsColorOutputOptionsDialog : DialogPage
[DisplayName("Time Stamp")]
public Color TimeStampColor { get; set; }

[Category(TimeStampSubCategory)]
[DisplayName("Time Stamp Elapsed Format")] // extra space because dialog sorts alpha
[Description("Use TimeSpan format strings, NOT DateTime")]
public string TimeStampElapsed { get; set; }

[Category(TimeStampSubCategory)]
[DisplayName("Time Stamp Difference Format")]
[Description("Use TimeSpan format strings, NOT DateTime")]
public string TimeStampDifference { get; set; }

public override void LoadSettingsFromStorage()
{
var settings = Settings.Load();
Expand Down Expand Up @@ -153,6 +163,9 @@ public override void LoadSettingsFromStorage()
FindSearchTermColor = settings.FindSearchTermColor;

TimeStampColor = settings.TimeStampColor;
TimeStampElapsed = settings.TimeStampElapsed;
TimeStampDifference = settings.TimeStampDifference;

SuppressDonation = settings.SuppressDonation;
}

Expand Down Expand Up @@ -185,6 +198,9 @@ public override void SaveSettingsToStorage()
FindSearchTermColor = FindSearchTermColor,
// --
TimeStampColor = TimeStampColor,
TimeStampElapsed = TimeStampElapsed,
TimeStampDifference = TimeStampDifference,
// --
SuppressDonation = SuppressDonation
};
settings.Save();
Expand Down

0 comments on commit 6bde466

Please sign in to comment.