Files
MesenCE/UI/Windows/LogWindow.axaml.cs
SourMesen e391fd8f9a Code: Add auto-formatting rules for C++ (clang-format) and enforce in CI via "clang-format" and "dotnet format" (#78)
* Code: Add auto-formatting rules for C++ projects (clang-format) and enforce code style via "clang-format" and "dotnet format"

* fix ui format warnings
2026-04-30 06:03:55 -07:00

84 lines
1.8 KiB
C#

using Avalonia;
using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using Mesen.Debugger.Controls;
using Mesen.Interop;
using System;
using System.ComponentModel;
namespace Mesen.Windows
{
public class LogWindow : MesenWindow
{
private DispatcherTimer _timer;
public static readonly StyledProperty<string> LogContentProperty = AvaloniaProperty.Register<LogWindow, string>(nameof(LogContent), "", defaultBindingMode: BindingMode.OneWayToSource);
public string LogContent
{
get { return GetValue(LogContentProperty); }
set { SetValue(LogContentProperty, value); }
}
public LogWindow()
{
InitializeComponent();
_timer = new DispatcherTimer(TimeSpan.FromMilliseconds(100), DispatcherPriority.Normal, (s, e) => UpdateLog());
AddHandler(InputElement.KeyDownEvent, OnPreviewKeyDown, RoutingStrategies.Tunnel, true);
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
private void UpdateLog()
{
string newLog = EmuApi.GetLog();
if(newLog != LogContent) {
LogContent = newLog;
Dispatcher.UIThread.Post(() => {
this.GetControl<MesenTextEditor>("txtLog").ScrollToEnd();
});
}
}
private void OnPreviewKeyDown(object? sender, KeyEventArgs e)
{
if(e.Key == Key.Escape) {
Close();
e.Handled = true;
}
}
protected override void OnOpened(EventArgs e)
{
base.OnOpened(e);
if(Design.IsDesignMode) {
return;
}
_timer.Start();
}
private void Ok_OnClick(object sender, RoutedEventArgs e)
{
Close();
}
protected override void OnClosing(WindowClosingEventArgs e)
{
base.OnClosing(e);
if(Design.IsDesignMode) {
return;
}
_timer.Stop();
}
}
}