mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 04:04:59 +00:00
feature: show command running time in logs window (#1253)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
825b74c2a3
commit
63803c9b88
3 changed files with 95 additions and 7 deletions
|
@ -18,6 +18,12 @@ namespace SourceGit.ViewModels
|
||||||
get;
|
get;
|
||||||
} = DateTime.Now;
|
} = DateTime.Now;
|
||||||
|
|
||||||
|
public DateTime EndTime
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
} = DateTime.Now;
|
||||||
|
|
||||||
public bool IsComplete
|
public bool IsComplete
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
@ -64,6 +70,8 @@ namespace SourceGit.ViewModels
|
||||||
_builder.Clear();
|
_builder.Clear();
|
||||||
_builder = null;
|
_builder = null;
|
||||||
|
|
||||||
|
EndTime = DateTime.Now;
|
||||||
|
|
||||||
OnPropertyChanged(nameof(IsComplete));
|
OnPropertyChanged(nameof(IsComplete));
|
||||||
|
|
||||||
if (_onNewLineReceived != null)
|
if (_onNewLineReceived != null)
|
||||||
|
|
80
src/Views/CommandLogTime.cs
Normal file
80
src/Views/CommandLogTime.cs
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
|
||||||
|
namespace SourceGit.Views
|
||||||
|
{
|
||||||
|
public class CommandLogTime : TextBlock
|
||||||
|
{
|
||||||
|
public static readonly StyledProperty<ViewModels.CommandLog> LogProperty =
|
||||||
|
AvaloniaProperty.Register<CommandLogTime, ViewModels.CommandLog>(nameof(Log), null);
|
||||||
|
|
||||||
|
public ViewModels.CommandLog Log
|
||||||
|
{
|
||||||
|
get => GetValue(LogProperty);
|
||||||
|
set => SetValue(LogProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Type StyleKeyOverride => typeof(TextBlock);
|
||||||
|
|
||||||
|
protected override void OnUnloaded(RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnUnloaded(e);
|
||||||
|
StopTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||||
|
{
|
||||||
|
base.OnPropertyChanged(change);
|
||||||
|
|
||||||
|
if (change.Property == LogProperty)
|
||||||
|
{
|
||||||
|
StopTimer();
|
||||||
|
|
||||||
|
if (change.NewValue is ViewModels.CommandLog log)
|
||||||
|
SetupCommandLog(log);
|
||||||
|
else
|
||||||
|
Text = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupCommandLog(ViewModels.CommandLog log)
|
||||||
|
{
|
||||||
|
Text = GetDisplayText(log);
|
||||||
|
if (log.IsComplete)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_refreshTimer = new Timer(_ =>
|
||||||
|
{
|
||||||
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
|
{
|
||||||
|
Text = GetDisplayText(log);
|
||||||
|
if (log.IsComplete)
|
||||||
|
StopTimer();
|
||||||
|
});
|
||||||
|
}, null, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopTimer()
|
||||||
|
{
|
||||||
|
if (_refreshTimer is { })
|
||||||
|
{
|
||||||
|
_refreshTimer.Dispose();
|
||||||
|
_refreshTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetDisplayText(ViewModels.CommandLog log)
|
||||||
|
{
|
||||||
|
var endTime = log.IsComplete ? log.EndTime : DateTime.Now;
|
||||||
|
var duration = (endTime - log.StartTime).ToString(@"hh\:mm\:ss\.fff");
|
||||||
|
return $"{log.StartTime:T} ({duration})";
|
||||||
|
}
|
||||||
|
|
||||||
|
private Timer _refreshTimer = null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -77,7 +77,7 @@
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
<ColumnDefinition Width="Auto" SharedSizeGroup="SearchCommitTimeColumn"/>
|
<ColumnDefinition Width="Auto" SharedSizeGroup="TimeColumn"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<v:LoadingIcon Grid.Column="0"
|
<v:LoadingIcon Grid.Column="0"
|
||||||
Width="14" Height="14"
|
Width="14" Height="14"
|
||||||
|
@ -91,12 +91,12 @@
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
TextTrimming="CharacterEllipsis"/>
|
TextTrimming="CharacterEllipsis"/>
|
||||||
|
|
||||||
<TextBlock Grid.Column="2"
|
<v:CommandLogTime Grid.Column="2"
|
||||||
Classes="primary"
|
Classes="primary"
|
||||||
Margin="4,0"
|
Margin="4,0"
|
||||||
Foreground="{DynamicResource Brush.FG2}"
|
Foreground="{DynamicResource Brush.FG2}"
|
||||||
Text="{Binding StartTime, StringFormat='{}{0:T}'}"
|
Log="{Binding}"
|
||||||
HorizontalAlignment="Right" VerticalAlignment="Center"/>
|
HorizontalAlignment="Right" VerticalAlignment="Center"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue