bloxstrap/Bloxstrap/UI/ViewModels/Settings/MainWindowViewModel.cs
2024-08-26 19:26:05 +01:00

42 lines
1.2 KiB
C#

using System.Windows.Input;
using Bloxstrap.UI.Elements.About;
using CommunityToolkit.Mvvm.Input;
namespace Bloxstrap.UI.ViewModels.Settings
{
public class MainWindowViewModel : NotifyPropertyChangedViewModel
{
public ICommand OpenAboutCommand => new RelayCommand(OpenAbout);
public ICommand SaveSettingsCommand => new RelayCommand(SaveSettings);
public EventHandler? RequestSaveNoticeEvent;
private void OpenAbout() => new MainWindow().ShowDialog();
private void SaveSettings()
{
const string LOG_IDENT = "MainWindowViewModel::SaveSettings";
App.Settings.Save();
App.State.Save();
App.FastFlags.Save();
foreach (var pair in App.PendingSettingTasks)
{
var task = pair.Value;
if (task.Changed)
{
App.Logger.WriteLine(LOG_IDENT, $"Executing pending task '{task}'");
task.Execute();
}
}
App.PendingSettingTasks.Clear();
RequestSaveNoticeEvent?.Invoke(this, new EventArgs());
}
}
}