From b1f5855b905d669b9bc80e20ead6f852cbc58a9a Mon Sep 17 00:00:00 2001 From: d2dyno006 <53011783+d2dyno006@users.noreply.github.com> Date: Wed, 22 Dec 2021 21:11:00 +0100 Subject: [PATCH] Small fix for file names when pasting images --- ClipboardCanvas/CanavsPasteModels/ImagePasteModel.cs | 8 +++++++- ClipboardCanvas/Helpers/ClipboardHelpers.cs | 5 +++++ ClipboardCanvas/Package.appxmanifest | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ClipboardCanvas/CanavsPasteModels/ImagePasteModel.cs b/ClipboardCanvas/CanavsPasteModels/ImagePasteModel.cs index ee1a650..e42d7fd 100644 --- a/ClipboardCanvas/CanavsPasteModels/ImagePasteModel.cs +++ b/ClipboardCanvas/CanavsPasteModels/ImagePasteModel.cs @@ -16,6 +16,7 @@ using ClipboardCanvas.Contexts.Operations; using ClipboardCanvas.Helpers; using ClipboardCanvas.Helpers.Filesystem; +using System.IO; namespace ClipboardCanvas.CanavsPasteModels { @@ -90,8 +91,13 @@ protected override async Task SetDataFromDataPackage(DataPack } else // Just image { - SafeWrapper bitmap = await dataPackage.SafeGetBitmapAsync(); + SafeWrapper uri = await dataPackage.SafeGetUriAsync(); + + if (uri) + { + customName = Path.GetFileName(uri.Result.LocalPath); + } if (!bitmap) { diff --git a/ClipboardCanvas/Helpers/ClipboardHelpers.cs b/ClipboardCanvas/Helpers/ClipboardHelpers.cs index a56d99e..7c26c47 100644 --- a/ClipboardCanvas/Helpers/ClipboardHelpers.cs +++ b/ClipboardCanvas/Helpers/ClipboardHelpers.cs @@ -47,5 +47,10 @@ public static async Task> SafeGetBitmap { return await SafeWrapperRoutines.SafeWrapAsync(() => dataPackage.GetBitmapAsync().AsTask()); } + + public static async Task> SafeGetUriAsync(this DataPackageView dataPackage) + { + return await SafeWrapperRoutines.SafeWrapAsync(() => dataPackage.GetUriAsync().AsTask()); + } } } diff --git a/ClipboardCanvas/Package.appxmanifest b/ClipboardCanvas/Package.appxmanifest index 95d3e37..510bb84 100644 --- a/ClipboardCanvas/Package.appxmanifest +++ b/ClipboardCanvas/Package.appxmanifest @@ -32,7 +32,7 @@ EntryPoint="$targetentrypoint$">