[Dev file previewer]Add option to set custom max file size and fix styling issue (#23689)

* [Dev file previewer] Add option to set costum max file size and fix style issue
This commit is contained in:
Aaron Junker 2023-02-13 19:57:33 +01:00 committed by GitHub
parent bc4bde8cee
commit 00e10d38c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 4 deletions

View File

@ -212,6 +212,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
downloadLink.Top = TextRenderer.MeasureText(Resources.WebView2_Not_Installed_Message, errorMessage.Font).Height + 10;
downloadLink.Width = TextRenderer.MeasureText(Resources.Download_WebView2, errorMessage.Font).Width + 10;
downloadLink.Height = TextRenderer.MeasureText(Resources.Download_WebView2, errorMessage.Font).Height;
downloadLink.ForeColor = Settings.TextColor;
Controls.Add(downloadLink);
}
});
@ -222,6 +223,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
Controls.Remove(_loadingBar);
Controls.Remove(_loadingBackground);
Label text = new Label();
text.ForeColor = Settings.TextColor;
text.Text = Resources.Exception_Occurred;
text.Text += e.Message;
text.Text += "\n" + e.Source;
@ -244,6 +246,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
Controls.Remove(_loadingBackground);
Label errorMessage = new Label();
errorMessage.Text = Resources.Max_File_Size_Error.Replace("%1", (_settings.MaxFileSize / 1000).ToString(CultureInfo.CurrentCulture), StringComparison.InvariantCulture);
errorMessage.ForeColor = Settings.TextColor;
errorMessage.Width = 500;
errorMessage.Height = 50;
Controls.Add(errorMessage);

View File

@ -58,11 +58,24 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
}
/// <summary>
/// Max file size for displaying (in bytes).
/// Gets Max file size for displaying (in bytes).
/// </summary>
private readonly long _maxFileSize = 50000;
public long MaxFileSize => _maxFileSize;
public double MaxFileSize
{
get
{
try
{
return moduleSettings.GetSettings<PowerPreviewSettings>(PowerPreviewSettings.ModuleName).Properties.MonacoPreviewMaxFileSize.Value * 1000;
}
catch (FileNotFoundException)
{
// Couldn't read the settings.
// Assume default of 50000.
return 50000;
}
}
}
/// <summary>
/// Gets the color of the window background.

View File

@ -13,6 +13,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public class PowerPreviewProperties
{
public const string DefaultStlThumbnailColor = "#FFC924";
public const int DefaultMonacoMaxFileSize = 50;
private bool enableSvgPreview = true;
@ -116,6 +117,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
}
}
[JsonPropertyName("monaco-previewer-max-file-size")]
public IntProperty MonacoPreviewMaxFileSize { get; set; }
private bool enablePdfPreview;
[JsonPropertyName("pdf-previewer-toggle-setting")]
@ -207,6 +211,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public PowerPreviewProperties()
{
StlThumbnailColor = new StringProperty(DefaultStlThumbnailColor);
MonacoPreviewMaxFileSize = new IntProperty(DefaultMonacoMaxFileSize);
}
public override string ToString()

View File

@ -2934,4 +2934,12 @@ Activate by holding the key for the character you want to add an accent to, then
<data name="UpdateAvailable.Title" xml:space="preserve">
<value>Update available</value>
</data>
<data name="FileExplorerPreview_Toggle_Monaco_Max_File_Size.Header" xml:space="preserve">
<value>Maximum file size to preview</value>
<comment>Size refers to the disk space used by a file</comment>
</data>
<data name="FileExplorerPreview_Toggle_Monaco_Max_File_Size.Description" xml:space="preserve">
<value>The maximum size, in kilobytes, for files to be displayed. This is a safety mechanism to prevent loading large files into RAM.</value>
<comment>"RAM" refers to random access memory; "size" refers to disk space; "bytes" refer to the measurement unit</comment>
</data>
</root>

View File

@ -98,6 +98,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
_monacoWrapText = Settings.Properties.EnableMonacoPreviewWordWrap;
_monacoPreviewTryFormat = Settings.Properties.MonacoPreviewTryFormat;
_monacoMaxFileSize = Settings.Properties.MonacoPreviewMaxFileSize.Value;
_pdfRenderEnabledGpoRuleConfiguration = GPOWrapper.GetConfiguredPdfPreviewEnabledValue();
if (_pdfRenderEnabledGpoRuleConfiguration == GpoRuleConfigured.Disabled || _pdfRenderEnabledGpoRuleConfiguration == GpoRuleConfigured.Enabled)
@ -175,6 +176,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private bool _monacoRenderIsEnabled;
private bool _monacoWrapText;
private bool _monacoPreviewTryFormat;
private int _monacoMaxFileSize;
private GpoRuleConfigured _pdfRenderEnabledGpoRuleConfiguration;
private bool _pdfRenderEnabledStateIsGPOConfigured;
@ -353,6 +355,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public int MonacoPreviewMaxFileSize
{
get
{
return _monacoMaxFileSize;
}
set
{
if (_monacoMaxFileSize != value)
{
_monacoMaxFileSize = value;
Settings.Properties.MonacoPreviewMaxFileSize.Value = value;
RaisePropertyChanged();
}
}
}
public bool PDFRenderIsEnabled
{
get

View File

@ -78,6 +78,16 @@
IsChecked="{x:Bind ViewModel.MonacoPreviewTryFormat, Mode=TwoWay}"
IsEnabled="{x:Bind ViewModel.MonacoRenderIsEnabled, Mode=OneWay}" />
</labs:SettingsCard>
<labs:SettingsCard
x:Uid="FileExplorerPreview_Toggle_Monaco_Max_File_Size"
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.MonacoRenderIsEnabled}">
<NumberBox
MinWidth="{StaticResource SettingActionControlMinWidth}"
Maximum="100"
Minimum="2"
SpinButtonPlacementMode="Compact"
Value="{x:Bind Mode=TwoWay, Path=ViewModel.MonacoPreviewMaxFileSize}" />
</labs:SettingsCard>
</labs:SettingsExpander.Items>
</labs:SettingsExpander>