2023-07-12 22:41:31 +00:00
|
|
|
|
using MSFSPopoutPanelManager.DomainModel.Profile;
|
|
|
|
|
using MSFSPopoutPanelManager.Orchestration;
|
|
|
|
|
using Prism.Commands;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
|
|
namespace MSFSPopoutPanelManager.MainApp.ViewModel
|
|
|
|
|
{
|
|
|
|
|
public class PanelConfigFieldViewModel : BaseViewModel
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
private readonly PanelConfigurationOrchestrator _panelConfigurationOrchestrator;
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
public PanelConfig DataItem { get; set; }
|
|
|
|
|
|
|
|
|
|
public string BindingPath { get; set; }
|
|
|
|
|
|
|
|
|
|
public RoutedEvent SourceUpdatedEvent { get; set; }
|
|
|
|
|
|
|
|
|
|
public DelegateCommand<object> PlusMinusCommand { get; set; }
|
|
|
|
|
|
|
|
|
|
public ICommand DataUpdatedCommand { get; set; }
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
public PanelConfigFieldViewModel(SharedStorage sharedStorage, PanelConfigurationOrchestrator panelConfigurationOrchestrator) : base(sharedStorage)
|
2023-07-12 22:41:31 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
_panelConfigurationOrchestrator = panelConfigurationOrchestrator;
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
PlusMinusCommand = new DelegateCommand<object>(OnPlusMinus);
|
|
|
|
|
DataUpdatedCommand = new DelegateCommand(OnDataUpdated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPlusMinus(object param)
|
|
|
|
|
{
|
|
|
|
|
if (DataItem == null || BindingPath == null || param == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var bindingPathProperty = typeof(PanelConfig).GetProperty(BindingPath);
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (bindingPathProperty == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var value = Convert.ToInt32(bindingPathProperty.GetValue(DataItem, null));
|
|
|
|
|
bindingPathProperty.SetValue(DataItem, Convert.ToInt32(param) + value);
|
2023-07-12 22:41:31 +00:00
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
OnDataUpdated();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDataUpdated()
|
|
|
|
|
{
|
|
|
|
|
if (DataItem != null)
|
2024-02-28 02:44:21 +00:00
|
|
|
|
_panelConfigurationOrchestrator.PanelConfigPropertyUpdated(DataItem.PanelHandle, (PanelConfigPropertyName)Enum.Parse(typeof(PanelConfigPropertyName), BindingPath));
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|