Debugger: Added debug log window

This commit is contained in:
Sour 2022-02-08 22:19:15 -05:00
parent 7f2a6ce0bc
commit f662ef1625
8 changed files with 144 additions and 15 deletions

View file

@ -2,9 +2,7 @@
namespace Mesen.Config
{
public class DebugLogConfig
public class DebugLogConfig : BaseWindowConfig<DebugLogConfig>
{
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
}
}

View file

@ -411,6 +411,9 @@ namespace Mesen.Debugger.Utilities
[IconFile("Chip")]
OpenAssembler,
[IconFile("LogWindow")]
OpenDebugLog,
[IconFile("Speed")]
OpenProfiler,

View file

@ -0,0 +1,33 @@
<Window
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:m="clr-namespace:Mesen"
xmlns:vm="using:Mesen.ViewModels"
xmlns:l="using:Mesen.Localization"
xmlns:v="using:Mesen.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="400"
x:Class="Mesen.Debugger.Windows.DebugLogWindow"
Width="400" Height="400"
Icon="/Assets/LogWindow.png"
Title="{l:Translate wndTitle}"
Name="root"
>
<DockPanel>
<StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right" Margin="2">
<Button Width="70" HorizontalContentAlignment="Center" IsCancel="True" Click="Ok_OnClick" Content="{l:Translate btnClose}" />
</StackPanel>
<TextBox
Name="txtLog"
Height="NaN"
IsReadOnly="True"
AcceptsReturn="True"
ScrollViewer.AllowAutoHide="False"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
Text="{CompiledBinding LogContent, ElementName=root}"
/>
</DockPanel>
</Window>

View file

@ -0,0 +1,75 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using System;
using System.ComponentModel;
using Avalonia.Data;
using Mesen.Interop;
using Mesen.Config;
namespace Mesen.Debugger.Windows
{
public class DebugLogWindow : Window
{
private DispatcherTimer _timer;
public static readonly StyledProperty<string> LogContentProperty = AvaloniaProperty.Register<DebugLogWindow, string>(nameof(LogContent), "", defaultBindingMode: BindingMode.OneWayToSource);
public string LogContent
{
get { return GetValue(LogContentProperty); }
set { SetValue(LogContentProperty, value); }
}
public DebugLogWindow()
{
InitializeComponent();
_timer = new DispatcherTimer(TimeSpan.FromMilliseconds(100), DispatcherPriority.Normal, (s, e) => UpdateLog());
ConfigManager.Config.Debug.DebugLog.LoadWindowSettings(this);
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
private void UpdateLog()
{
string newLog = DebugApi.GetLog();
if(newLog != LogContent) {
LogContent = newLog;
this.FindControl<TextBox>("txtLog").CaretIndex = Int32.MaxValue;
}
}
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(CancelEventArgs e)
{
base.OnClosing(e);
if(Design.IsDesignMode) {
return;
}
_timer.Stop();
ConfigManager.Config.Debug.DebugLog.SaveWindowSettings(this);
DataContext = null;
}
}
}

View file

@ -768,7 +768,17 @@
<Control ID="btnRun">Run</Control>
<Control ID="btnStop">Stop</Control>
</Form>
<Form ID="LogWindow">
<Control ID="wndTitle">Log Window</Control>
<Control ID="btnClose">Close</Control>
</Form>
<Form ID="DebugLogWindow">
<Control ID="wndTitle">Debug Log</Control>
<Control ID="btnClose">Close</Control>
</Form>
<Form ID="TraceLoggerWindow">
<Control ID="wndTitle">Trace Logger</Control>
<Control ID="lblFormat">Format: </Control>

View file

@ -267,6 +267,9 @@
<Compile Update="Debugger\Windows\BreakInWindow.axaml.cs">
<DependentUpon>BreakInWindow.axaml</DependentUpon>
</Compile>
<Compile Update="Debugger\Windows\DebugLogWindow.axaml.cs">
<DependentUpon>DebugLogWindow.axaml</DependentUpon>
</Compile>
<Compile Update="Debugger\Windows\RegisterViewerWindow.axaml.cs">
<DependentUpon>RegisterViewerWindow.axaml</DependentUpon>
</Compile>

View file

@ -802,6 +802,12 @@ namespace Mesen.ViewModels
IsEnabled = () => IsGameRunning,
OnClick = () => DebugWindowManager.OpenDebugWindow(() => new AssemblerWindow(new AssemblerWindowViewModel(MainWindow.RomInfo.ConsoleType.GetMainCpuType())))
},
new ContextMenuAction() {
ActionType = ActionType.OpenDebugLog,
Shortcut = () => ConfigManager.Config.Debug.Shortcuts.Get(DebuggerShortcut.OpenDebugLog),
IsEnabled = () => IsGameRunning,
OnClick = () => DebugWindowManager.OpenDebugWindow(() => new DebugLogWindow())
},
new ContextMenuAction() {
ActionType = ActionType.OpenProfiler,
Shortcut = () => ConfigManager.Config.Debug.Shortcuts.Get(DebuggerShortcut.OpenProfiler),

View file

@ -5,28 +5,29 @@
xmlns:m="clr-namespace:Mesen"
xmlns:vm="using:Mesen.ViewModels"
xmlns:v="using:Mesen.Views"
xmlns:l="using:Mesen.Localization"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="620" d:DesignHeight="500"
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="400"
x:Class="Mesen.Windows.LogWindow"
Width="620" Height="500"
Icon="/Assets/Icon.ico"
Title="Log Window"
Width="400" Height="400"
Icon="/Assets/LogWindow.png"
Title="{l:Translate wndTitle}"
Name="root"
>
<DockPanel DataContext="{Binding ElementName=root}">
<StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right" Margin="5 3">
<Button Width="70" HorizontalContentAlignment="Center" IsCancel="True" Click="Ok_OnClick">Close</Button>
<DockPanel>
<StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right" Margin="2">
<Button Width="70" HorizontalContentAlignment="Center" IsCancel="True" Click="Ok_OnClick" Content="{l:Translate btnClose}" />
</StackPanel>
<TextBox
Name="txtLog"
MaxHeight="10000"
Height="NaN"
IsReadOnly="True"
TextWrapping="Wrap"
AcceptsReturn="True"
VerticalContentAlignment="Top"
ScrollViewer.AllowAutoHide="False"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
Text="{Binding LogContent}"
Text="{CompiledBinding LogContent, ElementName=root}"
/>
</DockPanel>
</Window>