62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using System.Threading.Tasks;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using UnifiedFarmLauncher.Services;
|
|
using UnifiedFarmLauncher.ViewModels;
|
|
|
|
namespace UnifiedFarmLauncher.Views
|
|
{
|
|
public partial class GlobalSettingsWindow : Window
|
|
{
|
|
private readonly GlobalSettingsViewModel _viewModel;
|
|
private bool _result;
|
|
|
|
public GlobalSettingsWindow()
|
|
{
|
|
InitializeComponent();
|
|
var configService = new ConfigService();
|
|
_viewModel = new GlobalSettingsViewModel(configService);
|
|
DataContext = _viewModel;
|
|
SetupEventHandlers();
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(this);
|
|
}
|
|
|
|
private void SetupEventHandlers()
|
|
{
|
|
this.FindControl<Button>("OkButton")!.Click += OkButton_Click;
|
|
this.FindControl<Button>("CancelButton")!.Click += CancelButton_Click;
|
|
}
|
|
|
|
private void OkButton_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_viewModel.Save();
|
|
_result = true;
|
|
Close();
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
// Could show error message here
|
|
System.Diagnostics.Debug.WriteLine($"Failed to save global settings: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private void CancelButton_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
_result = false;
|
|
Close();
|
|
}
|
|
|
|
public async Task<bool> ShowDialogAsync(Window parent)
|
|
{
|
|
await base.ShowDialog(parent);
|
|
return _result;
|
|
}
|
|
}
|
|
}
|