示例#1
0
        protected async override void OnExecuteAsync(IExplorerViewModel vm)
        {
            var name = await _dialogService.Prompt("Enter name", "group name");

            if (name == null)
            {
                return;
            }

            var itemIndex = 1;
            var count     = vm.SelectedItems.Count;

            for (int i = 0; i < count; i++)
            {
                var item = vm.SelectedItems[0];
                try
                {
                    await item.StorageItem.RenameAsync($"{name} ({itemIndex}){item.FileType}");

                    vm.ExplorerItems.Remove(item);
                    vm.ExplorerItems.Add(await ExplorerItem.CreateAsync(item.StorageItem));
                }
                catch
                {
                    var currentName = $"{name} ({itemIndex})";

                    var result = await _dialogService.NameCollisionDialog(currentName);

                    if (result == Controls.ContentDialogs.NameCollisionDialogResult.Replace)
                    {
                        var existingItem = vm.ExplorerItems.First(it => it.Name == currentName + item.FileType);
                        await existingItem.StorageItem.DeleteAsync(Windows.Storage.StorageDeleteOption.Default);

                        vm.ExplorerItems.Remove(existingItem);

                        await item.StorageItem.RenameAsync(currentName + item.FileType);

                        vm.ExplorerItems.Add(await ExplorerItem.CreateAsync(item.StorageItem));
                    }
                    else if (result == Controls.ContentDialogs.NameCollisionDialogResult.Rename)
                    {
                        var items = await vm.CurrentFolder.GetItemsAsync();

                        currentName = NameCollision.GetUniqueNameForFile(currentName, item.FileType, items);

                        vm.ExplorerItems.Remove(item);
                        await item.StorageItem.RenameAsync(currentName);

                        vm.ExplorerItems.Add(await ExplorerItem.CreateAsync(item.StorageItem));
                    }
                }

                itemIndex++;
            }
        }
示例#2
0
        protected override async void OnExecuteAsync(IExplorerViewModel vm)
        {
            var folderName = await _dialogService.Prompt("Enter folder name", "New folder");

            if (folderName == null)
            {
                return;
            }

            try
            {
                var folder = await vm.CurrentFolder.CreateFolderAsync(folderName);

                var newItem = await ExplorerItem.CreateAsync(folder);

                vm.ExplorerItems.Add(newItem);
                vm.SelectedItem = newItem;
            }
            catch
            {
                var result = await _dialogService.NameCollisionDialog(folderName);

                if (result == Controls.ContentDialogs.NameCollisionDialogResult.Replace)
                {
                    var item = vm.ExplorerItems.First(i => i.Name == folderName);
                    await item.StorageItem.DeleteAsync(Windows.Storage.StorageDeleteOption.Default);

                    vm.ExplorerItems.Remove(item);

                    var folder = await vm.CurrentFolder.CreateFolderAsync(folderName);

                    var newItem = await ExplorerItem.CreateAsync(folder);

                    vm.ExplorerItems.Add(newItem);
                    vm.SelectedItem = newItem;
                }
                else if (result == Controls.ContentDialogs.NameCollisionDialogResult.Rename)
                {
                    var items = await vm.CurrentFolder.GetItemsAsync();

                    var unqiueName = NameCollision.GetUniqueNameForFolder(folderName, items);

                    var folder = await vm.CurrentFolder.CreateFolderAsync(unqiueName);

                    var newItem = await ExplorerItem.CreateAsync(folder);

                    vm.ExplorerItems.Add(newItem);
                    vm.SelectedItem = newItem;
                }
            }
        }
示例#3
0
        protected override async void OnExecuteAsync(IExplorerViewModel vm)
        {
            var result = await _dialogService.Prompt("Rename file", vm.SelectedItem.Name);

            if (result == null)
            {
                return;
            }

            try
            {
                await vm.SelectedItem.StorageItem.RenameAsync(result);

                var storageItem = vm.SelectedItem.StorageItem;
                var newItem     = await ExplorerItem.CreateAsync(storageItem);

                vm.ExplorerItems.Remove(vm.SelectedItem);
                vm.ExplorerItems.Add(newItem);
                vm.SelectedItem = newItem;
            }
            catch (Exception)
            {
                var unqiueName = string.Empty;

                if (vm.SelectedItem.IsFile)
                {
                    unqiueName = NameCollision.GetUniqueNameForFile(result.Split('.').First(), vm.SelectedItem.FileType, await vm.CurrentFolder.GetItemsAsync());
                }

                if (vm.SelectedItem.IsFolder)
                {
                    unqiueName = NameCollision.GetUniqueNameForFolder(result, await vm.CurrentFolder.GetItemsAsync());
                }

                var rename = await _dialogService.ShowMessage("There is already a file with the same name in this location.", $"Do you want to rename \"{vm.SelectedItem.Name}\" to \"{unqiueName}\"", "Ok", "Cancel", null);

                if (rename == true)
                {
                    await vm.SelectedItem.StorageItem.RenameAsync(unqiueName);

                    var storageItem = vm.SelectedItem.StorageItem;
                    var newItem     = await ExplorerItem.CreateAsync(storageItem);

                    vm.ExplorerItems.Remove(vm.SelectedItem);
                    vm.ExplorerItems.Add(newItem);
                    vm.SelectedItem = newItem;
                }
            }
        }
        protected override async void OnExecuteAsync(IExplorerViewModel vm)
        {
            var pastedItem   = _clipboardService.Get();
            var storageItems = await pastedItem.GetStorageItemsAsync();

            foreach (var item in storageItems)
            {
                if (item is IStorageFolder)
                {
                    try
                    {
                        var folder = await vm.CurrentFolder.CreateFolderAsync((item as IStorageFolder).Name);

                        await(item as IStorageFolder).CopyContentsRecursiveAsync(folder, vm.CancellationTokenSource.Token);
                        var explorerItem = await ExplorerItem.CreateAsync(folder);

                        vm.ExplorerItems.Add(explorerItem);
                    }
                    catch
                    {
                        var result = await _dialogService.NameCollisionDialog(item.Name);

                        if (result == Controls.ContentDialogs.NameCollisionDialogResult.Replace)
                        {
                            var existingItem = vm.ExplorerItems.First(i => i.Name == (item as IStorageFolder).Name);
                            await existingItem.StorageItem.DeleteAsync(StorageDeleteOption.Default);

                            vm.ExplorerItems.Remove(existingItem);

                            var folder = await vm.CurrentFolder.CreateFolderAsync((item as IStorageFolder).Name);

                            vm.ExplorerItems.Add(await ExplorerItem.CreateAsync(folder));
                        }
                        else if (result == Controls.ContentDialogs.NameCollisionDialogResult.Rename)
                        {
                            var folderName = (item as IStorageFolder).Name;
                            var items      = await vm.CurrentFolder.GetItemsAsync();

                            var folder = await vm.CurrentFolder.CreateFolderAsync(NameCollision.GetUniqueNameForFolder(folderName, items, " - Copy"));

                            vm.ExplorerItems.Add(await ExplorerItem.CreateAsync(folder));
                            await(item as IStorageFolder).CopyContentsRecursiveAsync(folder, vm.CancellationTokenSource.Token);
                        }
                    }
                }
                else if (item is IStorageFile)
                {
                    try
                    {
                        var file         = await(item as IStorageFile).CopyAsync(vm.CurrentFolder, item.Name, NameCollisionOption.GenerateUniqueName);
                        var explorerItem = await ExplorerItem.CreateAsync(file);

                        vm.ExplorerItems.Add(explorerItem);
                    }
                    catch
                    {
                        var result = await _dialogService.NameCollisionDialog(item.Name);

                        if (result == Controls.ContentDialogs.NameCollisionDialogResult.Replace)
                        {
                            await(item as IStorageFile).CopyAsync(vm.CurrentFolder, item.Name, NameCollisionOption.ReplaceExisting);
                        }
                        else if (result == Controls.ContentDialogs.NameCollisionDialogResult.Rename)
                        {
                            await(item as IStorageFile).CopyAsync(vm.CurrentFolder, item.Name, NameCollisionOption.GenerateUniqueName);
                        }
                    }
                }
            }
        }