1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-22 22:00:11 +00:00
msfs-popout-panel-manager/WpfApp/ViewModel/PanelConfigurationViewModel.cs

70 lines
2.7 KiB
C#
Raw Normal View History

2022-06-30 23:53:08 +00:00
using CommunityToolkit.Mvvm.ComponentModel;
using MSFSPopoutPanelManager.Model;
2022-01-27 13:40:04 +00:00
using MSFSPopoutPanelManager.Provider;
using System;
namespace MSFSPopoutPanelManager.WpfApp.ViewModel
{
2022-06-30 23:53:08 +00:00
public class PanelConfigurationViewModel : ObservableObject
2022-01-27 13:40:04 +00:00
{
private UserProfileManager _userProfileManager;
private PanelConfigurationManager _panelConfigurationManager;
public DataStore DataStore { get; set; }
public PanelConfigItem SelectedPanelConfigItem { get; set; }
public DelegateCommand LockPanelsCommand => new DelegateCommand(OnLockPanelsChanged, CanExecute);
public DelegateCommand PanelConfigUpdatedCommand => new DelegateCommand(OnPanelConfigUpdated, CanExecute);
public DelegateCommand MinusTenPixelCommand => new DelegateCommand(OnDataItemIncDec, CanExecute);
public DelegateCommand MinusOnePixelCommand => new DelegateCommand(OnDataItemIncDec, CanExecute);
public DelegateCommand PlusOnePixelCommand => new DelegateCommand(OnDataItemIncDec, CanExecute);
public DelegateCommand PlusTenPixelCommand => new DelegateCommand(OnDataItemIncDec, CanExecute);
public PanelConfigurationViewModel(DataStore dataStore, UserProfileManager userProfileManager)
{
DataStore = dataStore;
_userProfileManager = userProfileManager;
_panelConfigurationManager = new PanelConfigurationManager(_userProfileManager);
}
public void Initialize()
{
_userProfileManager.UserProfiles = DataStore.UserProfiles;
_panelConfigurationManager.UserProfile = DataStore.ActiveUserProfile;
_panelConfigurationManager.AllowEdit = DataStore.AllowEdit;
_panelConfigurationManager.HookWinEvent();
2022-06-30 23:53:08 +00:00
DataStore.OnAllowEditChanged += (sender, e) =>
2022-01-27 13:40:04 +00:00
{
2022-06-30 23:53:08 +00:00
_panelConfigurationManager.AllowEdit = DataStore.AllowEdit;
2022-01-27 13:40:04 +00:00
};
}
public void UnhookWinEvents()
{
_panelConfigurationManager.UnhookWinEvent();
}
private void OnLockPanelsChanged(object commandParamenter)
{
_panelConfigurationManager.LockPanelsUpdated();
}
private void OnPanelConfigUpdated(object panelConfigItem)
{
2022-06-30 23:53:08 +00:00
if (DataStore.AllowEdit)
2022-01-27 13:40:04 +00:00
_panelConfigurationManager.PanelConfigPropertyUpdated(panelConfigItem as PanelConfigItem);
}
private void OnDataItemIncDec(object commandParameter)
{
if (DataStore.AllowEdit)
_panelConfigurationManager.PanelConfigIncreaseDecrease(SelectedPanelConfigItem, Convert.ToInt32(commandParameter));
}
private bool CanExecute(object commandParameter)
{
return true;
}
2022-06-30 23:53:08 +00:00
}
}