From d314fa075e05a95bab2fce1486ca9e3b097be108 Mon Sep 17 00:00:00 2001 From: Heiko <61519853+htcfreek@users.noreply.github.com> Date: Mon, 21 Apr 2025 10:11:07 +0200 Subject: [PATCH] [RegPreview] Init with header and add NEW button (#37626) * default value * add new button * fix tool tip * update button symbol * feedback changes * spellcheck --- .github/actions/spell-check/expect.txt | 1 + .../RegistryPreviewMainPage.Events.cs | 58 +++++++++++++++++++ .../RegistryPreviewMainPage.Utilities.cs | 24 ++++++++ .../RegistryPreviewMainPage.xaml | 9 +++ .../Strings/en-US/Resources.resw | 3 + 5 files changed, 95 insertions(+) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index ea8ffa19ad..6a2041ce18 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -1006,6 +1006,7 @@ netsh newcolor NEWDIALOGSTYLE NEWFILE +NEWFILEHEADER newitem newpath newplus diff --git a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Events.cs b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Events.cs index 0df3a5c0f5..20009533c1 100644 --- a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Events.cs +++ b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Events.cs @@ -192,12 +192,70 @@ namespace RegistryPreviewUILib // reload the current Registry file and update the toolbar accordingly. UpdateToolBarAndUI(await OpenRegistryFile(_appFileName), true, true); + // disable the Save button as it's a new file saveButton.IsEnabled = false; // restore the TextChanged handler MonacoEditor.TextChanged += MonacoEditor_TextChanged; } + /// + /// Resets the editor content + /// + private async void NewButton_Click(object sender, RoutedEventArgs e) + { + // Check to see if the current file has been saved + if (saveButton.IsEnabled) + { + ContentDialog contentDialog = new ContentDialog() + { + Title = resourceLoader.GetString("YesNoCancelDialogTitle"), + Content = resourceLoader.GetString("YesNoCancelDialogContent"), + PrimaryButtonText = resourceLoader.GetString("YesNoCancelDialogPrimaryButtonText"), + SecondaryButtonText = resourceLoader.GetString("YesNoCancelDialogSecondaryButtonText"), + CloseButtonText = resourceLoader.GetString("YesNoCancelDialogCloseButtonText"), + DefaultButton = ContentDialogButton.Primary, + }; + + // Use this code to associate the dialog to the appropriate AppWindow by setting + // the dialog's XamlRoot to the same XamlRoot as an element that is already present in the AppWindow. + if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8)) + { + contentDialog.XamlRoot = this.Content.XamlRoot; + } + + ContentDialogResult contentDialogResult = await contentDialog.ShowAsync(); + switch (contentDialogResult) + { + case ContentDialogResult.Primary: + // Save, then continue the file open + SaveFile(); + break; + case ContentDialogResult.Secondary: + // Don't save and continue the file open! + saveButton.IsEnabled = false; + break; + default: + // Don't open the new file! + return; + } + } + + // mute the TextChanged handler to make for clean UI + MonacoEditor.TextChanged -= MonacoEditor_TextChanged; + + // reset editor, file info and ui. + _appFileName = string.Empty; + ResetEditorAndFile(); + + // restore the TextChanged handler + MonacoEditor.TextChanged += MonacoEditor_TextChanged; + + // disable buttons that do not make sense + saveButton.IsEnabled = false; + refreshButton.IsEnabled = false; + } + /// /// Opens the Registry Editor; UAC is handled by the request to open /// diff --git a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Utilities.cs b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Utilities.cs index 819fee949a..3ec275abf8 100644 --- a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Utilities.cs +++ b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Utilities.cs @@ -22,6 +22,8 @@ namespace RegistryPreviewUILib { public sealed partial class RegistryPreviewMainPage : Page { + private const string NEWFILEHEADER = "Windows Registry Editor Version 5.00\r\n\r\n"; + private static SemaphoreSlim _dialogSemaphore = new(1); private string lastKeyPath; @@ -77,6 +79,9 @@ namespace RegistryPreviewUILib } catch { + // Set default value for empty opening + await MonacoEditor.SetTextAsync(NEWFILEHEADER); + // restore TextChanged handler to make for clean UI MonacoEditor.TextChanged += MonacoEditor_TextChanged; @@ -167,6 +172,25 @@ namespace RegistryPreviewUILib ChangeCursor(gridPreview, false); } + private async void ResetEditorAndFile() + { + // Disable parts of the UI that can cause trouble when loading + ChangeCursor(gridPreview, true); + + // clear the treeView and dataGrid no matter what + treeView.RootNodes.Clear(); + ClearTable(); + + // update the current window's title with the current filename + _updateWindowTitleFunction(string.Empty); + + // Set default value for empty opening + await MonacoEditor.SetTextAsync(NEWFILEHEADER); + + // Reset the cursor but leave editor disabled as no content got loaded + ChangeCursor(gridPreview, false); + } + /// /// Parses the text that is passed in, which should be the same text that's in editor /// diff --git a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.xaml b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.xaml index a48222e9aa..18225902e3 100644 --- a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.xaml +++ b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.xaml @@ -55,6 +55,15 @@ HorizontalAlignment="Left" DefaultLabelPosition="Right"> + + + + + Copy value with key path Like "Copy item" + + New + \ No newline at end of file