Beispiel #1
0
        private IDataObject CreateDataObject(PackagePart packagePart)
        {
            var data = new DataObject();

            data.SetData(PackageFileDataFormat, packagePart.Path);

            if (packagePart is PackageFile packageFile)
            {
                long?fileSize = null;
                if (packageFile.OriginalPath != null && File.Exists(packageFile.OriginalPath))
                {
                    // Try to get the length, it may not really exist
                    try
                    {
                        fileSize = new FileInfo(packageFile.OriginalPath).Length;
                    }
                    catch (FileNotFoundException)
                    { }
                }

                data.SetData(NativeDragDrop.FileGroupDescriptorW, NativeDragDrop.CreateFileGroupDescriptorW(packageFile.Name, packageFile.LastWriteTime, fileSize));
                data.SetData(NativeDragDrop.FileContents, new LazyPackageFileStream(packageFile));
            }

            return(data);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        private IDataObject CreateDataObject(PackagePart packagePart)
        {
            var data = new DataObject();

            data.SetData(PackageFileDataFormat, packagePart.Path);

            if (packagePart is PackageFile packageFile)
            {
                data.SetData(DataFormats.FileDrop, new[] { packageFile.Name });
                data.SetData(NativeDragDrop.FileGroupDescriptorW, NativeDragDrop.CreateFileGroupDescriptorW(packageFile.Name, packageFile.LastWriteTime));
                data.SetData(NativeDragDrop.FileContents, new LazyPackageFileStream(packageFile));
            }

            return(data);
        }
        private IDataObject CreateDataObject(PackagePart packagePart)
        {
            var data = new DataObject();

            data.SetData(PackageFileDataFormat, packagePart.Path);

            if (packagePart is PackageFile packageFile)
            {
                long?fileSize = null;
                if (packageFile.OriginalPath != null)
                {
                    fileSize = new FileInfo(packageFile.OriginalPath).Length;
                }

                data.SetData(NativeDragDrop.FileGroupDescriptorW, NativeDragDrop.CreateFileGroupDescriptorW(packageFile.Name, packageFile.LastWriteTime, fileSize));
                data.SetData(NativeDragDrop.FileContents, new LazyPackageFileStream(packageFile));
            }

            return(data);
        }