Files
ThreadPilot/Views/SettingsWindow.xaml.cs
T

74 lines
2.6 KiB
C#

/*
* ThreadPilot - Advanced Windows Process and Power Plan Manager
* Copyright (C) 2025 Prime Build
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace ThreadPilot.Views
{
using System;
using System.ComponentModel;
using System.Windows;
using ThreadPilot.ViewModels;
/// <summary>
/// Interaction logic for SettingsWindow.xaml.
/// </summary>
public partial class SettingsWindow : Window
{
private readonly SettingsViewModel viewModel;
public SettingsWindow(SettingsViewModel viewModel)
{
this.InitializeComponent();
this.viewModel = viewModel ?? throw new ArgumentNullException(nameof(viewModel));
this.SettingsViewControl.DataContext = this.viewModel;
}
protected override void OnClosing(CancelEventArgs e)
{
// Check for unsaved changes
if (!this.viewModel.CanClose())
{
var result = System.Windows.MessageBox.Show(
"You have unsaved changes. Do you want to save them before closing?",
"Unsaved Changes",
System.Windows.MessageBoxButton.YesNoCancel,
System.Windows.MessageBoxImage.Question);
switch (result)
{
case System.Windows.MessageBoxResult.Yes:
// Save and close
if (this.viewModel.SaveSettingsCommand.CanExecute(null))
{
this.viewModel.SaveSettingsCommand.Execute(null);
}
break;
case System.Windows.MessageBoxResult.No:
// Close without saving
break;
case System.Windows.MessageBoxResult.Cancel:
// Cancel closing
e.Cancel = true;
return;
}
}
base.OnClosing(e);
}
}
}