mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-30 22:15:11 +00:00
[FileExplorer]Stl Thumbnails color customization (#19928)
This commit is contained in:
@@ -11,6 +11,7 @@ using System.Windows.Media.Media3D;
|
|||||||
using Common.ComInterlop;
|
using Common.ComInterlop;
|
||||||
using Common.Utilities;
|
using Common.Utilities;
|
||||||
using HelixToolkit.Wpf;
|
using HelixToolkit.Wpf;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
using Bitmap = System.Drawing.Bitmap;
|
using Bitmap = System.Drawing.Bitmap;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.ThumbnailHandler.Stl
|
namespace Microsoft.PowerToys.ThumbnailHandler.Stl
|
||||||
@@ -50,7 +51,7 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Stl
|
|||||||
|
|
||||||
var stlReader = new StLReader
|
var stlReader = new StLReader
|
||||||
{
|
{
|
||||||
DefaultMaterial = new DiffuseMaterial(new SolidColorBrush(Color.FromRgb(255, 201, 36))),
|
DefaultMaterial = new DiffuseMaterial(new SolidColorBrush(DefaultMaterialColor)),
|
||||||
};
|
};
|
||||||
|
|
||||||
var model = stlReader.Read(stream);
|
var model = stlReader.Read(stream);
|
||||||
@@ -141,5 +142,29 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Stl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating what color to use.
|
||||||
|
/// </summary>
|
||||||
|
public static Color DefaultMaterialColor
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var moduleSettings = new SettingsUtils();
|
||||||
|
|
||||||
|
var colorString = moduleSettings.GetSettings<PowerPreviewSettings>(PowerPreviewSettings.ModuleName).Properties.StlThumbnailColor.Value;
|
||||||
|
|
||||||
|
return (Color)ColorConverter.ConvertFromString(colorString);
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException)
|
||||||
|
{
|
||||||
|
// Couldn't read the settings.
|
||||||
|
// Assume default color value.
|
||||||
|
return Color.FromRgb(255, 201, 36);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,5 +26,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
|
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
|
||||||
<ProjectReference Include="..\Common\PreviewHandlerCommon.csproj" />
|
<ProjectReference Include="..\Common\PreviewHandlerCommon.csproj" />
|
||||||
|
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@@ -12,6 +12,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
|||||||
{
|
{
|
||||||
public class PowerPreviewProperties
|
public class PowerPreviewProperties
|
||||||
{
|
{
|
||||||
|
public const string DefaultStlThumbnailColor = "#FFC924";
|
||||||
|
|
||||||
private bool enableSvgPreview = true;
|
private bool enableSvgPreview = true;
|
||||||
|
|
||||||
[JsonPropertyName("svg-previewer-toggle-setting")]
|
[JsonPropertyName("svg-previewer-toggle-setting")]
|
||||||
@@ -182,8 +184,12 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonPropertyName("stl-thumbnail-color-setting")]
|
||||||
|
public StringProperty StlThumbnailColor { get; set; }
|
||||||
|
|
||||||
public PowerPreviewProperties()
|
public PowerPreviewProperties()
|
||||||
{
|
{
|
||||||
|
StlThumbnailColor = new StringProperty(DefaultStlThumbnailColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
@@ -56,6 +56,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
|||||||
_pdfThumbnailIsEnabled = Settings.Properties.EnablePdfThumbnail;
|
_pdfThumbnailIsEnabled = Settings.Properties.EnablePdfThumbnail;
|
||||||
_gcodeThumbnailIsEnabled = Settings.Properties.EnableGcodeThumbnail;
|
_gcodeThumbnailIsEnabled = Settings.Properties.EnableGcodeThumbnail;
|
||||||
_stlThumbnailIsEnabled = Settings.Properties.EnableStlThumbnail;
|
_stlThumbnailIsEnabled = Settings.Properties.EnableStlThumbnail;
|
||||||
|
_stlThumbnailColor = Settings.Properties.StlThumbnailColor.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _svgRenderIsEnabled;
|
private bool _svgRenderIsEnabled;
|
||||||
@@ -68,6 +69,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
|||||||
private bool _pdfThumbnailIsEnabled;
|
private bool _pdfThumbnailIsEnabled;
|
||||||
private bool _gcodeThumbnailIsEnabled;
|
private bool _gcodeThumbnailIsEnabled;
|
||||||
private bool _stlThumbnailIsEnabled;
|
private bool _stlThumbnailIsEnabled;
|
||||||
|
private string _stlThumbnailColor;
|
||||||
|
|
||||||
public bool SVGRenderIsEnabled
|
public bool SVGRenderIsEnabled
|
||||||
{
|
{
|
||||||
@@ -249,6 +251,24 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string STLThumbnailColor
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _stlThumbnailColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value != _stlThumbnailColor)
|
||||||
|
{
|
||||||
|
_stlThumbnailColor = value;
|
||||||
|
Settings.Properties.StlThumbnailColor.Value = value;
|
||||||
|
RaisePropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string GetSettingsSubPath()
|
public string GetSettingsSubPath()
|
||||||
{
|
{
|
||||||
return _settingsConfigFileFolder + "\\" + ModuleName;
|
return _settingsConfigFileFolder + "\\" + ModuleName;
|
||||||
|
@@ -684,6 +684,9 @@
|
|||||||
<value>.stl</value>
|
<value>.stl</value>
|
||||||
<comment>File extension, should not be altered</comment>
|
<comment>File extension, should not be altered</comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="FileExplorerPreview_Color_Thumbnail_STL.Header" xml:space="preserve">
|
||||||
|
<value>Color</value>
|
||||||
|
</data>
|
||||||
<data name="FileExplorerPreview_ToggleSwitch_Thumbnail_PDF.Header" xml:space="preserve">
|
<data name="FileExplorerPreview_ToggleSwitch_Thumbnail_PDF.Header" xml:space="preserve">
|
||||||
<value>Portable Document Format</value>
|
<value>Portable Document Format</value>
|
||||||
<comment>File type, do not translate</comment>
|
<comment>File type, do not translate</comment>
|
||||||
|
@@ -110,14 +110,29 @@
|
|||||||
</controls:Setting.ActionContent>
|
</controls:Setting.ActionContent>
|
||||||
</controls:Setting>
|
</controls:Setting>
|
||||||
|
|
||||||
<controls:Setting x:Uid="FileExplorerPreview_ToggleSwitch_Thumbnail_STL" Icon="">
|
<controls:SettingExpander IsExpanded="False">
|
||||||
<controls:Setting.ActionContent>
|
<controls:SettingExpander.Header>
|
||||||
<ToggleSwitch IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.STLThumbnailIsEnabled}"
|
<controls:Setting x:Uid="FileExplorerPreview_ToggleSwitch_Thumbnail_STL" Icon="">
|
||||||
x:Uid="ToggleSwitch"/>
|
<controls:Setting.ActionContent>
|
||||||
</controls:Setting.ActionContent>
|
<ToggleSwitch IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.STLThumbnailIsEnabled}"
|
||||||
</controls:Setting>
|
x:Uid="ToggleSwitch"/>
|
||||||
|
</controls:Setting.ActionContent>
|
||||||
|
</controls:Setting>
|
||||||
|
</controls:SettingExpander.Header>
|
||||||
|
|
||||||
|
<controls:SettingExpander.Content>
|
||||||
|
<StackPanel>
|
||||||
|
<controls:Setting x:Uid="FileExplorerPreview_Color_Thumbnail_STL" Style="{StaticResource ExpanderContentSettingStyle}">
|
||||||
|
<controls:Setting.ActionContent>
|
||||||
|
<controls:ColorPickerButton SelectedColor="{x:Bind Path=ViewModel.STLThumbnailColor, Mode=TwoWay}"
|
||||||
|
IsEnabled="{x:Bind ViewModel.STLThumbnailIsEnabled, Mode=OneWay}"/>
|
||||||
|
</controls:Setting.ActionContent>
|
||||||
|
</controls:Setting>
|
||||||
|
</StackPanel>
|
||||||
|
</controls:SettingExpander.Content>
|
||||||
|
</controls:SettingExpander>
|
||||||
</controls:SettingsGroup>
|
</controls:SettingsGroup>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</controls:SettingsPageControl.ModuleContent>
|
</controls:SettingsPageControl.ModuleContent>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user