mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
[Peek]Update FilePreviewer to prevent tooltips from obscuring title bar controls (#34718)
* Update FilePreviewer to prevent tooltips from obscuring title bar controls. Fixes #34496 * Small tidy to pointer move handler and StringBuilder setup.
This commit is contained in:
@@ -29,18 +29,25 @@
|
|||||||
x:Name="ImagePreview"
|
x:Name="ImagePreview"
|
||||||
MaxWidth="{x:Bind ImagePreviewer.MaxImageSize.Width, Mode=OneWay}"
|
MaxWidth="{x:Bind ImagePreviewer.MaxImageSize.Width, Mode=OneWay}"
|
||||||
MaxHeight="{x:Bind ImagePreviewer.MaxImageSize.Height, Mode=OneWay}"
|
MaxHeight="{x:Bind ImagePreviewer.MaxImageSize.Height, Mode=OneWay}"
|
||||||
|
PointerMoved="ToolTipParentControl_PointerMoved"
|
||||||
Source="{x:Bind ImagePreviewer.Preview, Mode=OneWay}"
|
Source="{x:Bind ImagePreviewer.Preview, Mode=OneWay}"
|
||||||
ToolTipService.ToolTip="{x:Bind InfoTooltip, Mode=OneWay}"
|
Visibility="{x:Bind IsPreviewVisible(ImagePreviewer, Previewer.State), Mode=OneWay}">
|
||||||
Visibility="{x:Bind IsPreviewVisible(ImagePreviewer, Previewer.State), Mode=OneWay}" />
|
<ToolTipService.ToolTip>
|
||||||
|
<ToolTip Content="{x:Bind InfoTooltip, Mode=OneWay}" />
|
||||||
|
</ToolTipService.ToolTip>
|
||||||
|
</Image>
|
||||||
|
|
||||||
<MediaPlayerElement
|
<MediaPlayerElement
|
||||||
x:Name="VideoPreview"
|
x:Name="VideoPreview"
|
||||||
AreTransportControlsEnabled="True"
|
AreTransportControlsEnabled="True"
|
||||||
AutoPlay="True"
|
AutoPlay="True"
|
||||||
FlowDirection="LeftToRight"
|
FlowDirection="LeftToRight"
|
||||||
|
PointerMoved="ToolTipParentControl_PointerMoved"
|
||||||
Source="{x:Bind VideoPreviewer.Preview, Mode=OneWay}"
|
Source="{x:Bind VideoPreviewer.Preview, Mode=OneWay}"
|
||||||
ToolTipService.ToolTip="{x:Bind InfoTooltip, Mode=OneWay}"
|
|
||||||
Visibility="{x:Bind IsPreviewVisible(VideoPreviewer, Previewer.State), Mode=OneWay}">
|
Visibility="{x:Bind IsPreviewVisible(VideoPreviewer, Previewer.State), Mode=OneWay}">
|
||||||
|
<ToolTipService.ToolTip>
|
||||||
|
<ToolTip Content="{x:Bind InfoTooltip, Mode=OneWay}" />
|
||||||
|
</ToolTipService.ToolTip>
|
||||||
<MediaPlayerElement.KeyboardAccelerators>
|
<MediaPlayerElement.KeyboardAccelerators>
|
||||||
<KeyboardAccelerator Key="Space" Invoked="KeyboardAccelerator_Space_Invoked" />
|
<KeyboardAccelerator Key="Space" Invoked="KeyboardAccelerator_Space_Invoked" />
|
||||||
</MediaPlayerElement.KeyboardAccelerators>
|
</MediaPlayerElement.KeyboardAccelerators>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using ManagedCommon;
|
|||||||
using Microsoft.PowerToys.Telemetry;
|
using Microsoft.PowerToys.Telemetry;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
|
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||||
using Microsoft.UI.Xaml.Input;
|
using Microsoft.UI.Xaml.Input;
|
||||||
using Microsoft.Web.WebView2.Core;
|
using Microsoft.Web.WebView2.Core;
|
||||||
using Peek.Common.Extensions;
|
using Peek.Common.Extensions;
|
||||||
@@ -340,10 +341,8 @@ namespace Peek.FilePreviewer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch and format available file properties
|
// Fetch and format available file properties
|
||||||
var sb = new StringBuilder();
|
|
||||||
|
|
||||||
string fileNameFormatted = ReadableStringHelper.FormatResourceString("PreviewTooltip_FileName", Item.Name);
|
string fileNameFormatted = ReadableStringHelper.FormatResourceString("PreviewTooltip_FileName", Item.Name);
|
||||||
sb.Append(fileNameFormatted);
|
var sb = new StringBuilder(fileNameFormatted, 256);
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
string fileType = await Task.Run(Item.GetContentTypeAsync);
|
string fileType = await Task.Run(Item.GetContentTypeAsync);
|
||||||
@@ -360,5 +359,23 @@ namespace Peek.FilePreviewer
|
|||||||
|
|
||||||
InfoTooltip = sb.ToString();
|
InfoTooltip = sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the placement of the tooltip for those previewers supporting the feature, ensuring it does not obscure the Main Window's title bar.
|
||||||
|
/// </summary>
|
||||||
|
private void ToolTipParentControl_PointerMoved(object sender, PointerRoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var previewControl = sender as FrameworkElement;
|
||||||
|
if (previewControl != null)
|
||||||
|
{
|
||||||
|
var toolTip = ToolTipService.GetToolTip(previewControl) as ToolTip;
|
||||||
|
if (toolTip != null)
|
||||||
|
{
|
||||||
|
var pos = e.GetCurrentPoint(previewControl).Position;
|
||||||
|
toolTip.Placement = pos.Y < previewControl.ActualHeight / 2 ?
|
||||||
|
PlacementMode.Bottom : PlacementMode.Top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user