diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-30 13:21:53 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-30 13:21:53 -0500 |
commit | b35a780479bbf5038a825d415f9ca49c92f6b425 (patch) | |
tree | 44e71007552714b03ae812e466495ec5c8a7e27b /command.c | |
parent | a61d90c32d4d6448148894872ebd91eb8f10fc2e (diff) |
ctrl+q to quit (with unsaved changes dialog)
Diffstat (limited to 'command.c')
-rw-r--r-- | command.c | 29 |
1 files changed, 27 insertions, 2 deletions
@@ -159,9 +159,34 @@ void command_execute(Ted *ted, Command c, i64 argument) { menu_open(ted, MENU_SAVE_AS); } break; + case CMD_SAVE_ALL: + ted_save_all(ted); + break; case CMD_QUIT: - // @TODO: check for unsaved changes in all buffers - ted->quit = true; + // pass argument of 2 to override dialog + if (argument == 2) { + ted->quit = true; + } else { + *ted->warn_unsaved_names = 0; + bool *buffers_used = ted->buffers_used; + bool first = true; + for (u16 i = 0; i < TED_MAX_BUFFERS; ++i) { + if (buffers_used[i]) { + buffer = &ted->buffers[i]; + if (buffer_unsaved_changes(buffer)) { + strbuf_catf(ted->warn_unsaved_names, "%s%s", first ? "" : ", ", path_filename(buffer->filename)); + first = false; + } + } + } + if (*ted->warn_unsaved_names) { + ted->warn_unsaved = CMD_QUIT; + menu_open(ted, MENU_WARN_UNSAVED); + } else { + // no unsaved changes + ted->quit = true; + } + } break; case CMD_UNDO: if (buffer) buffer_undo(buffer, argument); |