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
reuse file name
  • Loading branch information
htcfreek committed Feb 25, 2025
commit 7b22a197d2fa03134a46a796d5b87a159d39faa2
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
{
private readonly DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();

// Indicator if we loaded/reloaded/saved a file and need to skip TextChangedEevent one time.

Check warning on line 26 in src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Events.cs

GitHub Actions / Check Spelling

`Eevent` is not a recognized word. (unrecognized-spelling)
private static bool newFileLoaded;

/// <summary>
@@ -110,7 +110,7 @@
{
case ContentDialogResult.Primary:
// Save, then continue the file open
if (!AskFileName(false) ||
if (!AskFileName(_appFileName) ||
!SaveFile())
{
return;
@@ -167,7 +167,7 @@
/// </summary>
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
if (!AskFileName(false))
if (!AskFileName(_appFileName))
{
return;
}
@@ -181,7 +181,7 @@
/// </summary>
private async void SaveAsButton_Click(object sender, RoutedEventArgs e)
{
if (!AskFileName(true) || !SaveFile())
if (!AskFileName(_appFileName) || !SaveFile())
{
return;
}
@@ -267,7 +267,7 @@
{
case ContentDialogResult.Primary:
// Save, then continue the file open
if (!AskFileName(false) ||
if (!AskFileName(_appFileName) ||
!SaveFile())
{
return;
Original file line number Diff line number Diff line change
@@ -834,7 +834,7 @@
{
case ContentDialogResult.Primary:
// Save, then close
if (!AskFileName(false) ||
if (!AskFileName(_appFileName) ||
!SaveFile())
{
return;
@@ -934,18 +934,20 @@
/// <summary>
/// Ask the user for the file path if it is unknown because of an unsaved file
/// </summary>
/// <param name="askAlways">Ask regardless of the known file name in case of save as action.</param>
/// <param name="fileName">If not empty always aks for a file path and use the value as name.</param>

Check warning on line 937 in src/modules/registrypreview/RegistryPreviewUILib/RegistryPreviewMainPage.Utilities.cs

GitHub Actions / Check Spelling

`aks` is not a recognized word. (unrecognized-spelling)
/// <returns>Returns true if user selected a path, otherwise false</returns>
public bool AskFileName(bool askAlways)
public bool AskFileName(string fileName)
{
if (string.IsNullOrEmpty(_appFileName) || askAlways )
if (string.IsNullOrEmpty(_appFileName) || !string.IsNullOrEmpty(fileName) )
{
string fName = string.IsNullOrEmpty(fileName) ? resourceLoader.GetString("SuggestFileName") : fileName;

// 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"),
fName,
resourceLoader.GetString("FilterRegistryName") + '\0' + "*.reg" + '\0' + resourceLoader.GetString("FilterAllFiles") + '\0' + "*.*" + '\0' + '\0',
resourceLoader.GetString("SaveDialogTitle"));

Loading
Oops, something went wrong.