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
code improvement and fix save as button behavior
  • Loading branch information
htcfreek committed Feb 25, 2025
commit 067897d23032c28d7061f6622abe39343c25256c
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ public sealed partial class RegistryPreviewMainPage : Page
private readonly DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();

// Indicator if we loaded/reloaded/saved a file and need to skip TextChanged event one time.
private static bool newFileLoaded;
private static bool editorContentChangedScripted;

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

// update file name
_appFileName = storageFile.Path;
@@ -181,13 +181,19 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
/// </summary>
private async void SaveAsButton_Click(object sender, RoutedEventArgs e)
{
newFileLoaded = true;
// mute the TextChanged handler to make for clean UI
editorContentChangedScripted = true;
MonacoEditor.TextChanged -= MonacoEditor_TextChanged;

if (!AskFileName(_appFileName) || !SaveFile())
{
return;
}

UpdateToolBarAndUI(await OpenRegistryFile(_appFileName));

// restore the TextChanged handler
MonacoEditor.TextChanged += MonacoEditor_TextChanged;
}

/// <summary>
@@ -196,7 +202,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;
editorContentChangedScripted = true;
MonacoEditor.TextChanged -= MonacoEditor_TextChanged;

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

newFileLoaded = false;
editorContentChangedScripted = false;
});
}
}