mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[FileExplorer]GcodeThumbnailProvider and GcodePreviewHandler (#14827)
* Adds the GcodeThumbnailProvider * Registers the GcodeThumbnailProvider * Adds Settings support * Reverts solution changes back to original * Corrects "Gcode" text with "G-code" * Adds gcode thumbnail setting description * Follow up on PR review comments * Adds GcodePreviewHandler * Follow up on PR review comments * Renames assemblies following #14903
This commit is contained in:
@@ -97,6 +97,40 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
}
|
||||
}
|
||||
|
||||
private bool enableGcodePreview = true;
|
||||
|
||||
[JsonPropertyName("gcode-previewer-toggle-setting")]
|
||||
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
||||
public bool EnableGcodePreview
|
||||
{
|
||||
get => enableGcodePreview;
|
||||
set
|
||||
{
|
||||
if (value != enableGcodePreview)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
enableGcodePreview = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool enableGcodeThumbnail = true;
|
||||
|
||||
[JsonPropertyName("gcode-thumbnail-toggle-setting")]
|
||||
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
||||
public bool EnableGcodeThumbnail
|
||||
{
|
||||
get => enableGcodeThumbnail;
|
||||
set
|
||||
{
|
||||
if (value != enableGcodeThumbnail)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
enableGcodeThumbnail = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PowerPreviewProperties()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -50,14 +50,18 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
_svgThumbnailIsEnabled = Settings.Properties.EnableSvgThumbnail;
|
||||
_mdRenderIsEnabled = Settings.Properties.EnableMdPreview;
|
||||
_pdfRenderIsEnabled = Settings.Properties.EnablePdfPreview;
|
||||
_gcodeRenderIsEnabled = Settings.Properties.EnableGcodePreview;
|
||||
_pdfThumbnailIsEnabled = Settings.Properties.EnablePdfThumbnail;
|
||||
_gcodeThumbnailIsEnabled = Settings.Properties.EnableGcodeThumbnail;
|
||||
}
|
||||
|
||||
private bool _svgRenderIsEnabled;
|
||||
private bool _mdRenderIsEnabled;
|
||||
private bool _pdfRenderIsEnabled;
|
||||
private bool _gcodeRenderIsEnabled;
|
||||
private bool _svgThumbnailIsEnabled;
|
||||
private bool _pdfThumbnailIsEnabled;
|
||||
private bool _gcodeThumbnailIsEnabled;
|
||||
|
||||
public bool SVGRenderIsEnabled
|
||||
{
|
||||
@@ -149,6 +153,42 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool GCODERenderIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _gcodeRenderIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _gcodeRenderIsEnabled)
|
||||
{
|
||||
_gcodeRenderIsEnabled = value;
|
||||
Settings.Properties.EnableGcodePreview = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool GCODEThumbnailIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _gcodeThumbnailIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _gcodeThumbnailIsEnabled)
|
||||
{
|
||||
_gcodeThumbnailIsEnabled = value;
|
||||
Settings.Properties.EnableGcodeThumbnail = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSettingsSubPath()
|
||||
{
|
||||
return _settingsConfigFileFolder + "\\" + ModuleName;
|
||||
|
||||
@@ -58,9 +58,11 @@ namespace ViewModelTests
|
||||
Assert.AreEqual(originalGeneralSettings.IsElevated, viewModel.IsElevated);
|
||||
Assert.AreEqual(originalSettings.Properties.EnableMdPreview, viewModel.MDRenderIsEnabled);
|
||||
Assert.AreEqual(originalSettings.Properties.EnablePdfPreview, viewModel.PDFRenderIsEnabled);
|
||||
Assert.AreEqual(originalSettings.Properties.EnableGcodePreview, viewModel.GCODERenderIsEnabled);
|
||||
Assert.AreEqual(originalSettings.Properties.EnableSvgPreview, viewModel.SVGRenderIsEnabled);
|
||||
Assert.AreEqual(originalSettings.Properties.EnableSvgThumbnail, viewModel.SVGThumbnailIsEnabled);
|
||||
Assert.AreEqual(originalSettings.Properties.EnablePdfThumbnail, viewModel.PDFThumbnailIsEnabled);
|
||||
Assert.AreEqual(originalSettings.Properties.EnableGcodeThumbnail, viewModel.GCODEThumbnailIsEnabled);
|
||||
|
||||
// Verify that the stub file was used
|
||||
var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings<T>)
|
||||
@@ -121,6 +123,24 @@ namespace ViewModelTests
|
||||
viewModel.PDFThumbnailIsEnabled = true;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GCODEThumbnailIsEnabledShouldPrevHandlerWhenSuccessful()
|
||||
{
|
||||
// Assert
|
||||
Func<string, int> sendMockIPCConfigMSG = msg =>
|
||||
{
|
||||
SndModuleSettings<SndPowerPreviewSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<SndPowerPreviewSettings>>(msg);
|
||||
Assert.IsTrue(snd.PowertoysSetting.FileExplorerPreviewSettings.Properties.EnableGcodeThumbnail);
|
||||
return 0;
|
||||
};
|
||||
|
||||
// arrange
|
||||
PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository<PowerPreviewSettings>.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, PowerPreviewSettings.ModuleName);
|
||||
|
||||
// act
|
||||
viewModel.GCODEThumbnailIsEnabled = true;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MDRenderIsEnabledShouldPrevHandlerWhenSuccessful()
|
||||
{
|
||||
@@ -156,5 +176,23 @@ namespace ViewModelTests
|
||||
// act
|
||||
viewModel.PDFRenderIsEnabled = true;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GCODERenderIsEnabledShouldPrevHandlerWhenSuccessful()
|
||||
{
|
||||
// Assert
|
||||
Func<string, int> sendMockIPCConfigMSG = msg =>
|
||||
{
|
||||
SndModuleSettings<SndPowerPreviewSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<SndPowerPreviewSettings>>(msg);
|
||||
Assert.IsTrue(snd.PowertoysSetting.FileExplorerPreviewSettings.Properties.EnableGcodePreview);
|
||||
return 0;
|
||||
};
|
||||
|
||||
// arrange
|
||||
PowerPreviewViewModel viewModel = new PowerPreviewViewModel(SettingsRepository<PowerPreviewSettings>.GetInstance(mockPowerPreviewSettingsUtils.Object), SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, PowerPreviewSettings.ModuleName);
|
||||
|
||||
// act
|
||||
viewModel.GCODERenderIsEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1544,7 +1544,7 @@ From there, simply click on a Markdown file, PDF file or SVG icon in the File Ex
|
||||
<data name="EditButton.AutomationProperties.Name" xml:space="preserve">
|
||||
<value>Edit</value>
|
||||
</data>
|
||||
<data name="ImageResizer_EditSize.AutomationProperties.Name" xml:space="preserve">
|
||||
<data name="ImageResizer_EditSize.AutomationProperties.Name" xml:space="preserve">
|
||||
<value>Edit size</value>
|
||||
</data>
|
||||
<data name="No" xml:space="preserve">
|
||||
@@ -1828,4 +1828,18 @@ From there, simply click on a Markdown file, PDF file or SVG icon in the File Ex
|
||||
<data name="VideoConference_RunAsAdminRequired.Title" xml:space="preserve">
|
||||
<value>You need to run as administrator to modify these settings.</value>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_ToggleSwitch_GCODE_Thumbnail.Header" xml:space="preserve">
|
||||
<value>Enable G-code (.gcode) thumbnails</value>
|
||||
<comment>Do you want this feature on / off</comment>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_ToggleSwitch_GCODE_Thumbnail.Description" xml:space="preserve">
|
||||
<value>Only .gcode files with embedded thumbnails are supported</value>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_ToggleSwitch_Preview_GCODE.Description" xml:space="preserve">
|
||||
<value>Only .gcode files with embedded thumbnails are supported</value>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_ToggleSwitch_Preview_GCODE.Header" xml:space="preserve">
|
||||
<value>Enable G-code (.gcode) preview</value>
|
||||
<comment>Do you want this feature on / off</comment>
|
||||
</data>
|
||||
</root>
|
||||
@@ -55,6 +55,13 @@
|
||||
IsEnabled="{Binding Mode=OneWay, Path=IsElevated}"/>
|
||||
</controls:Setting.ActionContent>
|
||||
</controls:Setting>
|
||||
|
||||
<controls:Setting x:Uid="FileExplorerPreview_ToggleSwitch_Preview_GCODE" Icon="">
|
||||
<controls:Setting.ActionContent>
|
||||
<ToggleSwitch IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.GCODERenderIsEnabled}"
|
||||
IsEnabled="{Binding Mode=OneWay, Path=IsElevated}"/>
|
||||
</controls:Setting.ActionContent>
|
||||
</controls:Setting>
|
||||
</controls:SettingsGroup>
|
||||
|
||||
<controls:SettingsGroup x:Uid="FileExplorerPreview_IconThumbnail_GroupSettings">
|
||||
@@ -77,6 +84,13 @@
|
||||
IsEnabled="{Binding Mode=OneWay, Path=IsElevated}"/>
|
||||
</controls:Setting.ActionContent>
|
||||
</controls:Setting>
|
||||
|
||||
<controls:Setting x:Uid="FileExplorerPreview_ToggleSwitch_GCODE_Thumbnail" Icon="">
|
||||
<controls:Setting.ActionContent>
|
||||
<ToggleSwitch IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.GCODEThumbnailIsEnabled}"
|
||||
IsEnabled="{Binding Mode=OneWay, Path=IsElevated}"/>
|
||||
</controls:Setting.ActionContent>
|
||||
</controls:Setting>
|
||||
</controls:SettingsGroup>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
Reference in New Issue
Block a user