Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Peek] Update FilePreviewer to prevent tooltips from obscuring title bar controls #34718

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/modules/peek/Peek.FilePreviewer/FilePreview.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,24 @@
MaxWidth="{x:Bind ImagePreviewer.MaxImageSize.Width, Mode=OneWay}"
MaxHeight="{x:Bind ImagePreviewer.MaxImageSize.Height, 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}"
PointerMoved="ToolTipParentControl_PointerMoved">
<ToolTipService.ToolTip>
<ToolTip Content="{x:Bind InfoTooltip, Mode=OneWay}" />
</ToolTipService.ToolTip>
</Image>

<MediaPlayerElement
x:Name="VideoPreview"
AreTransportControlsEnabled="True"
AutoPlay="True"
FlowDirection="LeftToRight"
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}"
PointerMoved="ToolTipParentControl_PointerMoved">
<ToolTipService.ToolTip>
<ToolTip Content="{x:Bind InfoTooltip, Mode=OneWay}" />
</ToolTipService.ToolTip>
<MediaPlayerElement.KeyboardAccelerators>
<KeyboardAccelerator Key="Space" Invoked="KeyboardAccelerator_Space_Invoked" />
</MediaPlayerElement.KeyboardAccelerators>
Expand Down
23 changes: 20 additions & 3 deletions src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.PowerToys.Telemetry;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using Microsoft.Web.WebView2.Core;
using Peek.Common.Extensions;
Expand Down Expand Up @@ -336,10 +337,8 @@ private async Task UpdateTooltipAsync(CancellationToken cancellationToken)
}

// Fetch and format available file properties
var sb = new StringBuilder();

string fileNameFormatted = ReadableStringHelper.FormatResourceString("PreviewTooltip_FileName", Item.Name);
sb.Append(fileNameFormatted);
var sb = new StringBuilder(fileNameFormatted, 256);

cancellationToken.ThrowIfCancellationRequested();
string fileType = await Task.Run(Item.GetContentTypeAsync);
Expand All @@ -356,5 +355,23 @@ private async Task UpdateTooltipAsync(CancellationToken cancellationToken)

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;
}
}
}
}
}
Loading