mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
SvgPreviewControl: Add Background so that white .svg are visible (#25397)
* SvgPreviewControl: Add checkered background so that white .svg are visible * SvgPreviewControl: Move preview generation logic into own class * SvgPreviewControl: Add possibility to configure background of svg preview pane via the settings ui * SvgPreviewControl: Take user configuration into consideration when generating svg preview * SvgPreviewControl: Do not generate preview file, if the actual size is under the 2mb limiation of WebView2 * SvgPreviewControl: Introduce SvgPreviewColorMode enumeration instead of using magic values * SvgPreviewControl: Add additional checkered pattern shades * SvgPreviewControl: Use newly introduced enums as default values
This commit is contained in:
@@ -762,6 +762,33 @@
|
||||
<value>.svg</value>
|
||||
<comment>File extension, should not be altered</comment>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_Preview_SVG_Color_Mode.Header" xml:space="preserve">
|
||||
<value>Color mode</value>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_Preview_SVG_Color_Mode_Default.Content" xml:space="preserve">
|
||||
<value>Windows default</value>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_Preview_SVG_Color_Solid_Color.Content" xml:space="preserve">
|
||||
<value>Solid color</value>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_Preview_SVG_Checkered_Shade.Content" xml:space="preserve">
|
||||
<value>Checkered pattern</value>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_Preview_SVG_Background_Color.Header" xml:space="preserve">
|
||||
<value>Color</value>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_Preview_SVG_Checkered_Shade_Mode.Header" xml:space="preserve">
|
||||
<value>Checkered shade</value>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_Preview_SVG_Checkered_Shade_1.Content" xml:space="preserve">
|
||||
<value>Light</value>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_Preview_SVG_Checkered_Shade_2.Content" xml:space="preserve">
|
||||
<value>Medium</value>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_Preview_SVG_Checkered_Shade_3.Content" xml:space="preserve">
|
||||
<value>Dark</value>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_ToggleSwitch_Preview_PDF.Header" xml:space="preserve">
|
||||
<value>Portable Document Format</value>
|
||||
<comment>File type, do not translate</comment>
|
||||
|
||||
@@ -8,6 +8,7 @@ using global::PowerToys.GPOWrapper;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Settings.UI.Library.Enumerations;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
@@ -60,6 +61,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
_svgRenderIsEnabled = Settings.Properties.EnableSvgPreview;
|
||||
}
|
||||
|
||||
_svgBackgroundColorMode = Settings.Properties.SvgBackgroundColorMode.Value;
|
||||
_svgBackgroundSolidColor = Settings.Properties.SvgBackgroundSolidColor.Value;
|
||||
_svgBackgroundCheckeredShade = Settings.Properties.SvgBackgroundCheckeredShade.Value;
|
||||
|
||||
_svgThumbnailEnabledGpoRuleConfiguration = GPOWrapper.GetConfiguredSvgThumbnailsEnabledValue();
|
||||
if (_svgThumbnailEnabledGpoRuleConfiguration == GpoRuleConfigured.Disabled || _svgThumbnailEnabledGpoRuleConfiguration == GpoRuleConfigured.Enabled)
|
||||
{
|
||||
@@ -166,6 +171,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
private GpoRuleConfigured _svgRenderEnabledGpoRuleConfiguration;
|
||||
private bool _svgRenderEnabledStateIsGPOConfigured;
|
||||
private bool _svgRenderIsEnabled;
|
||||
private int _svgBackgroundColorMode;
|
||||
private string _svgBackgroundSolidColor;
|
||||
private int _svgBackgroundCheckeredShade;
|
||||
|
||||
private GpoRuleConfigured _mdRenderEnabledGpoRuleConfiguration;
|
||||
private bool _mdRenderEnabledStateIsGPOConfigured;
|
||||
@@ -227,6 +235,78 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public int SVGRenderBackgroundColorMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _svgBackgroundColorMode;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _svgBackgroundColorMode)
|
||||
{
|
||||
_svgBackgroundColorMode = value;
|
||||
Settings.Properties.SvgBackgroundColorMode.Value = value;
|
||||
RaisePropertyChanged();
|
||||
RaisePropertyChanged(nameof(IsSvgBackgroundColorVisible));
|
||||
RaisePropertyChanged(nameof(IsSvgCheckeredShadeVisible));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSvgBackgroundColorVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return (SvgPreviewColorMode)SVGRenderBackgroundColorMode == SvgPreviewColorMode.SolidColor;
|
||||
}
|
||||
}
|
||||
|
||||
public string SVGRenderBackgroundSolidColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _svgBackgroundSolidColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _svgBackgroundSolidColor)
|
||||
{
|
||||
_svgBackgroundSolidColor = value;
|
||||
Settings.Properties.SvgBackgroundSolidColor = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSvgCheckeredShadeVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return (SvgPreviewColorMode)SVGRenderBackgroundColorMode == SvgPreviewColorMode.Checkered;
|
||||
}
|
||||
}
|
||||
|
||||
public int SVGRenderBackgroundCheckeredShade
|
||||
{
|
||||
get
|
||||
{
|
||||
return _svgBackgroundCheckeredShade;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _svgBackgroundCheckeredShade)
|
||||
{
|
||||
_svgBackgroundCheckeredShade = value;
|
||||
Settings.Properties.SvgBackgroundCheckeredShade.Value = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSVGRenderEnabledGpoConfigured
|
||||
{
|
||||
get => _svgRenderEnabledStateIsGPOConfigured;
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
IsOn="{x:Bind IsShown, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
OffContent=""
|
||||
OnContent="" />
|
||||
|
||||
|
||||
<Button
|
||||
x:Uid="More_Options_Button"
|
||||
Grid.Column="1"
|
||||
|
||||
@@ -22,14 +22,39 @@
|
||||
IsOpen="True"
|
||||
IsTabStop="True"
|
||||
Severity="Warning" />
|
||||
<labs:SettingsCard
|
||||
<labs:SettingsExpander
|
||||
x:Uid="FileExplorerPreview_ToggleSwitch_Preview_SVG"
|
||||
HeaderIcon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=}"
|
||||
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsSVGRenderEnabledGpoConfigured, Converter={StaticResource BoolNegationConverter}}">
|
||||
<ToggleSwitch
|
||||
x:Uid="ToggleSwitch"
|
||||
IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.SVGRenderIsEnabled}" />
|
||||
</labs:SettingsCard>
|
||||
<labs:SettingsExpander.Items>
|
||||
<labs:SettingsCard x:Uid="FileExplorerPreview_Preview_SVG_Color_Mode">
|
||||
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind Path=ViewModel.SVGRenderBackgroundColorMode, Mode=TwoWay}"
|
||||
IsEnabled="{x:Bind ViewModel.SVGRenderIsEnabled, Mode=OneWay}">
|
||||
<ComboBoxItem x:Uid="FileExplorerPreview_Preview_SVG_Color_Mode_Default" />
|
||||
<ComboBoxItem x:Uid="FileExplorerPreview_Preview_SVG_Color_Solid_Color" />
|
||||
<ComboBoxItem x:Uid="FileExplorerPreview_Preview_SVG_Checkered_Shade" />
|
||||
</ComboBox>
|
||||
</labs:SettingsCard>
|
||||
<labs:SettingsCard x:Uid="FileExplorerPreview_Preview_SVG_Background_Color"
|
||||
Visibility="{x:Bind ViewModel.IsSvgBackgroundColorVisible, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}">
|
||||
<controls:ColorPickerButton
|
||||
IsEnabled="{x:Bind ViewModel.SVGRenderIsEnabled, Mode=OneWay}"
|
||||
SelectedColor="{x:Bind Path=ViewModel.SVGRenderBackgroundSolidColor, Mode=TwoWay}" />
|
||||
</labs:SettingsCard>
|
||||
<labs:SettingsCard x:Uid="FileExplorerPreview_Preview_SVG_Checkered_Shade_Mode"
|
||||
Visibility="{x:Bind ViewModel.IsSvgCheckeredShadeVisible, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}">
|
||||
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind Path=ViewModel.SVGRenderBackgroundCheckeredShade, Mode=TwoWay}"
|
||||
IsEnabled="{x:Bind ViewModel.SVGRenderIsEnabled, Mode=OneWay}">
|
||||
<ComboBoxItem x:Uid="FileExplorerPreview_Preview_SVG_Checkered_Shade_1" />
|
||||
<ComboBoxItem x:Uid="FileExplorerPreview_Preview_SVG_Checkered_Shade_2" />
|
||||
<ComboBoxItem x:Uid="FileExplorerPreview_Preview_SVG_Checkered_Shade_3" />
|
||||
</ComboBox>
|
||||
</labs:SettingsCard>
|
||||
</labs:SettingsExpander.Items>
|
||||
</labs:SettingsExpander>
|
||||
|
||||
<InfoBar
|
||||
x:Uid="GPO_IsSettingForced"
|
||||
|
||||
Reference in New Issue
Block a user