Exemple #1
0
        private void DropList_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(_dragFormat) && !_dragCanceled)
            {
                var files = (string[])e.Data.GetData(DataFormats.FileDrop);
                if (files == null || !files.Any())
                {
                    return;
                }

                string destination  = null;
                var    listViewItem = FindAnchestor <ListViewItem>(e.OriginalSource);

                if (listViewItem?.Content is FileItem item)
                {
                    destination = item.ItemType == ItemType.Container
                        ? item.Path
                        : item.Directory;
                }
                else
                {
                    var listView = FindAnchestor <ListView>(e.OriginalSource);
                    if (listView.DataContext is ILister lister)
                    {
                        destination = lister.Path;
                    }
                }

                if (destination != null)
                {
                    e.Effects = (e.KeyStates & DragDropKeyStates.ControlKey) != 0
                        ? DragDropEffects.Copy
                        : DragDropEffects.Move;
                    var fileAction = e.Effects == DragDropEffects.Copy ? FileAction.Copy : FileAction.Move;
                    if (_listView.DataContext is FileLister)
                    {
                        FilesystemAction.SetClipboard <FileItem>(fileAction, files);
                    }
                    else
                    {
                        FilesystemAction.SetClipboard <IItem>(fileAction, files);
                    }

                    var action = new FilesystemAction(_notificationHost);
                    var items  = Clipboard.GetFileDropList();
                    Task.Factory.StartNew(() => { action.Paste(destination, items, fileAction); });
                    if (fileAction == FileAction.Move)
                    {
                        Clipboard.Clear();
                    }
                    e.Handled = true;
                }
            }
        }
Exemple #2
0
        private void SetSelection(FileAction fa)
        {
            var selection = ItemsView.SelectedItems.Select(s => s.Path);

            FilesystemAction.SetClipboard <FileItem>(fa, selection);
        }