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
save as behavior for svae button
  • Loading branch information
htcfreek committed Feb 25, 2025
commit 36629362e4064f578cf35b4bf5dd400cbe834093
Original file line number Diff line number Diff line change
@@ -156,7 +156,28 @@ private async void OpenButton_Click(object sender, RoutedEventArgs e)
/// </summary>
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(_appFileName))
{
// Save out a new REG file and then open it - we have to use the direct Win32 method because FileOpenPicker crashes when it's
// called while running as admin
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(_mainWindow);
string filename = SaveFilePicker.ShowDialog(
windowHandle,
resourceLoader.GetString("SuggestFileName"),
resourceLoader.GetString("FilterRegistryName") + '\0' + "*.reg" + '\0' + resourceLoader.GetString("FilterAllFiles") + '\0' + "*.*" + '\0' + '\0',
resourceLoader.GetString("SaveDialogTitle"));

if (filename == string.Empty)
{
return;
}

_appFileName = filename;
}

// save and update window title
SaveFile();
_updateWindowTitleFunction(_appFileName);
}

/// <summary>
Original file line number Diff line number Diff line change
@@ -834,7 +834,12 @@ private async void HandleDirtyClosing(string title, string content, string prima
{
case ContentDialogResult.Primary:
// Save, then close
SaveFile();
if (!DirtyCloseSaveFile())
{
// save cancelled
return;
}

break;
case ContentDialogResult.Secondary:
// Don't save, and then close!
@@ -850,6 +855,31 @@ private async void HandleDirtyClosing(string title, string content, string prima
Application.Current.Exit();
}

private bool DirtyCloseSaveFile()
{
if (string.IsNullOrEmpty(_appFileName))
{
// Save out a new REG file and then open it - we have to use the direct Win32 method because FileOpenPicker crashes when it's
// called while running as admin
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(_mainWindow);
string filename = SaveFilePicker.ShowDialog(
windowHandle,
resourceLoader.GetString("SuggestFileName"),
resourceLoader.GetString("FilterRegistryName") + '\0' + "*.reg" + '\0' + resourceLoader.GetString("FilterAllFiles") + '\0' + "*.*" + '\0' + '\0',
resourceLoader.GetString("SaveDialogTitle"));

if (filename == string.Empty)
{
return false;
}

_appFileName = filename;
}

SaveFile();
return true;
}

/// <summary>
/// Method will open the Registry Editor or merge the current REG file into the Registry via the Editor
/// Process will prompt for elevation if it needs it.