Пример #1
0
        /// <summary>
        /// Creates a new sub-directory with a default name in this directory.
        /// </summary>
        /// <param name="editing">Indicates whether the new sub-directory should be put in edit mode immediately when constructed.</param>
        /// <returns>A new instance of <see cref="DirectoryViewModel"/> representing the new sub-directory.</returns>
        public DirectoryViewModel CreateSubDirectory(bool editing)
        {
            var newDirectory = new DirectoryViewModel(NamingHelper.ComputeNewName(NewFolderDefaultName, SubDirectories.Cast <DirectoryBaseViewModel>(), x => x.Name), this, true)
            {
                IsEditing = editing
            };

            return(newDirectory);
        }
Пример #2
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);
            }
        }
Пример #3
0
        private static int CompareDirectories(DirectoryViewModel x, DirectoryViewModel y)
        {
            if (x == null && y == null)
            {
                return(0);
            }

            if (x != null && y != null)
            {
                return(string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase));
            }

            return(x == null ? -1 : 1);
        }