Пример #1
0
        /// <summary>
        /// Deletes this folder. The folder must not contain any entity before being deleted.
        /// </summary>
        public void Delete()
        {
            if (InnerSubEntities.Any())
            {
                throw new InvalidOperationException("The folder being deleted is not empty.");
            }
            var path    = Path;
            var ownerId = Owner.Id;

            if (Parent == null)
            {
                throw new InvalidOperationException($"{nameof(Parent)} cannot be null");
            }
            Parent.Folders.Remove(this);
            if (!Editor.UndoRedoService.UndoRedoInProgress)
            {
                var operation = new EntityFolderOperation(Asset, EntityFolderOperation.Action.FolderDeleted, path, ownerId);
                Editor.UndoRedoService.PushOperation(operation);
            }
        }
Пример #2
0
        private void UpdateName([NotNull] string newName)
        {
            // note: even though folder paths are considered to be case-insensitive, we still want to propagate a case-only change and update the affected entities.
            if (string.Equals(name, newName, StringComparison.Ordinal))
            {
                return;
            }

            if (Editor.UndoRedoService.UndoRedoInProgress)
            {
                name = newName;
                return;
            }

            using (var transaction = Editor.UndoRedoService.CreateTransaction())
            {
                // We need to update the name first so that the Path properties is consistent
                var oldName = name;
                name = newName;

                foreach (var entity in InnerSubEntities)
                {
                    var node = Editor.NodeContainer.GetOrCreateNode(entity.EntityDesign);
                    // In this case, the parent is either the current folder or a subfolder in between
                    var parent = (EntityFolderViewModel)entity.Parent;
                    if (parent == null)
                    {
                        throw new InvalidOperationException($"{nameof(parent)} cannot be null");
                    }
                    node[nameof(EntityDesign.Folder)].Update(parent.Path);
                }

                if (Parent == null)
                {
                    throw new InvalidOperationException($"{nameof(Parent)} cannot be null");
                }
                var operation = new EntityFolderOperation(Asset, EntityFolderOperation.Action.FolderRenamed, Path, oldName, Parent.Owner.Id);
                Editor.UndoRedoService.PushOperation(operation);
                Editor.UndoRedoService.SetName(transaction, $"Rename folder '{oldName}' to '{newName}'");
            }
        }