1+ using System . Collections . Specialized ;
12using Avalonia . Controls ;
3+ using Avalonia . Controls . Documents ;
24using Avalonia . Threading ;
35using UniGetUI . Avalonia . ViewModels . DialogPages ;
6+ using UniGetUI . Avalonia . ViewModels . Pages . LogPages ;
47using UniGetUI . PackageOperations ;
58
69namespace UniGetUI . Avalonia . Views . DialogPages ;
@@ -9,11 +12,39 @@ public partial class OperationOutputWindow : Window
912{
1013 public OperationOutputWindow ( AbstractOperation operation )
1114 {
12- DataContext = new OperationOutputViewModel ( operation ) ;
15+ var vm = new OperationOutputViewModel ( operation ) ;
16+ DataContext = vm ;
1317 InitializeComponent ( ) ;
1418
15- ( ( OperationOutputViewModel ) DataContext ) . OutputLines . CollectionChanged +=
16- ( _ , _ ) => Dispatcher . UIThread . Post ( OutputScroll . ScrollToEnd , DispatcherPriority . Background ) ;
19+ foreach ( var line in vm . OutputLines )
20+ AppendLine ( line ) ;
21+
22+ vm . OutputLines . CollectionChanged += OnOutputLinesChanged ;
23+ }
24+
25+ private void OnOutputLinesChanged ( object ? sender , NotifyCollectionChangedEventArgs e )
26+ {
27+ Dispatcher . UIThread . Post ( ( ) =>
28+ {
29+ if ( e . Action == NotifyCollectionChangedAction . Reset )
30+ {
31+ OutputText . Inlines ? . Clear ( ) ;
32+ }
33+ else if ( e . NewItems is not null )
34+ {
35+ foreach ( LogLineItem item in e . NewItems )
36+ AppendLine ( item ) ;
37+ }
38+ OutputScroll . ScrollToEnd ( ) ;
39+ } , DispatcherPriority . Background ) ;
40+ }
41+
42+ private void AppendLine ( LogLineItem line )
43+ {
44+ var inlines = OutputText . Inlines ??= new InlineCollection ( ) ;
45+ if ( inlines . Count > 0 )
46+ inlines . Add ( new LineBreak ( ) ) ;
47+ inlines . Add ( new Run ( line . Text ) { Foreground = line . Foreground } ) ;
1748 }
1849
1950 protected override void OnOpened ( EventArgs e )
0 commit comments