1
1
using System ;
2
2
using System . Threading ;
3
3
4
- using Avalonia ;
5
4
using Avalonia . Controls ;
6
5
using Avalonia . Interactivity ;
7
6
using Avalonia . Threading ;
@@ -10,15 +9,6 @@ namespace SourceGit.Views
10
9
{
11
10
public class CommandLogTime : TextBlock
12
11
{
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
-
22
12
protected override Type StyleKeyOverride => typeof ( TextBlock ) ;
23
13
24
14
protected override void OnUnloaded ( RoutedEventArgs e )
@@ -27,19 +17,16 @@ protected override void OnUnloaded(RoutedEventArgs e)
27
17
StopTimer ( ) ;
28
18
}
29
19
30
- protected override void OnPropertyChanged ( AvaloniaPropertyChangedEventArgs change )
20
+ protected override void OnDataContextChanged ( EventArgs e )
31
21
{
32
- base . OnPropertyChanged ( change ) ;
22
+ base . OnDataContextChanged ( e ) ;
33
23
34
- if ( change . Property == LogProperty )
35
- {
36
- StopTimer ( ) ;
24
+ StopTimer ( ) ;
37
25
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 ;
43
30
}
44
31
45
32
private void SetupCommandLog ( ViewModels . CommandLog log )
@@ -74,12 +61,12 @@ private static string GetDisplayText(ViewModels.CommandLog log)
74
61
var duration = endTime - log . StartTime ;
75
62
76
63
if ( duration . TotalMinutes >= 1 )
77
- return $ "{ log . StartTime : T } ( { duration . TotalMinutes : G3} minutes) ";
64
+ return $ "{ duration . TotalMinutes : G3} min ";
78
65
79
66
if ( duration . TotalSeconds >= 1 )
80
- return $ "{ log . StartTime : T } ( { duration . TotalSeconds : G3} s) ";
67
+ return $ "{ duration . TotalSeconds : G3} s";
81
68
82
- return $ "{ log . StartTime : T } ( { duration . TotalMilliseconds : G3} ms) ";
69
+ return $ "{ duration . TotalMilliseconds : G3} ms";
83
70
}
84
71
85
72
private Timer _refreshTimer = null ;
0 commit comments