Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug in a process output dialog #2793

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 36 additions & 34 deletions src/UniGetUI/Controls/OperationWidgets/OperationControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using ExternalLibraries.Clipboard;
using Microsoft.UI;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -188,21 +185,35 @@ 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
};
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"],
Expand All @@ -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)
{
Expand All @@ -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()
{
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Management.Infrastructure" Version="3.0.0" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.3" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading