Skip to content

Commit

Permalink
[Peek] Unsupported File Previewer - Setting Window Size (#22645)
Browse files Browse the repository at this point in the history
* Adding setting for unsupported file window

* Fix
  • Loading branch information
sujessie authored Dec 8, 2022
1 parent 5bd9dd5 commit 4ef3f23
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ private async Task UpdatePreviewAsync()
if (Previewer != null)
{
var size = await Previewer.GetPreviewSizeAsync();
PreviewSizeChanged?.Invoke(this, new PreviewSizeChangedArgs(size));
SizeFormat windowSizeFormat = UnsupportedFilePreviewer != null ? SizeFormat.Percentage : SizeFormat.Pixels;
PreviewSizeChanged?.Invoke(this, new PreviewSizeChangedArgs(size, windowSizeFormat));
await Previewer.LoadPreviewAsync();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@ namespace Peek.FilePreviewer.Models
{
using Windows.Foundation;

public enum SizeFormat
{
Pixels,
Percentage,
}

public class PreviewSizeChangedArgs
{
public PreviewSizeChangedArgs(Size windowSizeRequested)
public PreviewSizeChangedArgs(Size windowSizeRequested, SizeFormat sizeFormat = SizeFormat.Pixels)
{
WindowSizeRequested = windowSizeRequested;
WindowSizeFormat = sizeFormat;
}

public Size WindowSizeRequested { get; init; }

public SizeFormat WindowSizeFormat { get; init; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />
<ProjectReference Include="..\Peek.Common\Peek.Common.csproj" />
<ProjectReference Include="..\WIC\WIC.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Peek.FilePreviewer.Previewers
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Imaging;
Expand All @@ -18,6 +19,7 @@ namespace Peek.FilePreviewer.Previewers
using Peek.Common.Helpers;
using Peek.FilePreviewer.Previewers.Helpers;
using Windows.Foundation;

using File = Peek.Common.Models.File;

public partial class UnsupportedFilePreviewer : ObservableObject, IUnsupportedFilePreviewer, IDisposable
Expand Down Expand Up @@ -46,10 +48,24 @@ public UnsupportedFilePreviewer(File file)
FileName = file.FileName;
DateModified = file.DateModified.ToString();
Dispatcher = DispatcherQueue.GetForCurrentThread();

PropertyChanged += OnPropertyChanged;

var settingsUtils = new SettingsUtils();
var settings = settingsUtils.GetSettingsOrDefault<PeekSettings>(PeekSettings.ModuleName);

if (settings != null)
{
UnsupportedFileWidthPercent = settings.Properties.UnsupportedFileWidthPercent / 100.0;
UnsupportedFileHeightPercent = settings.Properties.UnsupportedFileHeightPercent / 100.0;
}
}

private double UnsupportedFileWidthPercent { get; set; }

private double UnsupportedFileHeightPercent { get; set; }

public bool IsPreviewLoaded => iconPreview != null;

private File File { get; }

private DispatcherQueue Dispatcher { get; }
Expand All @@ -72,8 +88,7 @@ public Task<Size> GetPreviewSizeAsync()
{
return Task.Run(() =>
{
// TODO: This is the min size. Calculate a 20-25% of the screen.
return new Size(680, 500);
return new Size(UnsupportedFileWidthPercent, UnsupportedFileHeightPercent);
});
}

Expand Down
32 changes: 27 additions & 5 deletions src/modules/peek/Peek.UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

namespace Peek.UI
{
using System.Diagnostics;
using interop;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml.Input;
using Peek.FilePreviewer.Models;
using Peek.UI.Extensions;
using Peek.UI.Native;
using Windows.Foundation;
using Windows.System;
using Windows.UI.Core;
using WinUIEx;

/// <summary>
Expand Down Expand Up @@ -86,15 +85,38 @@ private void Uninitialize()
/// <param name="e">PreviewSizeChangedArgs</param>
private void FilePreviewer_PreviewSizeChanged(object sender, PreviewSizeChangedArgs e)
{
// TODO: Use design-defined rules for adjusted window size
var requestedSize = e.WindowSizeRequested;
var monitorSize = this.GetMonitorSize();

// TODO: Use design-defined rules for adjusted window size
var titleBarHeight = TitleBarControl.ActualHeight;
var maxContentSize = new Size(monitorSize.Width * MaxWindowToMonitorRatio, (monitorSize.Height - titleBarHeight) * MaxWindowToMonitorRatio);

var maxContentSize = new Size(0, 0);
var minContentSize = new Size(MinWindowWidth, MinWindowHeight - titleBarHeight);

var adjustedContentSize = requestedSize.Fit(maxContentSize, minContentSize);
var adjustedContentSize = new Size(0, 0);

if (e.WindowSizeFormat == SizeFormat.Percentage)
{
maxContentSize = new Size(monitorSize.Width * requestedSize.Width, (monitorSize.Height - titleBarHeight) * requestedSize.Height);
minContentSize = new Size(MinWindowWidth, MinWindowHeight - titleBarHeight);

adjustedContentSize = maxContentSize.Fit(maxContentSize, minContentSize);
}
else if (e.WindowSizeFormat == SizeFormat.Pixels)
{
maxContentSize = new Size(monitorSize.Width * MaxWindowToMonitorRatio, (monitorSize.Height - titleBarHeight) * MaxWindowToMonitorRatio);
minContentSize = new Size(MinWindowWidth, MinWindowHeight - titleBarHeight);

adjustedContentSize = requestedSize.Fit(maxContentSize, minContentSize);
}
else
{
Debug.Assert(false, "Unknown SizeFormat set for resizing window.");
adjustedContentSize = minContentSize;

return;
}

// TODO: Only re-center if window has not been resized by user (or use design-defined logic).
// TODO: Investigate why portrait images do not perfectly fit edge-to-edge
Expand Down
9 changes: 9 additions & 0 deletions src/settings-ui/Settings.UI.Library/PeekProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
public class PeekProperties
{
public const double DefaultUnsupportedFileWidthPercent = 40.0;
public const double DefaultUnsupportedFileHeightPercent = 40.0;

public PeekProperties()
{
ActivationShortcut = new HotkeySettings(false, true, false, false, 0x20);
UnsupportedFileWidthPercent = DefaultUnsupportedFileWidthPercent;
UnsupportedFileHeightPercent = DefaultUnsupportedFileHeightPercent;
}

public HotkeySettings ActivationShortcut { get; set; }

public double UnsupportedFileWidthPercent { get; set; }

public double UnsupportedFileHeightPercent { get; set; }

public override string ToString()
=> JsonSerializer.Serialize(this);
}
Expand Down
29 changes: 29 additions & 0 deletions src/settings-ui/Settings.UI.Library/ViewModels/PeekViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,35 @@ public HotkeySettings ActivationShortcut
}
}

public double UnsupportedFileWidthPercent
{
get => _peekSettings.Properties.UnsupportedFileWidthPercent;
set
{
if (_peekSettings.Properties.UnsupportedFileWidthPercent != value)
{
_peekSettings.Properties.UnsupportedFileWidthPercent = value;
OnPropertyChanged(nameof(UnsupportedFileWidthPercent));
NotifySettingsChanged();
}
}
}

public double UnsupportedFileHeightPercent
{
get => _peekSettings.Properties.UnsupportedFileHeightPercent;

set
{
if (_peekSettings.Properties.UnsupportedFileHeightPercent != value)
{
_peekSettings.Properties.UnsupportedFileHeightPercent = value;
OnPropertyChanged(nameof(UnsupportedFileHeightPercent));
NotifySettingsChanged();
}
}
}

private void NotifySettingsChanged()
{
// Using InvariantCulture as this is an IPC message
Expand Down
8 changes: 8 additions & 0 deletions src/settings-ui/Settings.UI/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2426,6 +2426,14 @@ From there, simply click on one of the supported files in the File Explorer and
<value>Enable Peek</value>
<comment>Peek is a product name, do not loc</comment>
</data>
<data name="Peek_UnsupportedFileWindowWidth.Header" xml:space="preserve">
<value>Unsupported file window width (%)</value>
<comment>Setting for width percent for unsupported file window.</comment>
</data>
<data name="Peek_UnsupportedFileWindowHeight.Header" xml:space="preserve">
<value>Unsupported file window height (%)</value>
<comment>Setting for height percent for unsupported file window.</comment>
</data>
<data name="FancyZones_DisableRoundCornersOnWindowSnap.Content" xml:space="preserve">
<value>Disable round corners when window is snapped</value>
</data>
Expand Down
18 changes: 18 additions & 0 deletions src/settings-ui/Settings.UI/Views/PeekPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@
<controls:ShortcutControl MinWidth="{StaticResource SettingActionControlMinWidth}" HotkeySettings="{x:Bind Path=ViewModel.ActivationShortcut, Mode=TwoWay}" />
</labs:SettingsCard>

<!-- Temporary internal setting. -->
<labs:SettingsCard x:Uid="Peek_UnsupportedFileWindowWidth">
<Slider
MinWidth="{StaticResource SettingActionControlMinWidth}"
Maximum="100"
Minimum="20"
Value="{x:Bind Mode=TwoWay, Path=ViewModel.UnsupportedFileWidthPercent}" />
</labs:SettingsCard>

<!-- Temporary internal setting. -->
<labs:SettingsCard x:Uid="Peek_UnsupportedFileWindowHeight">
<Slider
MinWidth="{StaticResource SettingActionControlMinWidth}"
Maximum="100"
Minimum="20"
Value="{x:Bind Mode=TwoWay, Path=ViewModel.UnsupportedFileHeightPercent}" />
</labs:SettingsCard>

</StackPanel>
</controls:SettingsPageControl.ModuleContent>
</controls:SettingsPageControl>
Expand Down

1 comment on commit 4ef3f23

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log for details.

Unrecognized words (140)
Abbrivation
apidl
ari
arw
BESTEFFORT
BHIDSF
BVal
calpwstr
CARRAY
CElems
Chromakey
cidl
crw
CVal
DANGEROUSLYCOMMITMERELYTODISKCACHE
dcr
dcs
Dct
DDEIf
Dds
DELAYCREATION
drf
Dwma
eip
Exa
exabyte
Excep
EXCEPINFO
EXTRINSICPROPERTIES
EXTRINSICPROPERTIESONLY
FASTPROPERTIESONLY
filetime
HANDLERPROPERTIESONLY
HDR
hicon
hif
HVal
IBitmap
IBlock
IColor
icolumn
IContext
IDecoder
IEncoder
IEnum
IIDI
iiq
IMetadata
IPalette
IQuery
IReader
ISource
ISurface
ithumbnail
jfi
jif
kdc
Keybd
Lcid
LOCKBYTES
LOCKTYPE
LVal
mdc
mef
Mega
mrw
neighborings
NOOPEN
nrw
ONLYIFCURRENT
ONLYONCE
OPENSLOWITEM
openspecs
OPLOCK
ori
overriden
pbgra
PBlob
pcch
pcelt
pcs
pef
PElems
Percision
petabyte
pkey
ppenum
pprop
PREFERQUERYPROPERTIES
Previer
PRGBA
PROPERTYNOTFOUND
PROPVARIANT
pscid
psfi
pstatstg
pstm
pui
pvar
raf
retunred
rfid
RGBE
rgelt
rgf
rwl
rwz
sachaple
SAFEARRAY
SCID
Scode
Shcontf
SHELLDETAILS
Shgno
Softcoded
srf
SRGB
STGC
STGTY
Stroe
Strret
tcs
terabyte
titlebar
tlbimp
toogle
UMsg
UOffset
USERDEFINED
UType
VARTYPE
VERSIONED
webbrowser
windowsapp
WMSDK
WReserved
WScan
wsp
WVk
YQuantized
Previously acknowledged words that are now absent brucelindbloom chromaticities companding DCR Eqn ffaa FILETIME HICON ITHUMBNAIL Pbgra PKEY Windowsapp :arrow_right:
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

... in a clone of the git@github.com:microsoft/PowerToys.git repository
on the peek branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.21/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/3653076990/attempts/1'
Available 📚 dictionaries could cover words not in the 📘 dictionary

This includes both expected items (2140) from .github/actions/spell-check/expect.txt and unrecognized words (140)

Dictionary Entries Covers
cspell:win32/src/win32.txt 53509 133
cspell:cpp/src/cpp.txt 30216 129
cspell:python/src/python/python-lib.txt 3873 32
cspell:php/php.txt 2597 17
cspell:node/node.txt 1768 14
cspell:typescript/typescript.txt 1211 12
cspell:python/src/python/python.txt 453 11
cspell:java/java.txt 7642 11
cspell:aws/aws.txt 218 8
cspell:r/src/r.txt 808 7

Consider adding them using (in .github/workflows/spelling2.yml):

      with:
        extra_dictionaries:
          cspell:win32/src/win32.txt
          cspell:cpp/src/cpp.txt
          cspell:python/src/python/python-lib.txt
          cspell:php/php.txt
          cspell:node/node.txt
          cspell:typescript/typescript.txt
          cspell:python/src/python/python.txt
          cspell:java/java.txt
          cspell:aws/aws.txt
          cspell:r/src/r.txt

To stop checking additional dictionaries, add:

      with:
        check_extra_dictionaries: ''
Errors (1)

See the 📜action log for details.

❌ Errors Count
❌ forbidden-pattern 1

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.