mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
[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:
parent
bc4bde8cee
commit
00e10d38c2
@ -212,6 +212,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
|
|||||||
downloadLink.Top = TextRenderer.MeasureText(Resources.WebView2_Not_Installed_Message, errorMessage.Font).Height + 10;
|
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.Width = TextRenderer.MeasureText(Resources.Download_WebView2, errorMessage.Font).Width + 10;
|
||||||
downloadLink.Height = TextRenderer.MeasureText(Resources.Download_WebView2, errorMessage.Font).Height;
|
downloadLink.Height = TextRenderer.MeasureText(Resources.Download_WebView2, errorMessage.Font).Height;
|
||||||
|
downloadLink.ForeColor = Settings.TextColor;
|
||||||
Controls.Add(downloadLink);
|
Controls.Add(downloadLink);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -222,6 +223,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
|
|||||||
Controls.Remove(_loadingBar);
|
Controls.Remove(_loadingBar);
|
||||||
Controls.Remove(_loadingBackground);
|
Controls.Remove(_loadingBackground);
|
||||||
Label text = new Label();
|
Label text = new Label();
|
||||||
|
text.ForeColor = Settings.TextColor;
|
||||||
text.Text = Resources.Exception_Occurred;
|
text.Text = Resources.Exception_Occurred;
|
||||||
text.Text += e.Message;
|
text.Text += e.Message;
|
||||||
text.Text += "\n" + e.Source;
|
text.Text += "\n" + e.Source;
|
||||||
@ -244,6 +246,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
|
|||||||
Controls.Remove(_loadingBackground);
|
Controls.Remove(_loadingBackground);
|
||||||
Label errorMessage = new Label();
|
Label errorMessage = new Label();
|
||||||
errorMessage.Text = Resources.Max_File_Size_Error.Replace("%1", (_settings.MaxFileSize / 1000).ToString(CultureInfo.CurrentCulture), StringComparison.InvariantCulture);
|
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.Width = 500;
|
||||||
errorMessage.Height = 50;
|
errorMessage.Height = 50;
|
||||||
Controls.Add(errorMessage);
|
Controls.Add(errorMessage);
|
||||||
|
@ -58,11 +58,24 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Max file size for displaying (in bytes).
|
/// Gets Max file size for displaying (in bytes).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly long _maxFileSize = 50000;
|
public double MaxFileSize
|
||||||
|
{
|
||||||
public long MaxFileSize => _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>
|
/// <summary>
|
||||||
/// Gets the color of the window background.
|
/// Gets the color of the window background.
|
||||||
|
@ -13,6 +13,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
|||||||
public class PowerPreviewProperties
|
public class PowerPreviewProperties
|
||||||
{
|
{
|
||||||
public const string DefaultStlThumbnailColor = "#FFC924";
|
public const string DefaultStlThumbnailColor = "#FFC924";
|
||||||
|
public const int DefaultMonacoMaxFileSize = 50;
|
||||||
|
|
||||||
private bool enableSvgPreview = true;
|
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;
|
private bool enablePdfPreview;
|
||||||
|
|
||||||
[JsonPropertyName("pdf-previewer-toggle-setting")]
|
[JsonPropertyName("pdf-previewer-toggle-setting")]
|
||||||
@ -207,6 +211,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
|||||||
public PowerPreviewProperties()
|
public PowerPreviewProperties()
|
||||||
{
|
{
|
||||||
StlThumbnailColor = new StringProperty(DefaultStlThumbnailColor);
|
StlThumbnailColor = new StringProperty(DefaultStlThumbnailColor);
|
||||||
|
MonacoPreviewMaxFileSize = new IntProperty(DefaultMonacoMaxFileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
@ -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">
|
<data name="UpdateAvailable.Title" xml:space="preserve">
|
||||||
<value>Update available</value>
|
<value>Update available</value>
|
||||||
</data>
|
</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>
|
</root>
|
@ -98,6 +98,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
_monacoWrapText = Settings.Properties.EnableMonacoPreviewWordWrap;
|
_monacoWrapText = Settings.Properties.EnableMonacoPreviewWordWrap;
|
||||||
_monacoPreviewTryFormat = Settings.Properties.MonacoPreviewTryFormat;
|
_monacoPreviewTryFormat = Settings.Properties.MonacoPreviewTryFormat;
|
||||||
|
_monacoMaxFileSize = Settings.Properties.MonacoPreviewMaxFileSize.Value;
|
||||||
|
|
||||||
_pdfRenderEnabledGpoRuleConfiguration = GPOWrapper.GetConfiguredPdfPreviewEnabledValue();
|
_pdfRenderEnabledGpoRuleConfiguration = GPOWrapper.GetConfiguredPdfPreviewEnabledValue();
|
||||||
if (_pdfRenderEnabledGpoRuleConfiguration == GpoRuleConfigured.Disabled || _pdfRenderEnabledGpoRuleConfiguration == GpoRuleConfigured.Enabled)
|
if (_pdfRenderEnabledGpoRuleConfiguration == GpoRuleConfigured.Disabled || _pdfRenderEnabledGpoRuleConfiguration == GpoRuleConfigured.Enabled)
|
||||||
@ -175,6 +176,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
private bool _monacoRenderIsEnabled;
|
private bool _monacoRenderIsEnabled;
|
||||||
private bool _monacoWrapText;
|
private bool _monacoWrapText;
|
||||||
private bool _monacoPreviewTryFormat;
|
private bool _monacoPreviewTryFormat;
|
||||||
|
private int _monacoMaxFileSize;
|
||||||
|
|
||||||
private GpoRuleConfigured _pdfRenderEnabledGpoRuleConfiguration;
|
private GpoRuleConfigured _pdfRenderEnabledGpoRuleConfiguration;
|
||||||
private bool _pdfRenderEnabledStateIsGPOConfigured;
|
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
|
public bool PDFRenderIsEnabled
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -78,6 +78,16 @@
|
|||||||
IsChecked="{x:Bind ViewModel.MonacoPreviewTryFormat, Mode=TwoWay}"
|
IsChecked="{x:Bind ViewModel.MonacoPreviewTryFormat, Mode=TwoWay}"
|
||||||
IsEnabled="{x:Bind ViewModel.MonacoRenderIsEnabled, Mode=OneWay}" />
|
IsEnabled="{x:Bind ViewModel.MonacoRenderIsEnabled, Mode=OneWay}" />
|
||||||
</labs:SettingsCard>
|
</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.Items>
|
||||||
</labs:SettingsExpander>
|
</labs:SettingsExpander>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user