1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-24 23:00:12 +00:00
msfs-popout-panel-manager/MainApp/ViewModel/ProfileCardListViewModel.cs

82 lines
2.6 KiB
C#
Raw Normal View History

2023-07-12 22:41:31 +00:00
using MaterialDesignThemes.Wpf;
using MSFSPopoutPanelManager.DomainModel.Profile;
using MSFSPopoutPanelManager.Orchestration;
using Prism.Commands;
using System;
using System.Windows.Input;
namespace MSFSPopoutPanelManager.MainApp.ViewModel
{
public class ProfileCardListViewModel : BaseViewModel
{
public ICommand AddProfileCommand { get; }
public ICommand NextProfileCommand { get; }
public ICommand PreviousProfileCommand { get; }
public ICommand SearchProfileSelectedCommand { get; set; }
public UserProfile SearchProfileSelectedItem { get; set; }
public int ProfileTransitionIndex { get; set; }
public bool IsProfileListEmpty { get { return ProfileData?.Profiles.Count == 0; } }
public bool IsProfileListNotEmpty { get { return ProfileData?.Profiles.Count > 0; } }
public event EventHandler OnProfileSelected;
public ProfileCardListViewModel(MainOrchestrator orchestrator) : base(orchestrator)
{
AddProfileCommand = new DelegateCommand(OnAddProfile);
NextProfileCommand = new DelegateCommand(OnNextProfile);
PreviousProfileCommand = new DelegateCommand(OnPreviousProfile);
SearchProfileSelectedCommand = new DelegateCommand(OnSearchProfileSelected);
ProfileTransitionIndex = 0;
}
private async void OnAddProfile()
{
var dialog = new AddProfileDialog();
var result = await DialogHost.Show(dialog, ROOT_DIALOG_HOST, null, dialog.ClosingEventHandler, null);
if (result.ToString() == "ADD")
UpdateProfileTransitionIndex();
}
private void OnNextProfile()
{
ProfileData.ResetActiveProfile();
Orchestrator.PanelSource.CloseAllPanelSource();
Orchestrator.Profile.MoveToNextProfile();
UpdateProfileTransitionIndex();
}
private void OnPreviousProfile()
{
ProfileData.ResetActiveProfile();
Orchestrator.PanelSource.CloseAllPanelSource();
Orchestrator.Profile.MoveToPreviousProfile();
UpdateProfileTransitionIndex();
}
private void OnSearchProfileSelected()
{
if (SearchProfileSelectedItem != null)
{
Orchestrator.Profile.ChangeProfile(SearchProfileSelectedItem);
UpdateProfileTransitionIndex();
OnProfileSelected?.Invoke(this, null);
}
}
private void UpdateProfileTransitionIndex()
{
ProfileTransitionIndex = ProfileTransitionIndex == 1 ? 0 : 1;
}
}
}