diff --git a/src/UniGetUI/Controls/OperationWidgets/OperationControl.xaml.cs b/src/UniGetUI/Controls/OperationWidgets/OperationControl.xaml.cs index 2518b7e28..c0ac89232 100644 --- a/src/UniGetUI/Controls/OperationWidgets/OperationControl.xaml.cs +++ b/src/UniGetUI/Controls/OperationWidgets/OperationControl.xaml.cs @@ -1,4 +1,5 @@ using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.Diagnostics; using ExternalLibraries.Clipboard; using Microsoft.UI; @@ -130,10 +131,6 @@ protected string[] RawProcessOutput } } - private readonly ContentDialog OutputDialog = new(); - private readonly ScrollViewer LiveOutputScrollBar = new(); - private readonly RichTextBlock LiveOutputTextBlock = new(); - public OperationStatus Status { get => __status; @@ -188,7 +185,20 @@ public AbstractOperation(bool IgnoreParallelInstalls = false) InitializeComponent(); - OutputDialog = new ContentDialog + + + Status = OperationStatus.Pending; + + ActionButton.Click += ActionButtonClicked; + OutputViewewBlock.Click += async (_, _) => + { + await OpenLiveViewDialog(); + }; + } + + public async Task OpenLiveViewDialog() + { + var OutputDialog = new ContentDialog { Style = (Style)Application.Current.Resources["DefaultContentDialogStyle"], XamlRoot = XamlRoot @@ -196,13 +206,14 @@ public AbstractOperation(bool IgnoreParallelInstalls = false) OutputDialog.Resources["ContentDialogMaxWidth"] = 1200; OutputDialog.Resources["ContentDialogMaxHeight"] = 1000; - LiveOutputTextBlock = new RichTextBlock + var LiveOutputTextBlock = new RichTextBlock { Margin = new Thickness(8), FontFamily = new FontFamily("Consolas") }; - LiveOutputScrollBar = new ScrollViewer + + var LiveOutputScrollBar = new ScrollViewer { CornerRadius = new CornerRadius(6), Background = (Brush)Application.Current.Resources["ApplicationPageBackgroundThemeBrush"], @@ -211,23 +222,7 @@ public AbstractOperation(bool IgnoreParallelInstalls = false) Content = LiveOutputTextBlock }; - OutputDialog.Title = CoreTools.Translate("Live output"); - OutputDialog.CloseButtonText = CoreTools.Translate("Close"); - - OutputDialog.SizeChanged += (_, _) => - { - if (!IsDialogOpen) - { - return; - } - - LiveOutputScrollBar.MinWidth = MainApp.Instance.MainWindow.NavigationPage.ActualWidth - 400; - LiveOutputScrollBar.MinHeight = MainApp.Instance.MainWindow.NavigationPage.ActualHeight - 200; - }; - - OutputDialog.Content = LiveOutputScrollBar; - - ProcessOutput.CollectionChanged += async (_, _) => + NotifyCollectionChangedEventHandler HandleProcessOutputChange = async (_, _) => { if (!IsDialogOpen) { @@ -242,27 +237,33 @@ public AbstractOperation(bool IgnoreParallelInstalls = false) p.Inlines.Add(new Run { Text = line.Contents + "\x0a" }); else if (line.Type is OutputLine.LineType.Header) // TODO: Theme-aware colorss - p.Inlines.Add(new Run { Text = line.Contents + "\x0a", Foreground = new SolidColorBrush(Colors.Azure)}); + p.Inlines.Add(new Run { Text = line.Contents + "\x0a", Foreground = new SolidColorBrush(Colors.Azure) }); else - p.Inlines.Add(new Run { Text = line.Contents + "\x0a", Foreground = new SolidColorBrush(Colors.Red)}); + p.Inlines.Add(new Run { Text = line.Contents + "\x0a", Foreground = new SolidColorBrush(Colors.Red) }); } LiveOutputTextBlock.Blocks.Add(p); await Task.Delay(100); LiveOutputScrollBar.ScrollToVerticalOffset(LiveOutputScrollBar.ScrollableHeight); }; - Status = OperationStatus.Pending; + ProcessOutput.CollectionChanged += HandleProcessOutputChange; - ActionButton.Click += ActionButtonClicked; - OutputViewewBlock.Click += (_, _) => + OutputDialog.Title = CoreTools.Translate("Live output"); + OutputDialog.CloseButtonText = CoreTools.Translate("Close"); + + OutputDialog.SizeChanged += (_, _) => { - OpenLiveViewDialog(); + if (!IsDialogOpen) + { + return; + } + + LiveOutputScrollBar.MinWidth = MainApp.Instance.MainWindow.NavigationPage.ActualWidth - 400; + LiveOutputScrollBar.MinHeight = MainApp.Instance.MainWindow.NavigationPage.ActualHeight - 200; }; - } - public async void OpenLiveViewDialog() - { - OutputDialog.XamlRoot = XamlRoot; + OutputDialog.Content = LiveOutputScrollBar; + LiveOutputTextBlock.Blocks.Clear(); Paragraph p = new() { @@ -287,6 +288,7 @@ public async void OpenLiveViewDialog() WindowsClipboard.SetText(string.Join('\n', ProcessOutput.ToArray())); } IsDialogOpen = false; + ProcessOutput.CollectionChanged -= HandleProcessOutputChange; } public void ActionButtonClicked(object sender, RoutedEventArgs args) diff --git a/src/WindowsPackageManager.Interop/ExternalLibraries.WindowsPackageManager.Interop.csproj b/src/WindowsPackageManager.Interop/ExternalLibraries.WindowsPackageManager.Interop.csproj index 3b8bedbce..52c738b4d 100644 --- a/src/WindowsPackageManager.Interop/ExternalLibraries.WindowsPackageManager.Interop.csproj +++ b/src/WindowsPackageManager.Interop/ExternalLibraries.WindowsPackageManager.Interop.csproj @@ -30,6 +30,7 @@ + all