Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RegPreview] Init with header and add NEW button #37626

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add new button
  • Loading branch information
htcfreek committed Feb 25, 2025
commit 280d5c907c839da09126530f97acd5591018cb51
Original file line number Diff line number Diff line change
@@ -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;
}

/// <summary>
/// Resets the editor content
/// </summary>
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;
}

/// <summary>
/// Opens the Registry Editor; UAC is handled by the request to open
/// </summary>
Original file line number Diff line number Diff line change
@@ -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);
}

/// <summary>
/// Parses the text that is passed in, which should be the same text that's in editor
/// </summary>
Original file line number Diff line number Diff line change
@@ -73,6 +73,15 @@
<KeyboardAccelerator Key="F5" />
</AppBarButton.KeyboardAccelerators>
</AppBarButton>
<AppBarButton
x:Name="newButton"
x:Uid="NewButton"
Click="NewButton_Click"
Icon="{ui:FontIcon Glyph=&#xe8a5;}">
<AppBarButton.KeyboardAccelerators>
<KeyboardAccelerator Key="N" Modifiers="Control" />
</AppBarButton.KeyboardAccelerators>
</AppBarButton>
<AppBarSeparator />
<AppBarButton
x:Name="saveButton"
Original file line number Diff line number Diff line change
@@ -297,4 +297,10 @@
<value>Copy value with key path</value>
<comment>Like "Copy item"</comment>
</data>
<data name="NewButton.Label" xml:space="preserve">
<value>New</value>
</data>
<data name="NewButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Reset editor to the default value and initilize a new file</value>

Check warning on line 304 in src/modules/registrypreview/RegistryPreviewUILib/Strings/en-US/Resources.resw

GitHub Actions / Check Spelling

`initilize` is not a recognized word. (unrecognized-spelling)
</data>
</root>
Loading
Oops, something went wrong.