Add message dialog asking to save on quit

This commit is contained in:
krzosa
2025-12-22 09:50:38 +01:00
parent 725cdde007
commit 32efabac6a
8 changed files with 95 additions and 28 deletions

View File

@@ -408,6 +408,30 @@ void OnCommand(Event event) {
String16 string16 = ToString16(scratch, event.text);
Replace(active.view, string16);
}
if (event.kind == EVENT_QUIT) {
Scratch scratch;
bool do_quit = true;
For (Buffers) {
if (it->garbage || it->dont_warn_on_save) {
continue;
}
if (it->dirty) {
String message = Format(scratch, "Do you really want to quit? Unsaved buffer: %S", it->name);
int save = SaveMessageBox("There are unsaved changes, do you really want to quit!", message.data);
if (save == 0) {
break;
}
if (save == 2) {
SaveBuffer(it);
}
}
}
if (do_quit) {
AppIsRunning = false;
}
}
}
void GarbageCollect() {
@@ -556,10 +580,6 @@ void MainLoop() {
if (it.kind != 1) {
if (!Testing) Serialize(&ser, &it);
}
if (it.kind == EVENT_QUIT) {
AppIsRunning = false;
return;
}
if (it.xwindow == 0 || it.ywindow == 0) {
int xwindow, ywindow;