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 twice closing crash
  • Loading branch information
htcfreek committed Feb 28, 2025
commit fc6dbe2c51a1c95e50d5bf123a44d0a3d8a31c60
Original file line number Diff line number Diff line change
@@ -811,48 +811,65 @@ private async void ShowMessageBox(string title, string content, string closeButt
/// </summary>
private async void HandleDirtyClosing(string title, string content, string primaryButtonText, string secondaryButtonText, string closeButtonText)
{
ContentDialog contentDialog = new ContentDialog()
{
Title = title,
Content = content,
PrimaryButtonText = primaryButtonText,
SecondaryButtonText = secondaryButtonText,
CloseButtonText = closeButtonText,
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))
if (_dialogSemaphore.CurrentCount == 0)
{
contentDialog.XamlRoot = this.Content.XamlRoot;
return;
}

ContentDialogResult contentDialogResult = await contentDialog.ShowAsync();

switch (contentDialogResult)
try
{
case ContentDialogResult.Primary:
// Save, then close
if (!AskFileName(string.Empty) ||
!SaveFile())
{
await _dialogSemaphore.WaitAsync();

ContentDialog contentDialog = new ContentDialog()
{
Title = title,
Content = content,
PrimaryButtonText = primaryButtonText,
SecondaryButtonText = secondaryButtonText,
CloseButtonText = closeButtonText,
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 close
if (!AskFileName(string.Empty) ||
!SaveFile())
{
return;
}

break;
case ContentDialogResult.Secondary:
// Don't save, and then close!
UpdateUnsavedFileIndicator(false);
saveButton.IsEnabled = false;
break;
default:
// Cancel closing!
return;
}
}

break;
case ContentDialogResult.Secondary:
// Don't save, and then close!
UpdateUnsavedFileIndicator(false);
saveButton.IsEnabled = false;
break;
default:
// Cancel closing!
return;
// if we got here, we should try to close again
Application.Current.Exit();
}
catch
{
}
finally
{
_dialogSemaphore.Release();
}

// if we got here, we should try to close again
Application.Current.Exit();
}

/// <summary>
Loading
Oops, something went wrong.