Files
HardwareMonitorStatusWindow/StatusWindow/SettingsWindow/HardwareSettingsPanel.xaml.cs
Chris Kaczor 853e8eab0d
Some checks failed
Deploy to Gitea Releases / deploy-to-gitea-releases (push) Failing after 9s
Initial WIP commit
2026-01-27 18:58:09 -05:00

112 lines
3.0 KiB
C#

using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
namespace HardwareMonitorStatusWindow.StatusWindow.SettingsWindow;
public partial class HardwareSettingsPanel
{
private CollectionViewSource _collectionViewSource;
public HardwareSettingsPanel()
{
InitializeComponent();
}
public override string CategoryName => StatusWindow.Resources.optionCategorySensors;
public override void LoadPanel(Window parentWindow)
{
base.LoadPanel(parentWindow);
if (_collectionViewSource == null)
{
_collectionViewSource = new CollectionViewSource { Source = Data.SensorEntries };
SensorDataGrid.ItemsSource = _collectionViewSource.View;
}
_collectionViewSource.View.Refresh();
if (SensorDataGrid.Items.Count > 0)
SensorDataGrid.SelectedIndex = 0;
SetSensorButtonStates();
}
private void HandleSensorDataGridSelectionChanged(object sender, SelectionChangedEventArgs e)
{
SetSensorButtonStates();
}
private void SetSensorButtonStates()
{
AddSensorButton.IsEnabled = true;
EditSensorButton.IsEnabled = SensorDataGrid.SelectedItems.Count == 1;
DeleteSensorButton.IsEnabled = SensorDataGrid.SelectedItems.Count > 0;
}
private void HandleAddSensorButtonClick(object sender, RoutedEventArgs e)
{
AddSensor();
}
private void HandleEditSensorButtonClick(object sender, RoutedEventArgs e)
{
EditSelectedSensor();
}
private void HandleDeleteSensorButtonClick(object sender, RoutedEventArgs e)
{
DeleteSelectedSensors();
}
private void HandleSensorDataGridRowMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
EditSelectedSensor();
}
private void AddSensor()
{
var sensorEntry = new SensorEntry();
var sensorWindow = new SensorWindow();
var result = sensorWindow.Display(sensorEntry, Window.GetWindow(this));
if (!result.HasValue || !result.Value)
return;
SensorDataGrid.SelectedItem = sensorEntry;
SetSensorButtonStates();
}
private void EditSelectedSensor()
{
if (SensorDataGrid.SelectedItem == null)
return;
var sensorEntry = (SensorEntry)SensorDataGrid.SelectedItem;
var sensorWindow = new SensorWindow();
sensorWindow.Display(sensorEntry, Window.GetWindow(this));
}
private void DeleteSelectedSensors()
{
if (MessageBox.Show(ParentWindow!, StatusWindow.Resources.ConfirmDeleteSensors, StatusWindow.Resources.ConfirmDeleteTitle, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
return;
var selectedItems = new SensorEntry[SensorDataGrid.SelectedItems.Count];
SensorDataGrid.SelectedItems.CopyTo(selectedItems, 0);
foreach (var sensorEntry in selectedItems)
Data.SensorEntries.Remove(sensorEntry);
SetSensorButtonStates();
}
}