From 45c03f43e6413a44cc9f4177212cefd17731889d Mon Sep 17 00:00:00 2001 From: htcfreek <61519853+htcfreek@users.noreply.github.com> Date: Tue, 25 Feb 2025 12:28:08 +0100 Subject: [PATCH 1/4] default value --- .../RegistryPreviewUILib/RegistryPreviewMainPage.Utilities.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Utilities.cs b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Utilities.cs index b8fc6e4e1d9a..e1a0420a6899 100644 --- a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Utilities.cs +++ b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Utilities.cs @@ -77,6 +77,9 @@ private async Task OpenRegistryFile(string filename) } catch { + // Set default value for empty opening + await MonacoEditor.SetTextAsync("Windows Registry Editor Version 5.00\r\n\r\n"); + // restore TextChanged handler to make for clean UI MonacoEditor.TextChanged += MonacoEditor_TextChanged; From 280d5c907c839da09126530f97acd5591018cb51 Mon Sep 17 00:00:00 2001 From: htcfreek <61519853+htcfreek@users.noreply.github.com> Date: Tue, 25 Feb 2025 13:17:34 +0100 Subject: [PATCH 2/4] add new button --- .../RegistryPreviewMainPage.Events.cs | 58 +++++++++++++++++++ .../RegistryPreviewMainPage.Utilities.cs | 19 ++++++ .../RegistryPreviewMainPage.xaml | 9 +++ .../Strings/en-US/Resources.resw | 6 ++ 4 files changed, 92 insertions(+) diff --git a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Events.cs b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Events.cs index 0df3a5c0f5ed..20009533c1d5 100644 --- a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Events.cs +++ b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Events.cs @@ -192,12 +192,70 @@ private async void RefreshButton_Click(object sender, RoutedEventArgs e) // 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 e1a0420a6899..e7c8328f3ca1 100644 --- a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Utilities.cs +++ b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Utilities.cs @@ -170,6 +170,25 @@ private void RefreshRegistryFile() 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("Windows Registry Editor Version 5.00\r\n\r\n"); + + // 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 a48222e9aa8f..572984b4fe62 100644 --- a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.xaml +++ b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.xaml @@ -73,6 +73,15 @@ + + + + + Copy value with key path Like "Copy item" + + New + + + Reset editor to the default value and initilize a new file + \ No newline at end of file From 3277d90380dfe76136455d1e678410cf4d30cd7d Mon Sep 17 00:00:00 2001 From: htcfreek <61519853+htcfreek@users.noreply.github.com> Date: Tue, 25 Feb 2025 14:39:56 +0100 Subject: [PATCH 3/4] fix tool tip --- .../RegistryPreviewUILib/Strings/en-US/Resources.resw | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/modules/registrypreview/RegistryPreviewUILib/Strings/en-US/Resources.resw b/src/modules/registrypreview/RegistryPreviewUILib/Strings/en-US/Resources.resw index 30085a24f153..93242072241d 100644 --- a/src/modules/registrypreview/RegistryPreviewUILib/Strings/en-US/Resources.resw +++ b/src/modules/registrypreview/RegistryPreviewUILib/Strings/en-US/Resources.resw @@ -300,7 +300,4 @@ New - - Reset editor to the default value and initilize a new file - \ No newline at end of file From 3c7d60f307a0dfda2b2906cd32b5f669e520f375 Mon Sep 17 00:00:00 2001 From: htcfreek <61519853+htcfreek@users.noreply.github.com> Date: Fri, 28 Feb 2025 13:33:20 +0100 Subject: [PATCH 4/4] update button symbol --- .../RegistryPreviewUILib/RegistryPreviewMainPage.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.xaml b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.xaml index 572984b4fe62..158a0c4e5c49 100644 --- a/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.xaml +++ b/src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.xaml @@ -77,7 +77,7 @@ x:Name="newButton" x:Uid="NewButton" Click="NewButton_Click" - Icon="{ui:FontIcon Glyph=}"> + Icon="{ui:FontIcon Glyph=}">