private bool HandleDataObject(PackageFolder folder, IDataObject data, bool copy) { if (!CanHandleDataObject(folder, data)) { return(false); } if (data.GetDataPresent(PackageFileDataFormat)) { if (data.GetData(PackageFileDataFormat) is string packagePartPath) { var packagePart = RootFolder.GetPackageParts().FirstOrDefault(part => part.Path == packagePartPath); if (packagePart != null) { folder = folder ?? RootFolder; if (packagePart is PackageFile file) { folder.AddFile(file, copy); } else { if (packagePart is PackageFolder childFolder && !folder.IsDescendantOf(childFolder)) { folder.AddFolder(childFolder, copy); } } return(true); } } } if (data.GetDataPresent(NativeDragDrop.FileGroupDescriptorW)) { folder = folder ?? RootFolder; var viewModel = DataContext as PackageViewModel; viewModel.AddDraggedAndDroppedFileDescriptors(folder, NativeDragDrop.GetFileGroupDescriptorW(data)); return(true); } if (data.GetDataPresent(DataFormats.FileDrop)) { var value = data.GetData(DataFormats.FileDrop); if (value is string[] filenames && filenames.Length > 0) { var viewModel = DataContext as PackageViewModel; viewModel.AddDraggedAndDroppedFiles(folder, filenames); return(true); } } return(false); }
private void OnTreeViewItemDrop(object sender, DragEventArgs e) { PackageFolder folder = null; var item = sender as TreeViewItem; if (item != null) { folder = item.DataContext as PackageFolder; } IDataObject data = e.Data; if (data.GetDataPresent(DataFormats.FileDrop)) { object value = data.GetData(DataFormats.FileDrop); var filenames = value as string[]; if (filenames != null && filenames.Length > 0) { var viewModel = DataContext as PackageViewModel; viewModel.AddDraggedAndDroppedFiles(folder, filenames); e.Handled = true; } } else if (data.GetDataPresent(PackageFileDataFormat)) { var packagePart = data.GetData(PackageFileDataFormat) as PackagePart; if (packagePart != null) { folder = folder ?? RootFolder; var file = packagePart as PackageFile; if (file != null) { bool copying = (e.KeyStates & DragDropKeyStates.ControlKey) == DragDropKeyStates.ControlKey; folder.AddFile(file, copying); } else { var childFolder = packagePart as PackageFolder; if (childFolder != null && !folder.IsDescendantOf(childFolder)) { folder.AddFolder(childFolder); } } e.Handled = true; } } }
private void OnTreeViewItemDrop(object sender, DragEventArgs e) { PackageFolder folder = null; if (sender is TreeViewItem item) { folder = item.DataContext as PackageFolder; } var data = e.Data; if (data.GetDataPresent(DataFormats.FileDrop)) { var value = data.GetData(DataFormats.FileDrop); if (value is string[] filenames && filenames.Length > 0) { var viewModel = DataContext as PackageViewModel; viewModel.AddDraggedAndDroppedFiles(folder, filenames); e.Handled = true; } } else if (data.GetDataPresent(PackageFileDataFormat)) { if (data.GetData(PackageFileDataFormat) is PackagePart packagePart) { folder = folder ?? RootFolder; if (packagePart is PackageFile file) { var copying = (e.KeyStates & DragDropKeyStates.ControlKey) == DragDropKeyStates.ControlKey; folder.AddFile(file, copying); } else { if (packagePart is PackageFolder childFolder && !folder.IsDescendantOf(childFolder)) { folder.AddFolder(childFolder); } } e.Handled = true; } } }