From 22e6de2eeb52305d05cb4c28f7e6e7cdd3e72f26 Mon Sep 17 00:00:00 2001 From: luizzeroxis Date: Sun, 18 Aug 2024 15:42:21 -0300 Subject: [PATCH] Removed quit var and fixed style --- UndertaleModTool/MainWindow.xaml.cs | 61 +++++++++++++++-------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/UndertaleModTool/MainWindow.xaml.cs b/UndertaleModTool/MainWindow.xaml.cs index 69a377c01..36c41d0d4 100644 --- a/UndertaleModTool/MainWindow.xaml.cs +++ b/UndertaleModTool/MainWindow.xaml.cs @@ -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)