[Peek]Fix icons, removed unneeded RTL code, ui tweaks and code suggestions (#32087)

* Force file pickers to open modal

* remove unneeded RTL code

* better icons and analyzer suggestions

* additions for preview controls

* more code improvs

* two nits in strings

* Adressing feedback

icon margin, drive usage bar, TitleBarHeightOption
This commit is contained in:
Jay
2024-04-16 11:04:46 +02:00
committed by GitHub
parent 83aecff13b
commit 8a210865ff
25 changed files with 150 additions and 330 deletions

View File

@@ -4,8 +4,7 @@
<Application
x:Class="Peek.UI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Peek.UI">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>

View File

@@ -89,7 +89,7 @@ namespace Peek.UI
var cmdArgs = Environment.GetCommandLineArgs();
if (cmdArgs?.Length > 1)
{
if (int.TryParse(cmdArgs[cmdArgs.Length - 1], out int powerToysRunnerPid))
if (int.TryParse(cmdArgs[^1], out int powerToysRunnerPid))
{
RunnerHelper.WaitForPowerToysRunner(powerToysRunnerPid, () =>
{

View File

@@ -11,12 +11,13 @@
xmlns:views="using:Peek.UI.Views"
xmlns:winuiex="using:WinUIEx"
Title="{x:Bind ViewModel.WindowTitle, Mode=OneWay}"
MinWidth="450"
MinHeight="400"
MinWidth="480"
MinHeight="320"
mc:Ignorable="d">
<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>
<Grid KeyboardAcceleratorPlacementMode="Hidden">
<Grid.KeyboardAccelerators>
<KeyboardAccelerator Key="Left" Invoked="PreviousNavigationInvoked" />
@@ -31,7 +32,7 @@
</Grid.KeyboardAccelerators>
<Grid.RowDefinitions>
<RowDefinition Height="48" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

View File

@@ -27,7 +27,7 @@ namespace Peek.UI
{
public MainWindowViewModel ViewModel { get; }
private ThemeListener? themeListener;
private readonly ThemeListener? themeListener;
public MainWindow()
{
@@ -47,6 +47,8 @@ namespace Peek.UI
ViewModel = Application.Current.GetService<MainWindowViewModel>();
TitleBarControl.SetTitleBarToWindow(this);
AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;
AppWindow.SetIcon("Assets/Peek/Icon.ico");
AppWindow.Closing += AppWindow_Closing;
@@ -85,14 +87,7 @@ namespace Peek.UI
{
AppWindow appWindow = this.AppWindow;
if (ThemeHelpers.GetAppTheme() == AppTheme.Light)
{
appWindow.TitleBar.ButtonForegroundColor = Colors.DarkSlateGray;
}
else
{
appWindow.TitleBar.ButtonForegroundColor = Colors.White;
}
appWindow.TitleBar.ButtonForegroundColor = ThemeHelpers.GetAppTheme() == AppTheme.Light ? Colors.DarkSlateGray : Colors.White;
}
private void PeekWindow_Activated(object sender, WindowActivatedEventArgs args)
@@ -159,16 +154,16 @@ namespace Peek.UI
// If no size is requested, try to fit to the monitor size.
Size requestedSize = e.PreviewSize.MonitorSize ?? monitorSize;
var contentScale = e.PreviewSize.UseEffectivePixels ? 1 : monitorScale;
Size scaledRequestedSize = new Size(requestedSize.Width / contentScale, requestedSize.Height / contentScale);
Size scaledRequestedSize = new(requestedSize.Width / contentScale, requestedSize.Height / contentScale);
// TODO: Investigate why portrait images do not perfectly fit edge-to-edge
// TODO: Investigate why portrait images do not perfectly fit edge-to-edge --> WindowHeightContentPadding can be 0 (or close to that) if custom? [Jay]
Size monitorMinContentSize = GetMonitorMinContentSize(monitorScale);
Size monitorMaxContentSize = GetMonitorMaxContentSize(monitorSize, monitorScale);
Size adjustedContentSize = scaledRequestedSize.Fit(monitorMaxContentSize, monitorMinContentSize);
var titleBarHeight = TitleBarControl.ActualHeight;
var desiredWindowHeight = adjustedContentSize.Height + titleBarHeight + WindowConstants.WindowWidthContentPadding;
var desiredWindowWidth = adjustedContentSize.Width + WindowConstants.WindowHeightContentPadding;
var desiredWindowWidth = adjustedContentSize.Width;
var desiredWindowHeight = adjustedContentSize.Height + titleBarHeight;
if (!TitleBarControl.Pinned)
{
@@ -220,12 +215,7 @@ namespace Peek.UI
var fileExplorerSelectedItemPath = selectedItems.GetItemAt(0).ToIFileSystemItem().Path;
var currentItemPath = ViewModel.CurrentItem?.Path;
if (fileExplorerSelectedItemPath == null || currentItemPath == null || fileExplorerSelectedItemPath == currentItemPath)
{
return false;
}
return true;
return fileExplorerSelectedItemPath != null && currentItemPath != null && fileExplorerSelectedItemPath != currentItemPath;
}
catch (Exception ex)
{

View File

@@ -6,20 +6,24 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Peek.UI.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FlowDirection="{x:Bind TitleBarFlowDirection, Mode=OneWay}"
mc:Ignorable="d">
<Grid x:Name="TitleBarRootContainer" Height="48">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="SystemLeftPaddingColumn" Width="0" />
<ColumnDefinition x:Name="DraggableColumn" Width="*" />
<ColumnDefinition x:Name="LaunchAppButtonColumn" Width="Auto" />
<ColumnDefinition x:Name="AppRightPaddingColumn" Width="8" />
<ColumnDefinition x:Name="PinButtonColumn" Width="Auto" />
<ColumnDefinition x:Name="SystemRightPaddingColumn" Width="180" />
</Grid.ColumnDefinitions>
<Grid
x:Name="AppIconAndFileTitleContainer"
Margin="8,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
ColumnSpacing="4">
Grid.Column="1"
HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="AppIconColumn" Width="32" />
<ColumnDefinition x:Name="AppIconColumn" Width="Auto" />
<ColumnDefinition x:Name="FileTitleColumn" Width="*" />
</Grid.ColumnDefinitions>
@@ -27,35 +31,32 @@
x:Name="PeekLogo"
x:Uid="PeekLogo"
Grid.Column="0"
Width="24"
Height="24"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Source="../../Assets/Peek/AppList.scale-400.png"
Width="16"
Height="16"
Margin="16,0"
Source="../../Assets/Peek/Icon.ico"
Stretch="UniformToFill" />
<Grid
x:Name="FileCountAndNameContainer"
Grid.Column="1"
VerticalAlignment="Center"
ColumnSpacing="4">
VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="FileCountColumn" Width="auto" />
<ColumnDefinition x:Name="FileCountColumn" Width="Auto" />
<ColumnDefinition x:Name="FileNameColumn" Width="*" />
</Grid.ColumnDefinitions>
<TextBlock
x:Name="AppTitle_FileCount"
x:Uid="AppTitle_FileCount"
Grid.Column="0"
FontWeight="Bold"
Margin="0,0,8,0"
FontWeight="SemiBold"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind FileCountText, Mode=OneWay}"
Visibility="{x:Bind IsMultiSelection, Mode=OneWay}" />
<TextBlock
x:Name="AppTitle_FileName"
x:Uid="AppTitle_FileName"
Grid.Column="1"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind Item.Name, Mode=OneWay}"
@@ -65,7 +66,7 @@
<Button
x:Name="LaunchAppButton"
x:Uid="LaunchAppButton"
Grid.Column="2"
VerticalAlignment="Center"
Command="{x:Bind LaunchDefaultAppButtonCommand, Mode=OneWay}"
ToolTipService.ToolTip="{x:Bind OpenWithAppToolTip, Mode=OneWay}"
@@ -74,12 +75,10 @@
<StackPanel Orientation="Horizontal" Spacing="4">
<FontIcon
x:Name="LaunchAppButton_Icon"
x:Uid="LaunchAppButton_Icon"
FontSize="{StaticResource CaptionTextBlockFontSize}"
FontSize="16"
Glyph="&#xE8E5;" />
<TextBlock
x:Name="LaunchAppButton_Text"
x:Uid="LaunchAppButton_Text"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind OpenWithAppText, Mode=OneWay}" />
</StackPanel>
@@ -91,15 +90,14 @@
<Button
x:Name="PinButton"
x:Uid="PinButton"
Grid.Column="4"
VerticalAlignment="Center"
Command="{x:Bind PinCommand, Mode=OneWay}"
ToolTipService.ToolTip="{x:Bind PinToolTip(Pinned), Mode=OneWay}">
<Button.Content>
<FontIcon
x:Name="PinButton_Icon"
x:Uid="PinButton_Icon"
FontSize="{StaticResource CaptionTextBlockFontSize}"
FontSize="16"
Glyph="{x:Bind PinGlyph(Pinned), Mode=OneWay}" />
</Button.Content>
</Button>

View File

@@ -71,13 +71,6 @@ namespace Peek.UI.Views
[ObservableProperty]
private bool pinned = false;
private ColumnDefinition systemLeftPaddingColumn = new() { Width = new GridLength(0) };
private ColumnDefinition draggableColumn = new() { Width = new GridLength(1, GridUnitType.Star) };
private ColumnDefinition launchAppButtonColumn = new() { Width = GridLength.Auto };
private ColumnDefinition appRightPaddingColumn = new() { Width = new GridLength(65) };
private ColumnDefinition pinButtonColumn = new() { Width = new GridLength(40) };
private ColumnDefinition systemRightPaddingColumn = new() { Width = new GridLength(0) };
public TitleBar()
{
InitializeComponent();
@@ -150,7 +143,7 @@ namespace Peek.UI.Views
PowerToysTelemetry.Log.WriteEvent(new OpenWithEvent() { App = DefaultAppName ?? string.Empty });
// StorageFile objects can't represent files that are ".lnk", ".url", or ".wsh" file types.
// https://learn.microsoft.com/en-us/uwp/api/windows.storage.storagefile?view=winrt-22621
// https://learn.microsoft.com/uwp/api/windows.storage.storagefile?view=winrt-22621
if (storageFile == null)
{
options.DisplayApplicationPicker = true;
@@ -177,7 +170,7 @@ namespace Peek.UI.Views
public string PinGlyph(bool pinned)
{
return pinned ? "\xE841" : "\xE77A";
return pinned ? "\xE77A" : "\xE718";
}
public string PinToolTip(bool pinned)
@@ -191,54 +184,6 @@ namespace Peek.UI.Views
Pinned = !Pinned;
}
public FlowDirection TitleBarFlowDirection
{
get
{
var direction = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft ?
FlowDirection.RightToLeft :
FlowDirection.LeftToRight;
SetupGridColumnDefinitions(direction);
return direction;
}
}
private void SetupGridColumnDefinitions(FlowDirection direction)
{
TitleBarRootContainer.ColumnDefinitions.Clear();
if (direction == FlowDirection.LeftToRight)
{
TitleBarRootContainer.ColumnDefinitions.Add(systemLeftPaddingColumn);
TitleBarRootContainer.ColumnDefinitions.Add(draggableColumn);
TitleBarRootContainer.ColumnDefinitions.Add(launchAppButtonColumn);
TitleBarRootContainer.ColumnDefinitions.Add(appRightPaddingColumn);
TitleBarRootContainer.ColumnDefinitions.Add(pinButtonColumn);
TitleBarRootContainer.ColumnDefinitions.Add(systemRightPaddingColumn);
Grid.SetColumn(AppIconAndFileTitleContainer, 1);
FileCountAndNameContainer.HorizontalAlignment = HorizontalAlignment.Left;
Grid.SetColumn(LaunchAppButton, 2);
Grid.SetColumn(PinButton, 4);
}
else
{
TitleBarRootContainer.ColumnDefinitions.Add(systemRightPaddingColumn);
TitleBarRootContainer.ColumnDefinitions.Add(pinButtonColumn);
TitleBarRootContainer.ColumnDefinitions.Add(appRightPaddingColumn);
TitleBarRootContainer.ColumnDefinitions.Add(launchAppButtonColumn);
TitleBarRootContainer.ColumnDefinitions.Add(draggableColumn);
TitleBarRootContainer.ColumnDefinitions.Add(systemLeftPaddingColumn);
Grid.SetColumn(AppIconAndFileTitleContainer, 4);
FileCountAndNameContainer.HorizontalAlignment = HorizontalAlignment.Right;
Grid.SetColumn(LaunchAppButton, 3);
LaunchAppButton.HorizontalAlignment = HorizontalAlignment.Left;
Grid.SetColumn(PinButton, 1);
PinButton.HorizontalAlignment = HorizontalAlignment.Right;
}
}
private void TitleBarRootContainer_SizeChanged(object sender, SizeChangedEventArgs e)
{
UpdateDragRegion();
@@ -256,37 +201,22 @@ namespace Peek.UI.Views
{
var scale = MainWindow.GetMonitorScale();
systemRightPaddingColumn.Width = new GridLength(appWindow.TitleBar.RightInset / scale);
systemLeftPaddingColumn.Width = new GridLength(appWindow.TitleBar.LeftInset / scale);
SystemLeftPaddingColumn.Width = new GridLength(appWindow.TitleBar.LeftInset / scale);
SystemRightPaddingColumn.Width = new GridLength(appWindow.TitleBar.RightInset / scale);
var dragRectsList = new List<RectInt32>();
RectInt32 dragRectangleLeft;
RectInt32 dragRectangleRight;
if (TitleBarFlowDirection == FlowDirection.LeftToRight)
{
dragRectangleLeft.X = (int)(systemLeftPaddingColumn.ActualWidth * scale);
dragRectangleLeft.Y = 0;
dragRectangleLeft.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
dragRectangleLeft.Width = (int)(draggableColumn.ActualWidth * scale);
dragRectangleLeft.X = (int)(SystemLeftPaddingColumn.ActualWidth * scale);
dragRectangleLeft.Y = 0;
dragRectangleLeft.Width = (int)(DraggableColumn.ActualWidth * scale);
dragRectangleLeft.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
dragRectangleRight.X = (int)((systemLeftPaddingColumn.ActualWidth + draggableColumn.ActualWidth + launchAppButtonColumn.ActualWidth) * scale);
dragRectangleRight.Y = 0;
dragRectangleRight.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
dragRectangleRight.Width = (int)(appRightPaddingColumn.ActualWidth * scale);
}
else
{
dragRectangleRight.X = (int)(pinButtonColumn.ActualWidth * scale);
dragRectangleRight.Y = 0;
dragRectangleRight.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
dragRectangleRight.Width = (int)(appRightPaddingColumn.ActualWidth * scale);
dragRectangleLeft.X = (int)((pinButtonColumn.ActualWidth + appRightPaddingColumn.ActualWidth + launchAppButtonColumn.ActualWidth) * scale);
dragRectangleLeft.Y = 0;
dragRectangleLeft.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
dragRectangleLeft.Width = (int)(draggableColumn.ActualWidth * scale);
}
dragRectangleRight.X = (int)((SystemLeftPaddingColumn.ActualWidth + DraggableColumn.ActualWidth + LaunchAppButtonColumn.ActualWidth) * scale);
dragRectangleRight.Y = 0;
dragRectangleRight.Width = (int)(AppRightPaddingColumn.ActualWidth * scale);
dragRectangleRight.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
dragRectsList.Add(dragRectangleLeft);
dragRectsList.Add(dragRectangleRight);
@@ -303,14 +233,7 @@ namespace Peek.UI.Views
appWindow.TitleBar.ExtendsContentIntoTitleBar = true;
appWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
appWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
if (ThemeHelpers.GetAppTheme() == AppTheme.Light)
{
appWindow.TitleBar.ButtonForegroundColor = Colors.DarkSlateGray;
}
else
{
appWindow.TitleBar.ButtonForegroundColor = Colors.White;
}
appWindow.TitleBar.ButtonForegroundColor = ThemeHelpers.GetAppTheme() == AppTheme.Light ? Colors.DarkSlateGray : Colors.White;
mainWindow.SetTitleBar(this);
}

View File

@@ -2,8 +2,6 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
namespace Peek.UI
{
public interface IUserSettings

View File

@@ -27,12 +27,7 @@ namespace Peek.UI
IsMultipleFilesActivation = hasMoreThanOneItem;
var neighboringItemsShellArray = hasMoreThanOneItem ? selectedItemsShellArray : FileExplorerHelper.GetItems(foregroundWindowHandle);
if (neighboringItemsShellArray == null)
{
return null;
}
return new NeighboringItems(neighboringItemsShellArray);
return neighboringItemsShellArray == null ? null : new NeighboringItems(neighboringItemsShellArray);
}
}
}

View File

@@ -19,7 +19,7 @@ namespace Peek.UI
private readonly SettingsUtils _settingsUtils;
private readonly IFileSystemWatcher _watcher;
private readonly object _loadingSettingsLock = new object();
private readonly object _loadingSettingsLock = new();
public bool CloseAfterLosingFocus { get; private set; }

View File

@@ -194,7 +194,7 @@
<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>
<value>Dimensions: {0} × {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">
@@ -206,7 +206,7 @@
<comment>Tooltip of preview when there's no file info available.</comment>
</data>
<data name="PinButton_Tooltip" xml:space="preserve">
<value>Pin the window to the current location</value>
<value>Pin the window to the current size</value>
<comment>Tooltip for button to pin the Peek window.</comment>
</data>
<data name="UnpinButton_ToolTip" xml:space="preserve">
@@ -266,7 +266,7 @@
<comment>Title of the Peek window. {0} is the name of the currently previewed item."Peek" is the name of the utility.</comment>
</data>
<data name="Drive_FreeSpace" xml:space="preserve">
<value>{0} free</value>
<value>{0} available</value>
<comment>{0} is the free space of the drive</comment>
</data>
<data name="Drive_UsedSpace" xml:space="preserve">