[Monaco]Make minimap toggleable (#33742)

This commit is contained in:
PesBandi
2025-01-14 12:47:53 +01:00
committed by GitHub
parent f11c885184
commit 80461c0241
16 changed files with 144 additions and 34 deletions

View File

@@ -231,10 +231,11 @@ namespace Peek.FilePreviewer.Controls
// When using Monaco, we show menu items that call the appropriate JS functions -
// WebView2 isn't able to show a "Copy" menu item of its own.
return [
CreateCommandMenuItem("ContextMenu_Copy", "runCopyCommand"),
new Separator(),
CreateCommandMenuItem("ContextMenu_ToggleTextWrapping", "runToggleTextWrapCommand"),
];
CreateCommandMenuItem("ContextMenu_Copy", "runCopyCommand"),
new Separator(),
CreateCommandMenuItem("ContextMenu_ToggleTextWrapping", "runToggleTextWrapCommand"),
CreateCommandMenuItem("ContextMenu_ToggleMinimap", "runToggleMinimap")
];
}
else
{

View File

@@ -13,5 +13,7 @@ namespace Peek.FilePreviewer.Models
public int SourceCodeFontSize { get; }
public bool SourceCodeStickyScroll { get; }
public bool SourceCodeMinimap { get; }
}
}

View File

@@ -30,6 +30,8 @@ namespace Peek.FilePreviewer.Models
public bool SourceCodeStickyScroll { get; private set; }
public bool SourceCodeMinimap { get; private set; }
public PreviewSettings()
{
_settingsUtils = new SettingsUtils();
@@ -37,6 +39,7 @@ namespace Peek.FilePreviewer.Models
SourceCodeTryFormat = false;
SourceCodeFontSize = 14;
SourceCodeStickyScroll = true;
SourceCodeMinimap = false;
LoadSettingsFromJson();
@@ -70,6 +73,7 @@ namespace Peek.FilePreviewer.Models
SourceCodeTryFormat = settings.SourceCodeTryFormat.Value;
SourceCodeFontSize = settings.SourceCodeFontSize.Value;
SourceCodeStickyScroll = settings.SourceCodeStickyScroll.Value;
SourceCodeMinimap = settings.SourceCodeMinimap.Value;
}
retry = false;

View File

@@ -48,13 +48,13 @@ namespace Peek.FilePreviewer.Previewers
/// <summary>
/// Prepares temp html for the previewing
/// </summary>
public static string PreviewTempFile(string fileText, string extension, string tempFolder, bool tryFormat, bool wrapText, bool stickyScroll, int fontSize)
public static string PreviewTempFile(string fileText, string extension, string tempFolder, bool tryFormat, bool wrapText, bool stickyScroll, int fontSize, bool minimap)
{
// TODO: check if file is too big, add MaxFileSize to settings
return InitializeIndexFileAndSelectedFile(fileText, extension, tempFolder, tryFormat, wrapText, stickyScroll, fontSize);
return InitializeIndexFileAndSelectedFile(fileText, extension, tempFolder, tryFormat, wrapText, stickyScroll, fontSize, minimap);
}
private static string InitializeIndexFileAndSelectedFile(string fileContent, string extension, string tempFolder, bool tryFormat, bool wrapText, bool stickyScroll, int fontSize)
private static string InitializeIndexFileAndSelectedFile(string fileContent, string extension, string tempFolder, bool tryFormat, bool wrapText, bool stickyScroll, int fontSize, bool minimap)
{
string vsCodeLangSet = Microsoft.PowerToys.FilePreviewCommon.MonacoHelper.GetLanguage(extension);
@@ -81,13 +81,14 @@ namespace Peek.FilePreviewer.Previewers
string html = Microsoft.PowerToys.FilePreviewCommon.MonacoHelper.ReadIndexHtml();
html = html.Replace("[[PT_LANG]]", vsCodeLangSet, StringComparison.InvariantCulture);
html = html.Replace("[[PT_WRAP]]", wrapText ? "1" : "0", StringComparison.InvariantCulture);
html = html.Replace("[[PT_CONTEXTMENU]]", "0", StringComparison.InvariantCulture);
html = html.Replace("[[PT_STICKY_SCROLL]]", stickyScroll ? "1" : "0", StringComparison.InvariantCulture);
html = html.Replace("[[PT_WRAP]]", wrapText ? "true" : "false", StringComparison.InvariantCulture);
html = html.Replace("[[PT_CONTEXTMENU]]", "false", StringComparison.InvariantCulture);
html = html.Replace("[[PT_STICKY_SCROLL]]", stickyScroll ? "true" : "false", StringComparison.InvariantCulture);
html = html.Replace("[[PT_THEME]]", theme, StringComparison.InvariantCulture);
html = html.Replace("[[PT_FONT_SIZE]]", fontSize.ToString(CultureInfo.InvariantCulture), StringComparison.InvariantCulture);
html = html.Replace("[[PT_CODE]]", base64FileCode, StringComparison.InvariantCulture);
html = html.Replace("[[PT_URL]]", Microsoft.PowerToys.FilePreviewCommon.MonacoHelper.VirtualHostName, StringComparison.InvariantCulture);
html = html.Replace("[[PT_MINIMAP]]", minimap ? "true" : "false", StringComparison.InvariantCulture);
string filename = tempFolder + "\\" + Guid.NewGuid().ToString() + ".html";
File.WriteAllText(filename, html);

View File

@@ -121,7 +121,7 @@ namespace Peek.FilePreviewer.Previewers
if (useMonaco)
{
var raw = await ReadHelper.Read(File.Path.ToString());
Preview = new Uri(MonacoHelper.PreviewTempFile(raw, File.Extension, TempFolderPath.Path, _previewSettings.SourceCodeTryFormat, _previewSettings.SourceCodeWrapText, _previewSettings.SourceCodeStickyScroll, _previewSettings.SourceCodeFontSize));
Preview = new Uri(MonacoHelper.PreviewTempFile(raw, File.Extension, TempFolderPath.Path, _previewSettings.SourceCodeTryFormat, _previewSettings.SourceCodeWrapText, _previewSettings.SourceCodeStickyScroll, _previewSettings.SourceCodeFontSize, _previewSettings.SourceCodeMinimap));
}
else if (isMarkdown)
{

View File

@@ -326,4 +326,7 @@
<value>Toggle text wrapping</value>
<comment>Toggle whether text in pane is word-wrapped</comment>
</data>
<data name="ContextMenu_ToggleMinimap" xml:space="preserve">
<value>Toggle minimap</value>
</data>
</root>