Skip to content

Commit

Permalink
Changed quitting to show a yes/no/cancel dialog instead of 2 yes/no d…
Browse files Browse the repository at this point in the history
…ialogs
  • Loading branch information
luizzeroxis committed Aug 18, 2024
1 parent 88eeb30 commit 8b2e32e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 36 deletions.
73 changes: 37 additions & 36 deletions UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -772,58 +772,59 @@ private async void DataWindow_Closing(object sender, CancelEventArgs e)
e.Cancel = true;

bool save = false;
bool quit = false;

if (SettingsWindow.WarnOnClose)
{
if (this.ShowQuestion("Are you sure you want to quit?") == MessageBoxResult.Yes)
{
if (this.ShowQuestion("Save changes first?") == MessageBoxResult.Yes)
{
if (scriptDialog is not null)
{
if (this.ShowQuestion("Script still runs. Save anyway?\nIt can corrupt the data file that you'll save.") == MessageBoxResult.Yes)
save = true;
}
else
save = true;
MessageBoxResult result = this.ShowQuestionWithCancel("Save changes before quitting?");

if (save)
{
SaveResult saveRes = await SaveCodeChanges();
if (result == MessageBoxResult.Yes) {
quit = true;

if (saveRes == SaveResult.NotSaved)
_ = DoSaveDialog();
else if (saveRes == SaveResult.Error)
{
this.ShowError("The changes in code editor weren't saved due to some error in \"SaveCodeChanges()\".");
return;
}
}
if (scriptDialog is not null)
{
if (this.ShowQuestion("Script still runs. Save anyway?\nIt can corrupt the data file that you'll save.") == MessageBoxResult.Yes)
save = true;
}
else
RevertProfile();

DestroyUMTLastEdited();
save = true;
} else if (result == MessageBoxResult.No) {
quit = true;
}
else
return;
}
else
{
RevertProfile();
DestroyUMTLastEdited();
quit = true;
}

if (SettingsWindow.UseGMLCache && Data?.GMLCache?.Count > 0 && !Data.GMLCacheWasSaved && Data.GMLCacheIsReady)
if (this.ShowQuestion("Save unedited code cache?") == MessageBoxResult.Yes)
await SaveGMLCache(FilePath, save);
if (quit) {
if (save) {
SaveResult saveRes = await SaveCodeChanges();

CloseOtherWindows();
if (saveRes == SaveResult.NotSaved)
_ = DoSaveDialog();
else if (saveRes == SaveResult.Error)
{
this.ShowError("The changes in code editor weren't saved due to some error in \"SaveCodeChanges()\".");
return;
}
} else {
RevertProfile();
}

IsAppClosed = true;
DestroyUMTLastEdited();

if (SettingsWindow.UseGMLCache && Data?.GMLCache?.Count > 0 && !Data.GMLCacheWasSaved && Data.GMLCacheIsReady)
if (this.ShowQuestion("Save unedited code cache?") == MessageBoxResult.Yes)
await SaveGMLCache(FilePath, save);

CloseOtherWindows();

IsAppClosed = true;

Closing -= DataWindow_Closing; //disable "on window closed" event handler (prevent recursion)
_ = Task.Run(() => Dispatcher.Invoke(Close));
Closing -= DataWindow_Closing; //disable "on window closed" event handler (prevent recursion)
_ = Task.Run(() => Dispatcher.Invoke(Close));
}
}
}
private void Command_Close(object sender, ExecutedRoutedEventArgs e)
Expand Down
13 changes: 13 additions & 0 deletions UndertaleModTool/MessageBoxExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ public static MessageBoxResult ShowQuestion(this Window window, string messageBo
return ShowCore(window, messageBoxText, title, MessageBoxButton.YesNo, icon);
}

/// <summary>
/// Shows a <see cref="MessageBox"/> prompting for a yes/no/cancel question with <paramref name="window"/> as the parent.
/// </summary>
/// <param name="window">The parent from which the <see cref="MessageBox"/> will show.</param>
/// <param name="messageBoxText">A <see cref="string"/> that specifies the text to display.</param>
/// <param name="icon">The <see cref="MessageBoxImage"/> to display.</param>
/// <param name="title">A <see cref="string"/> that specifies the title bar caption to display.</param>
/// <returns><see cref="MessageBoxResult.Yes"/>, <see cref="MessageBoxResult.No"/> or <see cref="MessageBoxResult.Cancel"/> depending on the users' answer.
public static MessageBoxResult ShowQuestionWithCancel(this Window window, string messageBoxText, MessageBoxImage icon = MessageBoxImage.Question, string title = "UndertaleModTool")

Check warning on line 45 in UndertaleModTool/MessageBoxExtensions.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, true, false)

XML comment has badly formed XML -- 'Expected an end tag for element 'returns'.'

Check warning on line 45 in UndertaleModTool/MessageBoxExtensions.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, true, false)

XML comment has badly formed XML -- 'Expected an end tag for element 'returns'.'

Check warning on line 45 in UndertaleModTool/MessageBoxExtensions.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, true, true)

XML comment has badly formed XML -- 'Expected an end tag for element 'returns'.'

Check warning on line 45 in UndertaleModTool/MessageBoxExtensions.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, true, true)

XML comment has badly formed XML -- 'Expected an end tag for element 'returns'.'
{
return ShowCore(window, messageBoxText, title, MessageBoxButton.YesNoCancel, icon);
}

/// <summary>
/// Shows a warning <see cref="MessageBox"/> with <paramref name="window"/> as the parent.
/// </summary>
Expand Down

0 comments on commit 8b2e32e

Please sign in to comment.