using System; using System.Collections.Generic; using System.Linq; using PsdParser.AdditionalLayerInformations; using YukkuriMovieMaker.Plugin.FileSource.Psd; namespace YukkuriMovieMaker.Plugin.Tachie.Psd; public class PsdFolderViewModel : PsdItemViewModel { public bool IsOpened { get; set; } public IReadOnlyCollection> Items { get; } public PsdFolderViewModel(PsdFolder psdFolder, PsdFileSettings settings, ShiftLayerCommand shiftLayerCommand, SwitchLayerCommand switchLayerCommand) : base(psdFolder, shiftLayerCommand, switchLayerCommand) { IsOpened = psdFolder.LayerRecordAndImage?.Record.AdditionalLayerInformations.OfType().Any((SectionDividerSetting x) => x.Type == SectionDividerSetting.LsctType.OpenedFolder) ?? true; ShiftLayerCommand childShiftLayerCommand = new ShiftLayerCommand(); SwitchLayerCommand childSwitchLayerCommand = new SwitchLayerCommand(); List> items = (List>)(Items = ((IEnumerable)psdFolder.Items).Select((Func>)delegate(PsdItem item) { if (!(item is PsdFolder psdFolder2)) { if (!(item is PsdLayer psdLayer)) { throw new Exception(); } return new PsdLayerViewModel(psdLayer, settings, childShiftLayerCommand, childSwitchLayerCommand); } return new PsdFolderViewModel(psdFolder2, settings, childShiftLayerCommand, childSwitchLayerCommand); }).ToList()); childShiftLayerCommand.Items = items; childSwitchLayerCommand.Items = items; } public override void UpdateEnable(IEnumerable enableLayers) { base.UpdateEnable(enableLayers); foreach (IPsdItemViewModel item in Items) { item.UpdateEnable(enableLayers); } } internal IEnumerable GetEnableItems() { foreach (IPsdItemViewModel item in Items) { if (item.IsEnabled) { yield return item.Id; } if (!(item is PsdFolderViewModel psdFolderViewModel)) { continue; } foreach (string enableItem in psdFolderViewModel.GetEnableItems()) { yield return enableItem; } } } internal IEnumerable<(string Id, string Path)> GetEnableItemsWithPath() { foreach (IPsdItemViewModel item in Items) { if (item.IsEnabled) { yield return (Id: item.Id, Path: item.Path); } if (!(item is PsdFolderViewModel psdFolderViewModel)) { continue; } foreach (var item2 in psdFolderViewModel.GetEnableItemsWithPath()) { yield return item2; } } } }