Пример #1
0
        // TODO: Move this in an utility class
        internal static List <AssetViewModel> GetReferencers(IAssetDependencyManager dependencyManager, SessionViewModel session, IEnumerable <AssetItem> assets)
        {
            var result = new List <AssetViewModel>();

            // Find which assets are referencing the pasted assets in order to fix the reference link.
            foreach (var asset in assets)
            {
                var referencers = dependencyManager.ComputeDependencies(asset.Id, AssetDependencySearchOptions.In, ContentLinkType.Reference);
                if (referencers != null)
                {
                    foreach (var referencerLink in referencers.LinksIn)
                    {
                        AssetViewModel assetViewModel = session.GetAssetById(referencerLink.Item.Id);
                        if (assetViewModel != null)
                        {
                            if (!result.Contains(assetViewModel))
                            {
                                result.Add(assetViewModel);
                            }
                        }
                    }
                }
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Indicates whether the given asset in within the scope of this package, either by being part of this package or part of
        /// one of its dependencies.
        /// </summary>
        /// <param name="asset">The asset for which to check if it's in the scope of this package</param>
        /// <returns><c>True</c> if the asset is in scope, <c>False</c> otherwise.</returns>
        public bool IsInScope(AssetViewModel asset)
        {
            var assetPackage = asset.Directory.Package;

            // Note: Would be better to switch to Dependencies view model as soon as we have FlattenedDependencies in those
            return(assetPackage == this || Package.Container.FlattenedDependencies.Any(x => x.Package == assetPackage.Package));
        }
Пример #3
0
        internal static Task NotifyAssetChanged(SessionViewModel session, AssetViewModel asset)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }
            lock (DirtyDependencies)
            {
                if (asset != null)
                {
                    DirtyDependencies.Add(asset);
                }

                // If a task of updating dependencies is already running, then we should return it - this asset will be included into it.
                var task = dependenciesUpdated;
                if (task != null)
                {
                    return(task.Task);
                }

                dependenciesUpdated = new TaskCompletionSource <int>();
            }

            // Trigger the update for the next dispatcher frame
            return(session.Dispatcher.InvokeAsync(() => UpdateReferences(session)));
        }
Пример #4
0
 public AssetSourcesViewModel(AssetViewModel asset) : base(asset.SafeArgument(nameof(asset)).ServiceProvider)
 {
     this.asset = asset;
     UpdateFromSourceCommand = new AnonymousTaskCommand(ServiceProvider, UpdateAssetFromSource);
     updatedHashes           = SourceHashesHelper.GetAllHashes(asset.Asset);
     currentSourceFiles.AddRange(updatedHashes.Keys);
 }
Пример #5
0
 public AssetDependenciesViewModel(AssetViewModel asset, bool forcedRoot)
     : base(asset.SafeArgument(nameof(asset)).ServiceProvider)
 {
     Asset = asset;
     ToggleIsRootOnSelectedAssetCommand = new AnonymousCommand(ServiceProvider, () => IsRoot = !IsRoot);
     ForcedRoot = forcedRoot;
     DirtyDependencies.Add(asset);
 }
Пример #6
0
        public override bool CanAddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers, out string message)
        {
            AssetViewModel asset       = null;
            var            singleChild = true;

            foreach (var child in children)
            {
                if (!singleChild)
                {
                    message = "Multiple assets selected";
                    return(false);
                }
                asset = child as AssetViewModel;
                if (asset == null)
                {
                    message = "The selection is not an asset";
                    return(false);
                }
                if (AssetRegistry.IsContentType(TargetNode.Type) || typeof(AssetReference).IsAssignableFrom(TargetNode.Type))
                {
                    var isCompatible       = false;
                    var resolvedAssetTypes = AssetRegistry.GetAssetTypes(TargetNode.Type);
                    foreach (var resolvedAssetType in resolvedAssetTypes)
                    {
                        if (resolvedAssetType.IsAssignableFrom(asset.AssetType))
                        {
                            isCompatible = true;
                            break;
                        }
                    }
                    if (!isCompatible)
                    {
                        message = "Incompatible asset";
                        return(false);
                    }
                }
                var command = TargetNode.GetCommand("SetContentReference");
                var param   = new SetContentReferenceCommand.Parameter {
                    Asset = asset, Type = TargetNode.Type
                };
                if (!command.CanExecute(param))
                {
                    message = "The selection is not valid in this context";
                    return(false);
                }

                singleChild = false;
            }
            if (asset == null)
            {
                message = "The selection is not an asset";
                return(false);
            }
            message = $"Reference {asset.Url}";
            return(true);
        }
Пример #7
0
        void IAddChildViewModel.AddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers)
        {
            int directoriesMoved = 0;
            int assetsMoved      = 0;
            DirectoryViewModel singleDirectoryMoved = null;
            AssetViewModel     singleAssetMoved     = null;

            using (var transaction = UndoRedoService.CreateTransaction())
            {
                foreach (var child in children)
                {
                    var directory = child as DirectoryViewModel;
                    var asset     = child as AssetViewModel;
                    if (directory != null)
                    {
                        ++directoriesMoved;
                        singleDirectoryMoved = directoriesMoved == 1 ? directory : null;
                        var hierarchy = new List <DirectoryBaseViewModel>();
                        directory.GetDirectoryHierarchy(hierarchy);
                        assetsMoved     += hierarchy.Select(x => x.Assets.Count).Sum();
                        singleAssetMoved = assetsMoved == 1 ? hierarchy.SelectMany(x => x.Assets).FirstOrDefault() : null;
                        directory.Parent = this;
                    }
                    if (asset != null)
                    {
                        ++assetsMoved;
                        singleAssetMoved = assetsMoved == 1 ? asset : null;
                        Package.MoveAsset(asset, this);
                    }
                }
                string message = "";
                if (singleDirectoryMoved != null)
                {
                    message = $"Move directory '{singleDirectoryMoved.Name}'";
                }
                else if (directoriesMoved > 1)
                {
                    message = $"Move {directoriesMoved} directories";
                }

                if (assetsMoved > 0)
                {
                    message += message.Length > 0 ? " and " : "Move ";
                    if (singleAssetMoved != null)
                    {
                        message += $"asset '{singleAssetMoved.Url}'";
                    }
                    else
                    {
                        message += $"{assetsMoved} assets";
                    }
                }
                UndoRedoService.SetName(transaction, message);
            }
        }
Пример #8
0
        internal void UpdateAssetStatus(AssetViewModel asset)
        {
            if (asset.Sources.NeedUpdateFromSource && !asset.IsDeleted)
            {
                assetsToUpdate.Add(asset);
            }
            else
            {
                assetsToUpdate.Remove(asset);
            }

            UpdateAllAssetsWithModifiedSourceCommand.IsEnabled = assetsToUpdate.Count > 0;
        }
Пример #9
0
 public void AddAsset(AssetViewModel asset, bool canUndoRedo)
 {
     if (canUndoRedo)
     {
         assets.Add(asset);
     }
     else
     {
         using (SuspendNotificationForCollectionChange(nameof(Assets)))
         {
             assets.Add(asset);
         }
     }
 }
Пример #10
0
        /// <summary>
        /// Rebuilds the references collections from the current selection in the asset view model collection passed to the constructor of this instance.
        /// </summary>
        private void RefreshReferences()
        {
            Dispatcher.EnsureAccess();

            var referencers = assetCollection.SelectedAssets.SelectMany(x => x.Dependencies.ReferencerAssets);

            referencerAssets.Clear();
            referencerAssets.AddRange(referencers);

            var referenced = AssetViewModel.ComputeRecursiveReferencedAssets(assetCollection.SelectedAssets);

            referencedAssets.Clear();
            referencedAssets.AddRange(referenced);

            UpdateDisplayedContent();
        }
Пример #11
0
 public void MoveAsset(AssetViewModel asset, DirectoryBaseViewModel directory)
 {
     asset.MoveAsset(Package, directory);
 }
Пример #12
0
 public void RemoveAsset(AssetViewModel asset)
 {
     assets.Remove(asset);
 }
Пример #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssetEditorViewModel"/> class.
 /// </summary>
 /// <param name="asset">The asset related to this editor.</param>
 protected AssetEditorViewModel([NotNull] AssetViewModel asset)
     : base(asset.SafeArgument(nameof(asset)).ServiceProvider)
 {
     Asset = asset;
 }
Пример #14
0
        private void AssetPropertiesChanged(object sender, AssetChangedEventArgs e)
        {
            var referencers = AssetViewModel.ComputeRecursiveReferencerAssets(e.Assets).ToList();

            RefreshThumbnails(e.Assets.Concat(referencers), true);
        }