[FileExplorer] Add PDF Thumbnail Provider for Windows Explorer (#13058)

* Add PdfPreviewHandler to build dependency of runner

* PDF Thumbnail Provider

* Remove using brackets

* Pdf Thumbnail - Settings and Unit Tests

* Removed resx

* Add PDF Thumbnail Provider binary

* Install Pdf Thumbnail Provider

* Fix pagee spelling error.

* Update Windows dependency to version 10.0.18362.0 because that is the minimal required version of the PowerToys.

* Add Pdf Preview Handler and Pdf Thumbnail Provider
This commit is contained in:
R. de Veen
2021-09-14 18:01:45 +02:00
committed by GitHub
parent 7e22f26b52
commit 7ac1e00d01
20 changed files with 487 additions and 9 deletions

View File

@@ -80,6 +80,23 @@ namespace Microsoft.PowerToys.Settings.UI.Library
}
}
private bool enablePdfThumbnail = true;
[JsonPropertyName("pdf-thumbnail-toggle-setting")]
[JsonConverter(typeof(BoolPropertyJsonConverter))]
public bool EnablePdfThumbnail
{
get => enablePdfThumbnail;
set
{
if (value != enablePdfThumbnail)
{
LogTelemetryEvent(value);
enablePdfThumbnail = value;
}
}
}
public PowerPreviewProperties()
{
}

View File

@@ -50,12 +50,14 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
_svgThumbnailIsEnabled = Settings.Properties.EnableSvgThumbnail;
_mdRenderIsEnabled = Settings.Properties.EnableMdPreview;
_pdfRenderIsEnabled = Settings.Properties.EnablePdfPreview;
_pdfThumbnailIsEnabled = Settings.Properties.EnablePdfThumbnail;
}
private bool _svgRenderIsEnabled;
private bool _mdRenderIsEnabled;
private bool _pdfRenderIsEnabled;
private bool _svgThumbnailIsEnabled;
private bool _pdfThumbnailIsEnabled;
public bool SVGRenderIsEnabled
{
@@ -129,6 +131,24 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
}
}
public bool PDFThumbnailIsEnabled
{
get
{
return _pdfThumbnailIsEnabled;
}
set
{
if (value != _pdfThumbnailIsEnabled)
{
_pdfThumbnailIsEnabled = value;
Settings.Properties.EnablePdfThumbnail = value;
RaisePropertyChanged();
}
}
}
public string GetSettingsSubPath()
{
return _settingsConfigFileFolder + "\\" + ModuleName;

View File

@@ -60,6 +60,7 @@ namespace ViewModelTests
Assert.AreEqual(originalSettings.Properties.EnablePdfPreview, viewModel.PDFRenderIsEnabled);
Assert.AreEqual(originalSettings.Properties.EnableSvgPreview, viewModel.SVGRenderIsEnabled);
Assert.AreEqual(originalSettings.Properties.EnableSvgThumbnail, viewModel.SVGThumbnailIsEnabled);
Assert.AreEqual(originalSettings.Properties.EnablePdfThumbnail, viewModel.PDFThumbnailIsEnabled);
// Verify that the stub file was used
var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings<T>)
@@ -102,6 +103,24 @@ namespace ViewModelTests
viewModel.SVGThumbnailIsEnabled = true;
}
[TestMethod]
public void PDFThumbnailIsEnabledShouldPrevHandlerWhenSuccessful()
{
// Assert
Func<string, int> sendMockIPCConfigMSG = msg =>
{
SndModuleSettings<SndPowerPreviewSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<SndPowerPreviewSettings>>(msg);
Assert.IsTrue(snd.PowertoysSetting.FileExplorerPreviewSettings.Properties.EnablePdfThumbnail);
return 0;
};
// arrange
PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository<PowerPreviewSettings>.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, PowerPreviewSettings.ModuleName);
// act
viewModel.PDFThumbnailIsEnabled = true;
}
[TestMethod]
public void MDRenderIsEnabledShouldPrevHandlerWhenSuccessful()
{

View File

@@ -586,6 +586,10 @@
<value>Enable SVG (.svg) thumbnails</value>
<comment>Do you want this feature on / off</comment>
</data>
<data name="FileExplorerPreview_ToggleSwitch_PDF_Thumbnail.Header" xml:space="preserve">
<value>Enable PDF (.pdf) thumbnails</value>
<comment>Do you want this feature on / off</comment>
</data>
<data name="FileExplorerPreview.ModuleDescription" xml:space="preserve">
<value>These settings allow you to manage your Windows File Explorer custom preview handlers.</value>
</data>
@@ -1194,7 +1198,7 @@ Made with 💗 by Microsoft and the PowerToys community.</value>
<value>FancyZones is a window manager that makes it easy to create complex window layouts and quickly position windows into those layouts.</value>
</data>
<data name="Oobe_FileExplorer_Description" xml:space="preserve">
<value>PowerToys introduces add-ons to the Windows File Explorer that will currently enable Markdown files (.md) and SVG icons (.svg) to be viewed in the preview pane.</value>
<value>PowerToys introduces add-ons to the Windows File Explorer that will currently enable Markdown files (.md), PDF files (.pdf) and SVG icons (.svg) to be viewed in the preview pane.</value>
</data>
<data name="Oobe_ImageResizer_Description" xml:space="preserve">
<value>Image Resizer is a Windows shell extension for simple bulk image-resizing.</value>
@@ -1245,7 +1249,7 @@ Take a moment to preview the various utilities listed or view our comprehensive
</data>
<data name="Oobe_FileExplorer_HowToEnable.Text" xml:space="preserve">
<value>Open File Explorer, **select the View tab** in the File Explorer ribbon, then **select Preview Pane**.
From there, simply click on a Markdown file or SVG icon in the File Explorer and observe the content on the preview pane!</value>
From there, simply click on a Markdown file, PDF file or SVG icon in the File Explorer and observe the content on the preview pane!</value>
</data>
<data name="Oobe_HowToCreateMappings.Text" xml:space="preserve">
<value>How to create mappings</value>

View File

@@ -67,6 +67,13 @@
IsEnabled="{Binding Mode=OneWay, Path=IsElevated}"/>
</controls:Setting.ActionContent>
</controls:Setting>
<controls:Setting x:Uid="FileExplorerPreview_ToggleSwitch_PDF_Thumbnail" Icon="&#xEA90;">
<controls:Setting.ActionContent>
<ToggleSwitch IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.PDFThumbnailIsEnabled}"
IsEnabled="{Binding Mode=OneWay, Path=IsElevated}"/>
</controls:Setting.ActionContent>
</controls:Setting>
</controls:SettingsGroup>
</StackPanel>