Skip to content

Commit d6295d9

Browse files
committed
ux: new style for command log times
Signed-off-by: leo <[email protected]>
1 parent 47910b3 commit d6295d9

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

src/Views/CommandLogTime.cs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Threading;
33

4-
using Avalonia;
54
using Avalonia.Controls;
65
using Avalonia.Interactivity;
76
using Avalonia.Threading;
@@ -10,15 +9,6 @@ namespace SourceGit.Views
109
{
1110
public class CommandLogTime : TextBlock
1211
{
13-
public static readonly StyledProperty<ViewModels.CommandLog> LogProperty =
14-
AvaloniaProperty.Register<CommandLogTime, ViewModels.CommandLog>(nameof(Log));
15-
16-
public ViewModels.CommandLog Log
17-
{
18-
get => GetValue(LogProperty);
19-
set => SetValue(LogProperty, value);
20-
}
21-
2212
protected override Type StyleKeyOverride => typeof(TextBlock);
2313

2414
protected override void OnUnloaded(RoutedEventArgs e)
@@ -27,19 +17,16 @@ protected override void OnUnloaded(RoutedEventArgs e)
2717
StopTimer();
2818
}
2919

30-
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
20+
protected override void OnDataContextChanged(EventArgs e)
3121
{
32-
base.OnPropertyChanged(change);
22+
base.OnDataContextChanged(e);
3323

34-
if (change.Property == LogProperty)
35-
{
36-
StopTimer();
24+
StopTimer();
3725

38-
if (change.NewValue is ViewModels.CommandLog log)
39-
SetupCommandLog(log);
40-
else
41-
Text = string.Empty;
42-
}
26+
if (DataContext is ViewModels.CommandLog log)
27+
SetupCommandLog(log);
28+
else
29+
Text = string.Empty;
4330
}
4431

4532
private void SetupCommandLog(ViewModels.CommandLog log)
@@ -74,12 +61,12 @@ private static string GetDisplayText(ViewModels.CommandLog log)
7461
var duration = endTime - log.StartTime;
7562

7663
if (duration.TotalMinutes >= 1)
77-
return $"{log.StartTime:T} ({duration.TotalMinutes:G3} minutes)";
64+
return $"{duration.TotalMinutes:G3} min";
7865

7966
if (duration.TotalSeconds >= 1)
80-
return $"{log.StartTime:T} ({duration.TotalSeconds:G3} s)";
67+
return $"{duration.TotalSeconds:G3} s";
8168

82-
return $"{log.StartTime:T} ({duration.TotalMilliseconds:G3} ms)";
69+
return $"{duration.TotalMilliseconds:G3} ms";
8370
}
8471

8572
private Timer _refreshTimer = null;

src/Views/ViewLogs.axaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@
7878
<Grid.ColumnDefinitions>
7979
<ColumnDefinition Width="Auto"/>
8080
<ColumnDefinition Width="*"/>
81-
<ColumnDefinition Width="Auto" SharedSizeGroup="TimeColumn"/>
81+
<ColumnDefinition Width="Auto" SharedSizeGroup="StartTimeColumn"/>
82+
<ColumnDefinition Width="Auto" SharedSizeGroup="DurationColumn"/>
8283
</Grid.ColumnDefinitions>
84+
8385
<v:LoadingIcon Grid.Column="0"
8486
Width="14" Height="14"
8587
Margin="4,0,4,0"
@@ -91,12 +93,16 @@
9193
Text="{Binding Name}"
9294
VerticalAlignment="Center"
9395
TextTrimming="CharacterEllipsis"/>
96+
97+
<TextBlock Grid.Column="2"
98+
Margin="4,0"
99+
Foreground="{DynamicResource Brush.FG2}"
100+
Text="{Binding StartTime, StringFormat=HH:mm:ss}"/>
94101

95-
<v:CommandLogTime Grid.Column="2"
102+
<v:CommandLogTime Grid.Column="3"
96103
Classes="primary"
97104
Margin="4,0"
98105
Foreground="{DynamicResource Brush.FG2}"
99-
Log="{Binding}"
100106
HorizontalAlignment="Right" VerticalAlignment="Center"/>
101107
</Grid>
102108
</DataTemplate>

0 commit comments

Comments
 (0)