using System; using System.Collections.ObjectModel; using System.IO; using JD.Adobe.Service.TargetMemories; using JD.Asset; using Orbit.Module.Actions; using Orbit.Module.Actions.PhotoshopActions; using Plume.Interfaces.WPF.Actions; using Plume.WPF.Mvvm; using ShuttleInstaller; using Action = Plume.Interfaces.WPF.Actions.Action; namespace Orbit.Module.ViewModel { public class ActionPanelsViewModel : BindableBase { private readonly IActionManager _actionManager; private readonly ITargetMemory _targetMemory; private readonly IShuttleInstaller _shuttleInstaller; private ObservableCollection _showInActions; private ObservableCollection _installShuttleActions; private ObservableCollection _offlinePhotoshopActions; private ObservableCollection _onlineBackgroundActions; private ObservableCollection _onlineMenuArtActions; public string SelectedTopFolder { get; set; } public IMapExplorer MapExplorer { get; } public ObservableCollection Actions { get; set; } = new ObservableCollection(); public ObservableCollection PhotoshopActions { get; set; } = new ObservableCollection(); public ActionPanelsViewModel(IActionManager actionManager, ITargetMemory targetMemory, IShuttleInstaller shuttleInstaller, IMapExplorer mapExplorer) { _actionManager = actionManager ?? throw new ArgumentNullException(nameof(actionManager)); _targetMemory = targetMemory ?? throw new ArgumentNullException(nameof(targetMemory)); _shuttleInstaller = shuttleInstaller ?? throw new ArgumentNullException(nameof(shuttleInstaller)); MapExplorer = mapExplorer; SelectedTopFolder = null; } public void Refresh() { RefreshShowInActions(); RefreshPhotoshopActions(); } private void RefreshShowInActions() { Actions = MapExplorer.SelectedMap != null ? GetShowInActions() : new ObservableCollection(); OnPropertyChanged(nameof(Actions)); } private void RefreshPhotoshopActions() { if (!_shuttleInstaller.IsProperlyInstalled) { PhotoshopActions = GetShuttleInstallActions(); } else if (MapExplorer.SelectedMap == null) { PhotoshopActions = new ObservableCollection(); } else if (!_targetMemory.HasTarget) { PhotoshopActions = GetOfflinePhotoshopActions(); } else { if (IsSameFolder(SelectedTopFolder, MapExplorer.SelectedMap.MenuArtFolder)) { PhotoshopActions = GetMenuArtActions(); } else if (IsSameFolder(SelectedTopFolder, MapExplorer.SelectedMap.BackgroundFolder)) { PhotoshopActions = GetBackgroundActions(); } else { PhotoshopActions = GetOfflinePhotoshopActions(); } } OnPropertyChanged(nameof(PhotoshopActions)); } private bool IsSameFolder(string folderName, PathInfo mapPathInfo) { string mapFolderName = mapPathInfo != null ? new DirectoryInfo(mapPathInfo).Name : null; return folderName != null && folderName.Equals(mapFolderName, StringComparison.InvariantCultureIgnoreCase); } private ObservableCollection GetShuttleInstallActions() { return _installShuttleActions ?? (_installShuttleActions = new ObservableCollection { _actionManager.Get() }); } private ObservableCollection GetShowInActions() { return _showInActions ?? (_showInActions = new ObservableCollection { _actionManager.Get(), _actionManager.Get(), _actionManager.Get() }); } private ObservableCollection GetOfflinePhotoshopActions() { return _offlinePhotoshopActions ?? (_offlinePhotoshopActions = new ObservableCollection { _actionManager.Get() }); } private ObservableCollection GetBackgroundActions() { return _onlineBackgroundActions ?? (_onlineBackgroundActions = new ObservableCollection { _actionManager.Get() }); } private ObservableCollection GetMenuArtActions() { return _onlineMenuArtActions ?? (_onlineMenuArtActions = new ObservableCollection { _actionManager.Get() }); } } }