summaryrefslogtreecommitdiff
path: root/command.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-30 11:52:25 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-30 11:52:25 -0500
commita61d90c32d4d6448148894872ebd91eb8f10fc2e (patch)
tree44d24f9b86064ba6ff706e4700865ebea65521a2 /command.c
parent55fd631d86769e719f81206901bc1c3fb598fb5e (diff)
warn when closing tab with unsaved changes
Diffstat (limited to 'command.c')
-rw-r--r--command.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/command.c b/command.c
index 5acd922..a7ff287 100644
--- a/command.c
+++ b/command.c
@@ -111,6 +111,7 @@ void command_execute(Ted *ted, Command c, i64 argument) {
case MENU_SAVE_AS: {
ted->file_selector.submitted = true;
} break;
+ case MENU_WARN_UNSAVED: break;
}
} else {
buffer_newline(buffer);
@@ -173,8 +174,7 @@ void command_execute(Ted *ted, Command c, i64 argument) {
break;
case CMD_CUT:
if (buffer) buffer_cut(buffer);
- break;
- case CMD_PASTE:
+ break; case CMD_PASTE:
if (buffer) buffer_paste(buffer);
break;
@@ -194,12 +194,26 @@ void command_execute(Ted *ted, Command c, i64 argument) {
} break;
case CMD_TAB_CLOSE: {
- Node *node = ted->active_node;
- if (node) {
- node_tab_close(ted, node, node->active_tab);
+ if (ted->menu) {
+ menu_close(ted, true);
} else {
- command_execute(ted, CMD_QUIT, 1);
- return;
+ Node *node = ted->active_node;
+ if (node) {
+ u16 tab_idx = node->active_tab;
+ buffer = &ted->buffers[node->tabs[tab_idx]];
+ // (an argument of 2 overrides the unsaved changes dialog)
+ if (argument != 2 && buffer_unsaved_changes(buffer)) {
+ // there are unsaved changes!
+ ted->warn_unsaved = CMD_TAB_CLOSE;
+ strbuf_printf(ted->warn_unsaved_names, "%s", path_filename(buffer->filename));
+ menu_open(ted, MENU_WARN_UNSAVED);
+ } else {
+ node_tab_close(ted, node, node->active_tab);
+ }
+ } else {
+ command_execute(ted, CMD_QUIT, 1);
+ return;
+ }
}
} break;
case CMD_TAB_NEXT: