private void FillRootAssetCollection() { RootAssets.Clear(); RootAssets.AddRange(Package.RootAssets.Select(x => Session.GetAssetById(x.Id))); foreach (var dependency in PackageContainer.FlattenedDependencies) { if (dependency.Package != null) { RootAssets.AddRange(dependency.Package.RootAssets.Select(x => Session.GetAssetById(x.Id))); } } RegisterMemberCollectionForActionStack(nameof(RootAssets), RootAssets); RootAssets.CollectionChanged += RootAssetsCollectionChanged; }
private void FillRootAssetCollection() { RootAssets.Clear(); RootAssets.AddRange(Package.RootAssets.Select(x => Session.GetAssetById(x.Id))); foreach (var dependency in Package.LocalDependencies) { RootAssets.AddRange(dependency.RootAssets.Select(x => Session.GetAssetById(x.Id))); } foreach (var dependency in Package.Meta.Dependencies) { RootAssets.AddRange(dependency.RootAssets.Select(x => Session.GetAssetById(x.Id))); } RegisterMemberCollectionForActionStack(nameof(RootAssets), RootAssets); RootAssets.CollectionChanged += RootAssetsCollectionChanged; }
private void RootAssetsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { // Replicate changes switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (var newItem in e.NewItems.Cast <AssetViewModel>()) { // Shouldn't happen, but make sure an item with same id is not already added Package.RootAssets.Remove(newItem.Id); Package.RootAssets.Add(new AssetReference(newItem.Id, newItem.Url)); Package.IsDirty = true; newItem.Dependencies.NotifyRootAssetChange(true); } break; case NotifyCollectionChangedAction.Remove: foreach (var oldItem in e.OldItems.Cast <AssetViewModel>()) { Package.RootAssets.Remove(oldItem.Id); Package.IsDirty = true; oldItem.Dependencies.NotifyRootAssetChange(true); } break; case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Move: case NotifyCollectionChangedAction.Reset: // Let's do a full resync Package.RootAssets.Clear(); Package.RootAssets.AddRange(RootAssets.Select(x => new AssetReference(x.Id, x.Url))); AllAssets.ForEach(x => { x.Dependencies.NotifyRootAssetChange(false); }); break; default: throw new ArgumentOutOfRangeException(); } Session.SelectionIsRoot = Session.ActiveAssetView.SelectedAssets.All(x => x.Dependencies.IsRoot); }