From d9edd1f62fa620d3a8a42c80aec330065b794e14 Mon Sep 17 00:00:00 2001 From: pommicket Date: Fri, 29 Jul 2022 15:56:32 -0400 Subject: fixed double ctrl+q problem --- command.c | 4 +++- find.c | 2 +- menu.c | 16 +++++++++++----- ted.c | 8 ++++---- ted.cfg | 1 + 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/command.c b/command.c index fc161e2..b55260d 100644 --- a/command.c +++ b/command.c @@ -211,12 +211,13 @@ void command_execute(Ted *ted, Command c, i64 argument) { break; case CMD_QUIT: // pass argument of 2 to override dialog - if (argument == 2) { + if (argument == 2 || ted->warn_unsaved == CMD_QUIT) { 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]; @@ -226,6 +227,7 @@ void command_execute(Ted *ted, Command c, i64 argument) { } } } + if (*ted->warn_unsaved_names) { ted->warn_unsaved = CMD_QUIT; menu_open(ted, MENU_WARN_UNSAVED); diff --git a/find.c b/find.c index d5cdfce..f85255c 100644 --- a/find.c +++ b/find.c @@ -122,7 +122,7 @@ static WarnUnusedResult bool find_match(Ted *ted, BufferPos *pos, u32 *match_sta } // check if the search term needs to be recompiled -static void find_update(Ted *ted, bool force) { +void find_update(Ted *ted, bool force) { TextBuffer *find_buffer = &ted->find_buffer; u32 flags = find_compilation_flags(ted); if (!force diff --git a/menu.c b/menu.c index ae69eac..5a0e964 100644 --- a/menu.c +++ b/menu.c @@ -1,4 +1,4 @@ -static void menu_close(Ted *ted) { +static void menu_close_with_next(Ted *ted, Menu next) { ted_switch_to_buffer(ted, ted->prev_active_buffer); TextBuffer *buffer = ted->active_buffer; ted->prev_active_buffer = NULL; @@ -14,8 +14,10 @@ static void menu_close(Ted *ted) { buffer_clear(&ted->line_buffer); break; case MENU_WARN_UNSAVED: - ted->warn_unsaved = 0; - *ted->warn_unsaved_names = 0; + if (next != MENU_WARN_UNSAVED) { + ted->warn_unsaved = 0; + *ted->warn_unsaved_names = 0; + } break; case MENU_ASK_RELOAD: *ted->ask_reload = 0; @@ -40,9 +42,13 @@ static void menu_close(Ted *ted) { ted->selector_open = NULL; } -static void menu_open(Ted *ted, Menu menu) { +void menu_close(Ted *ted) { + menu_close_with_next(ted, 0); +} + +void menu_open(Ted *ted, Menu menu) { if (ted->menu) - menu_close(ted); + menu_close_with_next(ted, menu); if (ted->find) find_close(ted); ted->autocomplete = false; ted->menu = menu; diff --git a/ted.c b/ted.c index 9bff01a..f79ca89 100644 --- a/ted.c +++ b/ted.c @@ -1,7 +1,7 @@ -static void menu_open(Ted *ted, Menu menu); -static void menu_close(Ted *ted); -static void find_update(Ted *ted, bool force); -static Command command_from_str(char const *str); +void menu_open(Ted *ted, Menu menu); +void menu_close(Ted *ted); +void find_update(Ted *ted, bool force); +Command command_from_str(char const *str); // this is a macro so we get -Wformat warnings #define ted_seterr(ted, ...) \ diff --git a/ted.cfg b/ted.cfg index b4ede62..448c936 100644 --- a/ted.cfg +++ b/ted.cfg @@ -29,6 +29,7 @@ auto-reload-config = on build-default-command = make # restore previously opened files when ted is launched? restore-session = on + # search depth for files to generate tags for. # if set to 0, tag generation/regeneration will do nothing tags-max-depth = 2 -- cgit v1.2.3