work on inventory
This commit is contained in:
parent
50d32abd49
commit
32781b1462
11 changed files with 240 additions and 146 deletions
|
|
@ -1,6 +1,8 @@
|
|||
using System.Collections.Specialized;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Documents;
|
||||
using Avalonia.Media;
|
||||
using Poe2Trade.Core;
|
||||
using Poe2Trade.Ui.ViewModels;
|
||||
|
||||
|
|
@ -10,6 +12,13 @@ public partial class MainWindow : Window
|
|||
{
|
||||
private ConfigStore? _store;
|
||||
|
||||
private static readonly IBrush TimeBrush = new SolidColorBrush(Color.Parse("#484f58"));
|
||||
private static readonly IBrush InfoBrush = new SolidColorBrush(Color.Parse("#58a6ff"));
|
||||
private static readonly IBrush WarnBrush = new SolidColorBrush(Color.Parse("#d29922"));
|
||||
private static readonly IBrush ErrorBrush = new SolidColorBrush(Color.Parse("#f85149"));
|
||||
private static readonly IBrush DebugBrush = new SolidColorBrush(Color.Parse("#8b949e"));
|
||||
private static readonly IBrush DefaultBrush = new SolidColorBrush(Color.Parse("#e6edf3"));
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
|
@ -42,16 +51,58 @@ public partial class MainWindow : Window
|
|||
{
|
||||
vm.Logs.CollectionChanged += (_, args) =>
|
||||
{
|
||||
if (args.Action == NotifyCollectionChangedAction.Add)
|
||||
var block = this.FindControl<SelectableTextBlock>("LogBlock");
|
||||
var scroll = this.FindControl<ScrollViewer>("LogScroll");
|
||||
if (block == null) return;
|
||||
|
||||
if (args.Action == NotifyCollectionChangedAction.Add && args.NewItems != null)
|
||||
{
|
||||
var logList = this.FindControl<ListBox>("LogList");
|
||||
if (logList != null && vm.Logs.Count > 0)
|
||||
logList.ScrollIntoView(vm.Logs[^1]);
|
||||
foreach (LogEntry entry in args.NewItems)
|
||||
AppendLogEntry(block, entry);
|
||||
}
|
||||
else if (args.Action == NotifyCollectionChangedAction.Remove)
|
||||
{
|
||||
// Rebuild when old entries trimmed
|
||||
RebuildLog(block, vm);
|
||||
}
|
||||
|
||||
scroll?.ScrollToEnd();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static void AppendLogEntry(SelectableTextBlock block, LogEntry entry)
|
||||
{
|
||||
if (block.Inlines?.Count > 0)
|
||||
block.Inlines.Add(new Run("\n"));
|
||||
|
||||
block.Inlines ??= [];
|
||||
block.Inlines.Add(new Run(entry.Time + " ") { Foreground = TimeBrush });
|
||||
block.Inlines.Add(new Run(entry.Message) { Foreground = LevelBrush(entry.Level) });
|
||||
}
|
||||
|
||||
private static void RebuildLog(SelectableTextBlock block, MainWindowViewModel vm)
|
||||
{
|
||||
block.Inlines?.Clear();
|
||||
block.Inlines ??= [];
|
||||
for (var i = 0; i < vm.Logs.Count; i++)
|
||||
{
|
||||
if (i > 0) block.Inlines.Add(new Run("\n"));
|
||||
var entry = vm.Logs[i];
|
||||
block.Inlines.Add(new Run(entry.Time + " ") { Foreground = TimeBrush });
|
||||
block.Inlines.Add(new Run(entry.Message) { Foreground = LevelBrush(entry.Level) });
|
||||
}
|
||||
}
|
||||
|
||||
private static IBrush LevelBrush(string level) => level switch
|
||||
{
|
||||
"INFO" => InfoBrush,
|
||||
"WARN" or "WARNING" => WarnBrush,
|
||||
"ERROR" => ErrorBrush,
|
||||
"DEBUG" => DebugBrush,
|
||||
_ => DefaultBrush,
|
||||
};
|
||||
|
||||
protected override void OnClosing(WindowClosingEventArgs e)
|
||||
{
|
||||
if (_store != null)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue