Esempio n. 1
0
        private async void PasteFiles(string destDir, IEnumerable <string> files, DragDropEffects effect)
        {
            try
            {
                if ((effect & DragDropEffects.Move) != 0)
                {
                    await _explorer.MoveFilesAsync(destDir, files);
                }
                else if ((effect & DragDropEffects.Copy) != 0)
                {
                    await _explorer.CopyFilesAsync(destDir, files);
                }
            }
            catch (OperationCanceledException)
            {
            }

            if (_isDisposed)
            {
                return;
            }

            // update subdirectories in given path
            View_ExpandDirectory(this, new DirectoryEventArgs(destDir));
        }
Esempio n. 2
0
        private async Task CopyMoveFilesToViewAsync(
            string destinationDirectory,
            DragDropEffects allowedEffects,
            IEnumerable <string> files)
        {
            // pick the destination directory
            if (destinationDirectory == null)
            {
                var folders = FindAllFolders();
                if (folders.Count < 1)
                {
                    return; // there is no destination folder, this is a no-op
                }
                if (folders.Count == 1)
                {
                    // copy/move the file right away
                    destinationDirectory = folders.First();
                }
                else
                {
                    // make user pick where to copy/move the files
                    try
                    {
                        destinationDirectory = await View.PickDirectoryAsync(folders);
                    }
                    catch (OperationCanceledException)
                    {
                        return;
                    }
                }
            }

            Trace.Assert(destinationDirectory != null);

            // ignore copy/move dest => dest operation
            var movedFiles = files.Where(path =>
                                         !string.Equals(path, destinationDirectory, StringComparison.CurrentCultureIgnoreCase));

            if (!movedFiles.Any())
            {
                return;
            }

            try
            {
                if ((allowedEffects & DragDropEffects.Move) != 0)
                {
                    await _explorer.MoveFilesAsync(destinationDirectory, movedFiles);
                }
                else if ((allowedEffects & DragDropEffects.Copy) != 0)
                {
                    await _explorer.CopyFilesAsync(destinationDirectory, movedFiles);
                }
            }
            catch (OperationCanceledException)
            {
            }
        }