summaryrefslogtreecommitdiff
path: root/menu.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-30 13:55:24 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-30 13:55:24 -0500
commited8a56cc65411b8d00e4a8a9366855ea101f2e27 (patch)
tree654f6c2f1a2241598c96d5755aa0c1088cb890cb /menu.c
parent2994bf93de60930af3855db7a230c27be77de4ef (diff)
better startup, informative message when nothing's open
Diffstat (limited to 'menu.c')
-rw-r--r--menu.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/menu.c b/menu.c
index 8fd0a3b..f979b72 100644
--- a/menu.c
+++ b/menu.c
@@ -20,8 +20,8 @@ static void menu_open(Ted *ted, Menu menu) {
}
}
-static void menu_close(Ted *ted, bool restore_prev_active_buffer) {
- if (restore_prev_active_buffer) ted->active_buffer = ted->prev_active_buffer;
+static void menu_close(Ted *ted) {
+ ted->active_buffer = ted->prev_active_buffer;
ted->prev_active_buffer = NULL;
switch (ted->menu) {
case MENU_NONE: assert(0); break;
@@ -44,7 +44,7 @@ static void menu_escape(Ted *ted) {
*ted->warn_overwrite = 0;
ted->active_buffer = &ted->line_buffer;
} else {
- menu_close(ted, true);
+ menu_close(ted);
}
}
@@ -80,7 +80,7 @@ static void menu_update(Ted *ted, Menu menu) {
if (buffer) {
buffer_save_as(buffer, ted->warn_overwrite);
}
- menu_close(ted, true);
+ menu_close(ted);
} break;
case POPUP_NO:
// back to the file selector
@@ -89,7 +89,7 @@ static void menu_update(Ted *ted, Menu menu) {
break;
case POPUP_CANCEL:
// close "save as" menu
- menu_close(ted, true);
+ menu_close(ted);
break;
}
} else {
@@ -104,7 +104,7 @@ static void menu_update(Ted *ted, Menu menu) {
} else {
// create the new file.
buffer_save_as(buffer, selected_file);
- menu_close(ted, true);
+ menu_close(ted);
}
}
free(selected_file);
@@ -115,10 +115,8 @@ static void menu_update(Ted *ted, Menu menu) {
char *selected_file = file_selector_update(ted, &ted->file_selector);
if (selected_file) {
// open that file!
- if (ted_open_file(ted, selected_file)) {
- menu_close(ted, false);
- file_selector_free(&ted->file_selector);
- }
+ menu_close(ted);
+ ted_open_file(ted, selected_file);
free(selected_file);
}
} break;
@@ -129,7 +127,7 @@ static void menu_update(Ted *ted, Menu menu) {
// save changes
switch (ted->warn_unsaved) {
case CMD_TAB_CLOSE: {
- menu_close(ted, true);
+ menu_close(ted);
TextBuffer *buffer = ted->active_buffer;
command_execute(ted, CMD_SAVE, 1);
if (!buffer_unsaved_changes(buffer)) {
@@ -137,7 +135,7 @@ static void menu_update(Ted *ted, Menu menu) {
}
} break;
case CMD_QUIT:
- menu_close(ted, true);
+ menu_close(ted);
if (ted_save_all(ted)) {
command_execute(ted, CMD_QUIT, 1);
}
@@ -150,11 +148,11 @@ static void menu_update(Ted *ted, Menu menu) {
case POPUP_NO: {
// pass in an argument of 2 to override dialog
Command cmd = ted->warn_unsaved;
- menu_close(ted, true);
+ menu_close(ted);
command_execute(ted, cmd, 2);
} break;
case POPUP_CANCEL:
- menu_close(ted, true);
+ menu_close(ted);
break;
}
break;