fixed source stack panel, added autoscroll to the log when adding an entry

This commit is contained in:
kitbyte
2025-03-21 23:53:24 +02:00
parent 4049ade4b1
commit 68cbbee275
4 changed files with 45 additions and 13 deletions
+24 -1
View File
@@ -1,9 +1,32 @@
namespace WeModPatcher
using System;
using System.Threading.Tasks;
using System.Windows;
using MessageBox = System.Windows.Forms.MessageBox;
namespace WeModPatcher
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
protected override void OnStartup(StartupEventArgs e)
{
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
base.OnStartup(e);
}
private void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
MessageBox.Show(e.ToString());
Shutdown();
}
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show(e.ToString());
Shutdown();
}
}
}
+12 -8
View File
@@ -75,15 +75,17 @@
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<TextBox Style="{StaticResource TitledTextBox}"
Uid="Folder path" Margin="10" IsReadOnly="True"
Cursor="Hand"
Text="{Binding WeModPath}"
VerticalAlignment="Center" Tag="Folder not found">
<TextBox.InputBindings>
<Grid Margin="10" Cursor="Hand" Background="Transparent">
<Grid.InputBindings>
<MouseBinding Gesture="LeftClick" Command="{Binding SetFolderPathCommand}" />
</TextBox.InputBindings>
</TextBox>
</Grid.InputBindings>
<TextBox Style="{StaticResource TitledTextBox}"
Uid="Folder path" IsReadOnly="True"
Text="{Binding WeModPath}"
VerticalAlignment="Center" Tag="Folder not found">
</TextBox>
</Grid>
<Border Grid.Row="1" BorderBrush="{DynamicResource Border}" BorderThickness="1"
Margin="10 0 10 10"
@@ -91,6 +93,7 @@
<ListBox ItemsSource="{Binding LogList}" SelectionMode="Single"
BorderBrush="Transparent" BorderThickness="0"
Background="Transparent"
x:Name="LogList"
Padding="6"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
@@ -159,6 +162,7 @@
<DockPanel Grid.Row="2" Margin="10 0 10 10">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center"
Cursor="Hand"
HorizontalAlignment="Left"
MouseDown="OpenSourceClicked"
Background="Transparent">
<Viewbox VerticalAlignment="Center" Width="32" Height="32">
@@ -15,7 +15,7 @@ namespace WeModPatcher.View.MainWindow
public MainWindow()
{
InitializeComponent();
this.DataContext = new MainWindowVm();
this.DataContext = new MainWindowVm(this);
Instance = this;
}
+8 -3
View File
@@ -17,6 +17,7 @@ namespace WeModPatcher.View.MainWindow
public class MainWindowVm : ObservableObject
{
private readonly MainWindow _view;
public ObservableCollection<LogEntry> LogList { get; } = new ObservableCollection<LogEntry>();
private string _weModPath;
@@ -153,6 +154,7 @@ namespace WeModPatcher.View.MainWindow
}
File.Copy(backupPath, Path.Combine(WeModPath, "resources", "app.asar"), true);
File.Delete(backupPath);
Log("Backup restored successfully.", ELogType.Success);
AlreadyPatched = false;
IsPatchEnabled = true;
@@ -181,16 +183,19 @@ namespace WeModPatcher.View.MainWindow
{
message = $"[{logType.ToString().ToUpper()}] {message}";
LogList.Add(new LogEntry
var entry = new LogEntry
{
LogType = logType,
Message = message
});
};
LogList.Add(entry);
_view.LogList.ScrollIntoView(entry);
});
}
public MainWindowVm()
public MainWindowVm(MainWindow view)
{
_view = view;
SetFolderPathCommand = new RelayCommand(OnFolderPathSelection);
ApplyPatchCommand = new RelayCommand(OnPatching);
RestoreBackupCommand = new RelayCommand(OnBackupRestoring);