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

Changed quitting to show a yes/no/cancel dialog instead of 2 yes/no dialogs #1877

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 26 additions & 31 deletions UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -775,54 +775,49 @@

if (SettingsWindow.WarnOnClose)
{
if (this.ShowQuestion("Are you sure you want to quit?") == MessageBoxResult.Yes)
MessageBoxResult result = this.ShowQuestionWithCancel("Save changes before quitting?");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing the "are you sure you want to quit" is probably fine to do for now, but if you could add a comment that mentions to only ask whether changes should be saved if the file was changed, and ask whether the user really wants to quit otherwise would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to get if changes have been made; maybe that's for another PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it absolutely is, was mostly just mentioning that adding a comment for that would be neat.


if (result == MessageBoxResult.Cancel)
{
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;
return;
}

if (save)
{
SaveResult saveRes = await SaveCodeChanges();
if (result == MessageBoxResult.Yes)
{
if (scriptDialog is null || (this.ShowQuestion("Script still runs. Save anyway?\nIt can corrupt the data file that you'll save.") == MessageBoxResult.Yes))
save = true;
Miepee marked this conversation as resolved.
Show resolved Hide resolved
}
}

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();
if (save)
{
SaveResult saveRes = await SaveCodeChanges();

DestroyUMTLastEdited();
if (saveRes == SaveResult.NotSaved)
{
_ = DoSaveDialog();
}
else
else if (saveRes == SaveResult.Error)
{
this.ShowError("The changes in code editor weren't saved due to some error in \"SaveCodeChanges()\".");
return;
}
}
else
{
RevertProfile();
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);
DestroyUMTLastEdited();

if (SettingsWindow.UseGMLCache && Data?.GMLCache?.Count > 0 && !Data.GMLCacheWasSaved && Data.GMLCacheIsReady && 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)
Closing -= DataWindow_Closing; // Disable "on window closed" event handler (prevent recursion)
_ = Task.Run(() => Dispatcher.Invoke(Close));
}
}
Expand Down Expand Up @@ -3057,7 +3052,7 @@
};
SetProgressBar();

using (WebClient webClient = new())

Check warning on line 3055 in UndertaleModTool/MainWindow.xaml.cs

View workflow job for this annotation

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

'WebClient.WebClient()' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.' (https://aka.ms/dotnet-warnings/SYSLIB0014)

Check warning on line 3055 in UndertaleModTool/MainWindow.xaml.cs

View workflow job for this annotation

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

'WebClient.WebClient()' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.' (https://aka.ms/dotnet-warnings/SYSLIB0014)

Check warning on line 3055 in UndertaleModTool/MainWindow.xaml.cs

View workflow job for this annotation

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

'WebClient.WebClient()' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.' (https://aka.ms/dotnet-warnings/SYSLIB0014)

Check warning on line 3055 in UndertaleModTool/MainWindow.xaml.cs

View workflow job for this annotation

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

'WebClient.WebClient()' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.' (https://aka.ms/dotnet-warnings/SYSLIB0014)
{
bool end = false;
bool ended = false;
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 @@
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, false, 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, false, 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, false, 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, false, false)

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
Loading