Mesen2/UI/Windows/CheatEditWindow.axaml.cs
Sour 716227c0a7 UI: Update to Avalonia11-preview6
Notes:
-Uses a copy of VirtualizingStackPanel (to include fixes done after preview6) + fix another issue in lists
-Fixes memory leaks when closing windows (by setting DataContext to null, etc.)
2023-04-10 22:59:48 -04:00

73 lines
1.4 KiB
C#

using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Mesen.Config;
using Mesen.Controls;
using Mesen.Utilities;
using Mesen.ViewModels;
using System;
using System.ComponentModel;
using System.Threading.Tasks;
namespace Mesen.Windows
{
public class CheatEditWindow : MesenWindow
{
private CheatEditWindowViewModel _model;
[Obsolete("For designer only")]
public CheatEditWindow() : this(new CheatCode()) { }
public CheatEditWindow(CheatCode cheat)
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
_model = new CheatEditWindowViewModel(cheat);
DataContext = _model;
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
protected override void OnOpened(EventArgs e)
{
base.OnOpened(e);
this.GetControl<TextBox>("txtCodes").Focus();
}
private void Ok_OnClick(object sender, RoutedEventArgs e)
{
Close(true);
}
private void Cancel_OnClick(object sender, RoutedEventArgs e)
{
Close(false);
}
protected override void OnClosing(WindowClosingEventArgs e)
{
base.OnClosing(e);
_model.Dispose();
}
public static async Task<bool> EditCheat(CheatCode cheat, Control parent)
{
CheatCode copy = cheat.Clone();
CheatEditWindow wnd = new CheatEditWindow(copy);
bool result = await wnd.ShowCenteredDialog<bool>(parent);
if(result) {
cheat.CopyFrom(copy);
}
return result;
}
}
}