Esempio n. 1
0
        void Paste()
        {
            if (Clipboard.ContainsFileDropList())
            {
                var filenames = new List <string>();

                Parallel.ForEach(Clipboard.GetFileDropList().Cast <string>(), filepath =>
                {
                    filenames.Add(filepath);
                });

                var supportedFilenames = FilesManager.FilterSupportedFiles(filenames.ToArray());
                if (supportedFilenames.Length > 0)
                {
                    Parallel.ForEach(supportedFilenames, AddNewTab);
                }
            }
        }
Esempio n. 2
0
        public DataPackageView GetContent()
        {
            var dataPackage = new DataPackage();

            if (Clipboard.ContainsImage())
            {
                dataPackage.SetDataProvider(StandardDataFormats.Bitmap, async ct =>
                {
                    var bitmap       = Clipboard.GetImage();
                    var bitmapStream = new MemoryStream();

                    var bitmapEncoder = new BmpBitmapEncoder();
                    bitmapEncoder.Frames.Add(BitmapFrame.Create(bitmap));
                    bitmapEncoder.Save(bitmapStream);

                    // Letting a MemoryStream run around does not cause problems.
                    // The GC will take care of it, just like a byte[].
                    return(RandomAccessStreamReference.CreateFromStream(bitmapStream.AsRandomAccessStream()));
                });
            }
            if (Clipboard.ContainsText())
            {
                // Copying significant amounts of text still makes Clipboard.GetText() slow, so
                // we'll still use the SetDataProvider
                dataPackage.SetDataProvider(StandardDataFormats.Text, async ct =>
                {
                    return(Clipboard.GetText());
                });
            }
            if (Clipboard.ContainsData(DataFormats.Html))
            {
                dataPackage.SetDataProvider(StandardDataFormats.Html, async ct =>
                {
                    return(Clipboard.GetData(DataFormats.Html));
                });
            }
            if (Clipboard.ContainsData(DataFormats.Rtf))
            {
                dataPackage.SetDataProvider(StandardDataFormats.Rtf, async ct =>
                {
                    return(Clipboard.GetData(DataFormats.Rtf));
                });
            }
            if (Clipboard.ContainsFileDropList())
            {
                dataPackage.SetDataProvider(StandardDataFormats.StorageItems, async ct =>
                {
                    var list            = Clipboard.GetFileDropList();
                    var storageItemList = new List <IStorageItem>(list.Count);
                    foreach (var path in list)
                    {
                        var attr = File.GetAttributes(path);
                        if (attr.HasFlag(global::System.IO.FileAttributes.Directory))
                        {
                            storageItemList.Add(await StorageFolder.GetFolderFromPathAsync(path));
                        }
                        else
                        {
                            storageItemList.Add(await StorageFile.GetFileFromPathAsync(path));
                        }
                    }
                    return(storageItemList);
                });
            }

            return(dataPackage.GetView());
        }