Enable PDF files in preview pane (#9088)

## Summary of the Pull Request
This PR enables user to preview PDF files in the Explorer preview pane
and in Outlook. 

**What is this about:**
Windows does not support out of the box experience for previewing PDF
files in the preview pane. Users need to install third-party software
like Adobe Acrobat reader. The PdfPreviewHandler module enbales the user
to preview PDF files.

**How does someone test / validate:** 
Run the installer, open Explorer and select a PDF file, enable the
preview pane. Maybe need to remove third-party PDF software.

## Quality Checklist

- [X] **Linked issue:** #3548
- [ ] **Communication:** I've discussed this with core contributors in the issue. 
- [X] **Tests:** Added/updated and all pass
- [X] **Installer:** Added/updated and all pass
- [X] **Localization:** All end user facing strings can be localized
- [ ] **Docs:** Added/ updated
- [x] **Binaries:** Any new files are added to WXS / YML
   - [ ] No new binaries
   - [x] YML for signing
   - [x] WXS for installer
This commit is contained in:
R. de Veen
2021-08-26 23:43:26 +02:00
committed by GitHub
parent da46b90457
commit 4177708e49
34 changed files with 1073 additions and 14 deletions

View File

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

View File

@@ -49,10 +49,12 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
_svgRenderIsEnabled = Settings.Properties.EnableSvgPreview;
_svgThumbnailIsEnabled = Settings.Properties.EnableSvgThumbnail;
_mdRenderIsEnabled = Settings.Properties.EnableMdPreview;
_pdfRenderIsEnabled = Settings.Properties.EnablePdfPreview;
}
private bool _svgRenderIsEnabled;
private bool _mdRenderIsEnabled;
private bool _pdfRenderIsEnabled;
private bool _svgThumbnailIsEnabled;
public bool SVGRenderIsEnabled
@@ -109,6 +111,24 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
}
}
public bool PDFRenderIsEnabled
{
get
{
return _pdfRenderIsEnabled;
}
set
{
if (value != _pdfRenderIsEnabled)
{
_pdfRenderIsEnabled = value;
Settings.Properties.EnablePdfPreview = value;
RaisePropertyChanged();
}
}
}
public string GetSettingsSubPath()
{
return _settingsConfigFileFolder + "\\" + ModuleName;

View File

@@ -57,6 +57,7 @@ namespace ViewModelTests
// Verify that the old settings persisted
Assert.AreEqual(originalGeneralSettings.IsElevated, viewModel.IsElevated);
Assert.AreEqual(originalSettings.Properties.EnableMdPreview, viewModel.MDRenderIsEnabled);
Assert.AreEqual(originalSettings.Properties.EnablePdfPreview, viewModel.PDFRenderIsEnabled);
Assert.AreEqual(originalSettings.Properties.EnableSvgPreview, viewModel.SVGRenderIsEnabled);
Assert.AreEqual(originalSettings.Properties.EnableSvgThumbnail, viewModel.SVGThumbnailIsEnabled);
@@ -118,5 +119,23 @@ namespace ViewModelTests
// act
viewModel.MDRenderIsEnabled = true;
}
[TestMethod]
public void PDFRenderIsEnabledShouldPrevHandlerWhenSuccessful()
{
// Assert
Func<string, int> sendMockIPCConfigMSG = msg =>
{
SndModuleSettings<SndPowerPreviewSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<SndPowerPreviewSettings>>(msg);
Assert.IsTrue(snd.PowertoysSetting.FileExplorerPreviewSettings.Properties.EnablePdfPreview);
return 0;
};
// arrange
PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository<PowerPreviewSettings>.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, PowerPreviewSettings.ModuleName);
// act
viewModel.PDFRenderIsEnabled = true;
}
}
}

View File

@@ -58,7 +58,6 @@
Foreground="{ThemeResource CardPrimaryForegroundBrush}"
VerticalAlignment="Center"/>
<StackPanel
VerticalAlignment="Center"
Grid.Column="1"

View File

@@ -581,6 +581,10 @@
<value>Enable SVG (.svg) preview</value>
<comment>Do you want this feature on / off</comment>
</data>
<data name="FileExplorerPreview_ToggleSwitch_Preview_PDF.Header" xml:space="preserve">
<value>Enable PDF (.pdf) preview</value>
<comment>Do you want this feature on / off</comment>
</data>
<data name="FileExplorerPreview_ToggleSwitch_SVG_Thumbnail.Header" xml:space="preserve">
<value>Enable SVG (.svg) thumbnails</value>
<comment>Do you want this feature on / off</comment>

View File

@@ -18,7 +18,6 @@
ModuleImageSource="ms-appx:///Assets/Modules/PowerPreview.png">
<controls:SettingsPageControl.ModuleContent>
<StackPanel Orientation="Vertical">
<muxc:InfoBar Severity="Warning"
@@ -47,10 +46,16 @@
IsEnabled="{Binding Mode=OneWay, Path=IsElevated}"/>
</controls:Setting.ActionContent>
</controls:Setting>
<controls:Setting x:Uid="FileExplorerPreview_ToggleSwitch_Preview_PDF" Icon="&#xEA90;">
<controls:Setting.ActionContent>
<ToggleSwitch IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.PDFRenderIsEnabled}"
IsEnabled="{Binding Mode=OneWay, Path=IsElevated}"/>
</controls:Setting.ActionContent>
</controls:Setting>
</controls:SettingsGroup>
<controls:SettingsGroup x:Uid="FileExplorerPreview_IconThumbnail_GroupSettings">
<muxc:InfoBar Severity="Informational"
x:Uid="FileExplorerPreview_RebootRequired"
IsOpen="True"
@@ -62,9 +67,8 @@
IsEnabled="{Binding Mode=OneWay, Path=IsElevated}"/>
</controls:Setting.ActionContent>
</controls:Setting>
</controls:SettingsGroup>
</StackPanel>
</controls:SettingsPageControl.ModuleContent>