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] Various improvements on how files are saved #37628

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
fix wrong unsaved state after opening file
  • Loading branch information
htcfreek committed Feb 25, 2025
commit 410c37fef3fb4a864851715fc9528380b2f8fb78
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@ public sealed partial class RegistryPreviewMainPage : Page
{
private readonly DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();

// Indicator if we loaded or reloaded a file
private static bool newFileLoaded;

/// <summary>
/// Event that is will prevent the app from closing if the "save file" flag is active
/// </summary>
@@ -144,6 +147,9 @@ private async void OpenButton_Click(object sender, RoutedEventArgs e)
{
// mute the TextChanged handler to make for clean UI
MonacoEditor.TextChanged -= MonacoEditor_TextChanged;
newFileLoaded = true;

// update file name
_appFileName = storageFile.Path;
UpdateToolBarAndUI(await OpenRegistryFile(_appFileName));

@@ -215,6 +221,7 @@ private async void SaveAsButton_Click(object sender, RoutedEventArgs e)
private async void RefreshButton_Click(object sender, RoutedEventArgs e)
{
// mute the TextChanged handler to make for clean UI
newFileLoaded = true;
MonacoEditor.TextChanged -= MonacoEditor_TextChanged;

// reload the current Registry file and update the toolbar accordingly.
@@ -388,8 +395,13 @@ private void MonacoEditor_TextChanged(object sender, EventArgs e)
_dispatcherQueue.TryEnqueue(() =>
{
RefreshRegistryFile();
saveButton.IsEnabled = true;
UpdateUnsavedFileIndicator(true);
if (!newFileLoaded)
{
saveButton.IsEnabled = true;
UpdateUnsavedFileIndicator(true);
}

newFileLoaded = false;
});
}
}
Loading
Oops, something went wrong.