mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
Add tooltip to File
This commit is contained in:
@@ -45,5 +45,13 @@ namespace Peek.Common.Helpers
|
|||||||
|
|
||||||
return formattedString;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
x:Class="Peek.FilePreviewer.FilePreview"
|
x:Class="Peek.FilePreviewer.FilePreview"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:controls="using:Peek.FilePreviewer.Controls"
|
||||||
xmlns:conv="using:Peek.Common.Converters"
|
xmlns:conv="using:Peek.Common.Converters"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="using:Peek.FilePreviewer"
|
xmlns:local="using:Peek.FilePreviewer"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:controls="using:Peek.FilePreviewer.Controls"
|
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
@@ -21,14 +21,16 @@
|
|||||||
<Image
|
<Image
|
||||||
x:Name="PreviewImage"
|
x:Name="PreviewImage"
|
||||||
Source="{x:Bind BitmapPreviewer.Preview, Mode=OneWay}"
|
Source="{x:Bind BitmapPreviewer.Preview, Mode=OneWay}"
|
||||||
|
ToolTipService.ToolTip="{x:Bind ImageInfoTooltip, Mode=OneWay}"
|
||||||
Visibility="{x:Bind IsImageVisible, Mode=OneWay}" />
|
Visibility="{x:Bind IsImageVisible, Mode=OneWay}" />
|
||||||
|
|
||||||
<controls:BrowserControl x:Name="PreviewBrowser"
|
<controls:BrowserControl
|
||||||
|
x:Name="PreviewBrowser"
|
||||||
x:Load="True"
|
x:Load="True"
|
||||||
Source="{x:Bind BrowserPreviewer.Preview, Mode=OneWay}"
|
|
||||||
IsNavigationCompleted="{x:Bind BrowserPreviewer.IsPreviewLoaded, Mode=TwoWay}"
|
IsNavigationCompleted="{x:Bind BrowserPreviewer.IsPreviewLoaded, Mode=TwoWay}"
|
||||||
Visibility="{x:Bind IsBrowserVisible, Mode=OneWay, FallbackValue=Collapsed}"
|
NavigationCompleted="PreviewBrowser_NavigationCompleted"
|
||||||
NavigationCompleted="PreviewBrowser_NavigationCompleted"/>
|
Source="{x:Bind BrowserPreviewer.Preview, Mode=OneWay}"
|
||||||
|
Visibility="{x:Bind IsBrowserVisible, Mode=OneWay, FallbackValue=Collapsed}" />
|
||||||
|
|
||||||
<local:UnsupportedFilePreview
|
<local:UnsupportedFilePreview
|
||||||
DateModified="{x:Bind UnsupportedFilePreviewer.DateModified, Mode=OneWay}"
|
DateModified="{x:Bind UnsupportedFilePreviewer.DateModified, Mode=OneWay}"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace Peek.FilePreviewer
|
|||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.UI.Xaml.Media.Imaging;
|
using Microsoft.UI.Xaml.Media.Imaging;
|
||||||
|
using Peek.Common.Helpers;
|
||||||
using Peek.Common.Models;
|
using Peek.Common.Models;
|
||||||
using Peek.FilePreviewer.Models;
|
using Peek.FilePreviewer.Models;
|
||||||
using Peek.FilePreviewer.Previewers;
|
using Peek.FilePreviewer.Previewers;
|
||||||
@@ -36,7 +37,9 @@ namespace Peek.FilePreviewer
|
|||||||
[NotifyPropertyChangedFor(nameof(IsUnsupportedPreviewVisible))]
|
[NotifyPropertyChangedFor(nameof(IsUnsupportedPreviewVisible))]
|
||||||
[NotifyPropertyChangedFor(nameof(BrowserPreviewer))]
|
[NotifyPropertyChangedFor(nameof(BrowserPreviewer))]
|
||||||
[NotifyPropertyChangedFor(nameof(IsBrowserVisible))]
|
[NotifyPropertyChangedFor(nameof(IsBrowserVisible))]
|
||||||
|
[NotifyPropertyChangedFor(nameof(ImageInfoTooltip))]
|
||||||
private IPreviewer? previewer;
|
private IPreviewer? previewer;
|
||||||
|
private string imageTooltip = "No file yet";
|
||||||
|
|
||||||
public FilePreview()
|
public FilePreview()
|
||||||
{
|
{
|
||||||
@@ -49,6 +52,8 @@ namespace Peek.FilePreviewer
|
|||||||
|
|
||||||
public bool IsImageVisible => BitmapPreviewer != null;
|
public bool IsImageVisible => BitmapPreviewer != null;
|
||||||
|
|
||||||
|
public string ImageInfoTooltip => imageTooltip;
|
||||||
|
|
||||||
public IUnsupportedFilePreviewer? UnsupportedFilePreviewer => Previewer as IUnsupportedFilePreviewer;
|
public IUnsupportedFilePreviewer? UnsupportedFilePreviewer => Previewer as IUnsupportedFilePreviewer;
|
||||||
|
|
||||||
public bool IsUnsupportedPreviewVisible => UnsupportedFilePreviewer != null;
|
public bool IsUnsupportedPreviewVisible => UnsupportedFilePreviewer != null;
|
||||||
@@ -90,6 +95,8 @@ namespace Peek.FilePreviewer
|
|||||||
PreviewSizeChanged?.Invoke(this, new PreviewSizeChangedArgs(size));
|
PreviewSizeChanged?.Invoke(this, new PreviewSizeChangedArgs(size));
|
||||||
await Previewer.LoadPreviewAsync();
|
await Previewer.LoadPreviewAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await UpdateImageTooltipAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PreviewBrowser_NavigationCompleted(WebView2 sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs args)
|
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
|
// Once browser has completed navigation it is ready to be visible
|
||||||
OnPropertyChanged(nameof(IsBrowserVisible));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,4 +181,24 @@
|
|||||||
<value>{0} EB</value>
|
<value>{0} EB</value>
|
||||||
<comment>Abbrivation for the size unit exabyte.</comment>
|
<comment>Abbrivation for the size unit exabyte.</comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="PreviewTooltip_FileName" xml:space="preserve">
|
||||||
|
<value>Filename: {0}</value>
|
||||||
|
<comment>Filename for the tooltip of preview. {0} is the name.</comment>
|
||||||
|
</data>
|
||||||
|
<data name="PreviewTooltip_FileType" xml:space="preserve">
|
||||||
|
<value>Item Type: {0}</value>
|
||||||
|
<comment>Item Type for the tooltip of preview. {0} is the type.</comment>
|
||||||
|
</data>
|
||||||
|
<data name="PreviewTooltip_DateModified" xml:space="preserve">
|
||||||
|
<value>Date Modified: {0}</value>
|
||||||
|
<comment>Date Modified label for the tooltip of preview. {0} is the date.</comment>
|
||||||
|
</data>
|
||||||
|
<data name="PreviewTooltip_Dimensions" xml:space="preserve">
|
||||||
|
<value>Dimensions: {0} x {1}</value>
|
||||||
|
<comment>Dimensions label for the tooltip of preview. {0} is the width, {1} is the height.</comment>
|
||||||
|
</data>
|
||||||
|
<data name="PreviewTooltip_FileSize" xml:space="preserve">
|
||||||
|
<value>Size: {0}</value>
|
||||||
|
<comment>File Size label for the tooltip of preview. {0} is the size.</comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
Reference in New Issue
Block a user