[FileExplorer] StlThumbnailProvider (#15568)

* Adds StlThumbnailProvider

* Spell checker fixes

* Adds missing changes

* Attempts to fix alpha background issue

* Adds missing dependency references

* Upgrades .NET Core 3.1 to .NET 5

* Updates Helix Toolkit to fix .net5 compatibility

* Return null bitmap If STL model is empty
This commit is contained in:
Pedro Lamas
2022-01-25 11:51:37 +00:00
committed by GitHub
parent edc43e39ca
commit cccadec44c
22 changed files with 530 additions and 2 deletions

View File

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

View File

@@ -53,6 +53,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
_gcodeRenderIsEnabled = Settings.Properties.EnableGcodePreview;
_pdfThumbnailIsEnabled = Settings.Properties.EnablePdfThumbnail;
_gcodeThumbnailIsEnabled = Settings.Properties.EnableGcodeThumbnail;
_stlThumbnailIsEnabled = Settings.Properties.EnableStlThumbnail;
}
private bool _svgRenderIsEnabled;
@@ -62,6 +63,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
private bool _svgThumbnailIsEnabled;
private bool _pdfThumbnailIsEnabled;
private bool _gcodeThumbnailIsEnabled;
private bool _stlThumbnailIsEnabled;
public bool SVGRenderIsEnabled
{
@@ -189,6 +191,24 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
}
}
public bool STLThumbnailIsEnabled
{
get
{
return _stlThumbnailIsEnabled;
}
set
{
if (value != _stlThumbnailIsEnabled)
{
_stlThumbnailIsEnabled = value;
Settings.Properties.EnableStlThumbnail = value;
RaisePropertyChanged();
}
}
}
public string GetSettingsSubPath()
{
return _settingsConfigFileFolder + "\\" + ModuleName;

View File

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

View File

@@ -632,6 +632,10 @@
<value>Enable SVG (.svg) thumbnails</value>
<comment>Do you want this feature on / off</comment>
</data>
<data name="FileExplorerPreview_ToggleSwitch_STL_Thumbnail.Header" xml:space="preserve">
<value>Enable STL (.stl) 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>

View File

@@ -77,6 +77,13 @@
x:Uid="ToggleSwitch"/>
</controls:Setting.ActionContent>
</controls:Setting>
<controls:Setting x:Uid="FileExplorerPreview_ToggleSwitch_STL_Thumbnail" Icon="&#xF158;">
<controls:Setting.ActionContent>
<ToggleSwitch IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.STLThumbnailIsEnabled}"
x:Uid="ToggleSwitch"/>
</controls:Setting.ActionContent>
</controls:Setting>
</controls:SettingsGroup>
</StackPanel>