Skip to content

Commit

Permalink
Removed quit var and fixed style
Browse files Browse the repository at this point in the history
  • Loading branch information
luizzeroxis committed Aug 18, 2024
1 parent 8b2e32e commit 22e6de2
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -772,59 +772,60 @@ private async void DataWindow_Closing(object sender, CancelEventArgs e)
e.Cancel = true;

bool save = false;
bool quit = false;

if (SettingsWindow.WarnOnClose)
{
MessageBoxResult result = this.ShowQuestionWithCancel("Save changes before quitting?");

if (result == MessageBoxResult.Yes) {
quit = true;
if (result == MessageBoxResult.Cancel)
{
return;
}

if (result == 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;
} else if (result == MessageBoxResult.No) {
quit = true;
}
}
}
else
{
quit = true;
}

if (quit) {
if (save) {
SaveResult saveRes = await SaveCodeChanges();
if (save)
{
SaveResult saveRes = await SaveCodeChanges();

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 (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();
}

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

CloseOtherWindows();
CloseOtherWindows();

IsAppClosed = true;
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

0 comments on commit 22e6de2

Please sign in to comment.