ux: new style for command log times

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-07-23 21:38:45 +08:00
parent 47910b346b
commit d6295d91ff
2 changed files with 19 additions and 26 deletions

View File

@@ -1,7 +1,6 @@
using System;
using System.Threading;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;
@@ -10,15 +9,6 @@ namespace SourceGit.Views
{
public class CommandLogTime : TextBlock
{
public static readonly StyledProperty<ViewModels.CommandLog> LogProperty =
AvaloniaProperty.Register<CommandLogTime, ViewModels.CommandLog>(nameof(Log));
public ViewModels.CommandLog Log
{
get => GetValue(LogProperty);
set => SetValue(LogProperty, value);
}
protected override Type StyleKeyOverride => typeof(TextBlock);
protected override void OnUnloaded(RoutedEventArgs e)
@@ -27,19 +17,16 @@ namespace SourceGit.Views
StopTimer();
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
protected override void OnDataContextChanged(EventArgs e)
{
base.OnPropertyChanged(change);
base.OnDataContextChanged(e);
if (change.Property == LogProperty)
{
StopTimer();
StopTimer();
if (change.NewValue is ViewModels.CommandLog log)
SetupCommandLog(log);
else
Text = string.Empty;
}
if (DataContext is ViewModels.CommandLog log)
SetupCommandLog(log);
else
Text = string.Empty;
}
private void SetupCommandLog(ViewModels.CommandLog log)
@@ -74,12 +61,12 @@ namespace SourceGit.Views
var duration = endTime - log.StartTime;
if (duration.TotalMinutes >= 1)
return $"{log.StartTime:T} ({duration.TotalMinutes:G3} minutes)";
return $"{duration.TotalMinutes:G3} min";
if (duration.TotalSeconds >= 1)
return $"{log.StartTime:T} ({duration.TotalSeconds:G3} s)";
return $"{duration.TotalSeconds:G3} s";
return $"{log.StartTime:T} ({duration.TotalMilliseconds:G3} ms)";
return $"{duration.TotalMilliseconds:G3} ms";
}
private Timer _refreshTimer = null;

View File

@@ -78,8 +78,10 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="TimeColumn"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="StartTimeColumn"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="DurationColumn"/>
</Grid.ColumnDefinitions>
<v:LoadingIcon Grid.Column="0"
Width="14" Height="14"
Margin="4,0,4,0"
@@ -91,12 +93,16 @@
Text="{Binding Name}"
VerticalAlignment="Center"
TextTrimming="CharacterEllipsis"/>
<TextBlock Grid.Column="2"
Margin="4,0"
Foreground="{DynamicResource Brush.FG2}"
Text="{Binding StartTime, StringFormat=HH:mm:ss}"/>
<v:CommandLogTime Grid.Column="2"
<v:CommandLogTime Grid.Column="3"
Classes="primary"
Margin="4,0"
Foreground="{DynamicResource Brush.FG2}"
Log="{Binding}"
HorizontalAlignment="Right" VerticalAlignment="Center"/>
</Grid>
</DataTemplate>