diff --git a/src/modules/peek/Peek.Common/Helpers/ReadableStringHelper.cs b/src/modules/peek/Peek.Common/Helpers/ReadableStringHelper.cs index d95a72599c..f4f51d4774 100644 --- a/src/modules/peek/Peek.Common/Helpers/ReadableStringHelper.cs +++ b/src/modules/peek/Peek.Common/Helpers/ReadableStringHelper.cs @@ -45,5 +45,13 @@ namespace Peek.Common.Helpers return formattedString; } + + public static string FormatResourceString(string resourceId, object? args0, object? args1) + { + var formatString = ResourceLoader.GetForViewIndependentUse().GetString(resourceId); + var formattedString = string.Format(formatString, args0, args1); + + return formattedString; + } } } diff --git a/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml b/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml index 6617315cf9..ada5a3357f 100644 --- a/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml +++ b/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml @@ -5,11 +5,11 @@ x:Class="Peek.FilePreviewer.FilePreview" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:controls="using:Peek.FilePreviewer.Controls" xmlns:conv="using:Peek.Common.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:Peek.FilePreviewer" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:controls="using:Peek.FilePreviewer.Controls" mc:Ignorable="d"> @@ -21,14 +21,16 @@ - + BitmapPreviewer != null; + public string ImageInfoTooltip => imageTooltip; + public IUnsupportedFilePreviewer? UnsupportedFilePreviewer => Previewer as IUnsupportedFilePreviewer; public bool IsUnsupportedPreviewVisible => UnsupportedFilePreviewer != null; @@ -90,6 +95,8 @@ namespace Peek.FilePreviewer PreviewSizeChanged?.Invoke(this, new PreviewSizeChangedArgs(size)); await Previewer.LoadPreviewAsync(); } + + await UpdateImageTooltipAsync(); } private void PreviewBrowser_NavigationCompleted(WebView2 sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs args) @@ -97,5 +104,33 @@ namespace Peek.FilePreviewer // Once browser has completed navigation it is ready to be visible OnPropertyChanged(nameof(IsBrowserVisible)); } + + private async Task UpdateImageTooltipAsync() + { + if (File == null) + { + return; + } + + imageTooltip = string.Empty; + + // Fetch and format available file properties + imageTooltip += ReadableStringHelper.FormatResourceString("PreviewTooltip_FileName", File.FileName); + + string fileType = await PropertyHelper.GetFileType(File.Path); + imageTooltip += string.IsNullOrEmpty(fileType) ? string.Empty : "\n" + ReadableStringHelper.FormatResourceString("PreviewTooltip_FileType", fileType); + + string dateModified = File.DateModified.ToString(); + imageTooltip += string.IsNullOrEmpty(dateModified) ? string.Empty : "\n" + ReadableStringHelper.FormatResourceString("PreviewTooltip_DateModified", dateModified); + + Size dimensions = await PropertyHelper.GetImageSize(File.Path); + imageTooltip += dimensions.IsEmpty ? string.Empty : "\n" + ReadableStringHelper.FormatResourceString("PreviewTooltip_Dimensions", dimensions.Width, dimensions.Height); + + ulong bytes = await PropertyHelper.GetFileSizeInBytes(File.Path); + string fileSize = ReadableStringHelper.BytesToReadableString(bytes); + imageTooltip += string.IsNullOrEmpty(fileSize) ? string.Empty : "\n" + ReadableStringHelper.FormatResourceString("PreviewTooltip_FileSize", fileSize); + + OnPropertyChanged(nameof(ImageInfoTooltip)); + } } } diff --git a/src/modules/peek/Peek.UI/Strings/en-us/Resources.resw b/src/modules/peek/Peek.UI/Strings/en-us/Resources.resw index 45ab4adb33..dd2cc0cc70 100644 --- a/src/modules/peek/Peek.UI/Strings/en-us/Resources.resw +++ b/src/modules/peek/Peek.UI/Strings/en-us/Resources.resw @@ -181,4 +181,24 @@ {0} EB Abbrivation for the size unit exabyte. + + Filename: {0} + Filename for the tooltip of preview. {0} is the name. + + + Item Type: {0} + Item Type for the tooltip of preview. {0} is the type. + + + Date Modified: {0} + Date Modified label for the tooltip of preview. {0} is the date. + + + Dimensions: {0} x {1} + Dimensions label for the tooltip of preview. {0} is the width, {1} is the height. + + + Size: {0} + File Size label for the tooltip of preview. {0} is the size. + \ No newline at end of file