This commit is contained in:
lanyi 2021-10-14 14:22:06 +02:00
parent c3a41c0d4e
commit 5b907309e0
2 changed files with 40 additions and 27 deletions

View File

@ -1,6 +1,7 @@
using Microsoft.Win32;
using System;
using System.IO;
using System.Threading;
using System.Windows;
namespace AnotherReplayReader
@ -20,12 +21,15 @@ namespace AnotherReplayReader
}
}
public event Action<string> NewText;
public event Action<string>? NewText;
public Proxy DebugMessage
{
get => new Proxy();
set => NewText?.Invoke(value.Payload);
}
public event Action? RequestedSave;
public void RequestSave() => RequestedSave?.Invoke();
}
/// <summary>
/// Debug.xaml 的交互逻辑
@ -33,14 +37,31 @@ namespace AnotherReplayReader
public sealed partial class Debug : Window
{
public static readonly DebugMessageWrapper Instance = new DebugMessageWrapper();
private static Debug? _window = null;
public Debug()
public static void Initialize()
{
InitializeComponent();
Instance.NewText += t => Dispatcher.Invoke(() => _textBox.AppendText(t));
Interlocked.CompareExchange(ref _window, new(), null);
_window.InitializeComponent();
Instance.NewText += _window.AppendText;
Instance.RequestedSave += _window.ExportInMainWindow;
}
private void OnExport_Click(object sender, RoutedEventArgs e)
public static new void ShowDialog() => (_window as Window)?.ShowDialog();
private Debug() { }
private void OnExport_Click(object sender, RoutedEventArgs e) => Export(this);
private void OnClear_Click(object sender, RoutedEventArgs e) => _textBox.Clear();
private void AppendText(string s) => Dispatcher.Invoke(() => _textBox.AppendText(s));
private void ExportInMainWindow() => Export(Application.Current.MainWindow);
private void Export(Window owner)
{
Dispatcher.Invoke(() =>
{
var saveFileDialog = new SaveFileDialog
{
@ -48,7 +69,7 @@ namespace AnotherReplayReader
OverwritePrompt = true,
};
var result = saveFileDialog.ShowDialog(this);
var result = saveFileDialog.ShowDialog(owner);
if (result == true)
{
using (var file = saveFileDialog.OpenFile())
@ -57,11 +78,7 @@ namespace AnotherReplayReader
writer.Write(_textBox.Text);
}
}
}
private void OnClear_Click(object sender, RoutedEventArgs e)
{
_textBox.Clear();
});
}
}
}

View File

@ -492,11 +492,7 @@ namespace AnotherReplayReader
detailsWindow.ShowDialog();
}
private void OnDebugButton_Click(object sender, RoutedEventArgs e)
{
var debug = new Debug();
debug.ShowDialog();
}
private void OnDebugButton_Click(object sender, RoutedEventArgs e) => Debug.ShowDialog();
private void OnPlayReplayButton_Click(object sender, RoutedEventArgs e)
{