From 44066273ead454e5b9b3f811e9c9220602a2dd16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Sun, 16 May 2021 16:39:03 +0200 Subject: [PATCH] prompt to save unsaved work on exit --- code/game/source/editors/texed.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/code/game/source/editors/texed.c b/code/game/source/editors/texed.c index 202c480..abf9081 100644 --- a/code/game/source/editors/texed.c +++ b/code/game/source/editors/texed.c @@ -225,7 +225,7 @@ void texed_run(int argc, char **argv) { GuiSetStyle(TEXTBOX, TEXT_COLOR_NORMAL, ColorToInt(RAYWHITE)); - while (!WindowShouldClose()) { + while (1) { zpl_aabb2 screen = { .min = (zpl_vec2) {.x = 0.0f, .y = 0.0f}, .max = (zpl_vec2) {.x = GetScreenWidth(), .y = GetScreenHeight()}, @@ -282,6 +282,24 @@ void texed_run(int argc, char **argv) { texed_draw_msgbox(orig_screen); } EndDrawing(); + + static bool exit_pending = false; + if (WindowShouldClose()) { + if (!ctx.is_saved) { + texed_msgbox_init("Discard unsaved work?", "You have an unsaved work! Do you want to proceed?", "OK;Cancel"); + exit_pending = true; + } else { + break; + } + } + + if (exit_pending && ctx.msgbox.result != -1) { + exit_pending = false; + if (ctx.msgbox.result == 1) { + break; + } + ctx.msgbox.result = -1; + } } UnloadTexture(checker_tex); @@ -310,6 +328,7 @@ void texed_new(int32_t w, int32_t h) { void texed_destroy(void) { UnloadTexture(ctx.tex); UnloadImage(ctx.img); + CloseWindow(); zpl_array_free(ctx.ops); }