ref: d1c44aac44622ad6a2baa6cf3daa69cb3f5dcf95
parent: 96897adad83661f17380bbab6d2a72faee3a38b1
author: cancel <cancel@cancel.fm>
date: Sat Jan 4 20:51:39 EST 2020
Add confirmation dialog to create new file
--- a/tui_main.c
+++ b/tui_main.c
@@ -1846,6 +1846,7 @@
Set_tempo_form_id,
Set_grid_dims_form_id,
Autofit_menu_id,
+ Confirm_new_file_menu_id,
};
enum {
Open_name_text_line_id = 1,
@@ -1864,6 +1865,10 @@
Autofit_tightly_id,
};
enum {
+ Confirm_new_file_reject_id = 1,
+ Confirm_new_file_accep_id,
+};
+enum {
Main_menu_quit = 1,
Main_menu_controls,
Main_menu_opers_guide,
@@ -1904,6 +1909,14 @@
qnav_stack_pop();
}
+void push_confirm_new_file_menu(void) {
+ Qmenu* qm = qmenu_create(Confirm_new_file_menu_id);
+ qmenu_set_title(qm, "Are you sure?");
+ qmenu_add_choice(qm, "Cancel", Confirm_new_file_reject_id);
+ qmenu_add_choice(qm, "Create New File", Confirm_new_file_accep_id);
+ qmenu_push_to_nav(qm);
+}
+
void push_autofit_menu(void) {
Qmenu* qm = qmenu_create(Autofit_menu_id);
qmenu_set_title(qm, "Auto-fit Grid");
@@ -2798,32 +2811,9 @@
case Main_menu_about:
push_about_msg();
break;
- case Main_menu_new: {
- Usz new_field_h, new_field_w;
- if (ged_suggest_nice_grid_size(ged_state.win_h, ged_state.win_w,
- ged_state.softmargin_y,
- ged_state.softmargin_x,
- (int)ged_state.ruler_spacing_y,
- (int)ged_state.ruler_spacing_x,
- &new_field_h, &new_field_w)) {
- undo_history_push(&ged_state.undo_hist, &ged_state.field,
- ged_state.tick_num);
- field_resize_raw(&ged_state.field, new_field_h, new_field_w);
- memset(ged_state.field.buffer, '.',
- new_field_h * new_field_w * sizeof(Glyph));
- ged_cursor_confine(&ged_state.ged_cursor, new_field_h,
- new_field_w);
- mbuf_reusable_ensure_size(&ged_state.mbuf_r, new_field_h,
- new_field_w);
- ged_update_internal_geometry(&ged_state);
- ged_make_cursor_visible(&ged_state);
- ged_state.needs_remarking = true;
- ged_state.is_draw_dirty = true;
- heapstr_set_cstr(&file_name, "");
- ged_state.filename = "unnamed"; // slightly redundant
- pop_qnav_if_main_menu();
- }
- } break;
+ case Main_menu_new:
+ push_confirm_new_file_menu();
+ break;
case Main_menu_open:
push_open_form(file_name.str);
break;
@@ -2876,6 +2866,39 @@
}
qnav_stack_pop();
pop_qnav_if_main_menu();
+ } else if (qmenu_id(qm) == Confirm_new_file_menu_id) {
+ switch (act.picked.id) {
+ case Confirm_new_file_reject_id:
+ qnav_stack_pop();
+ break;
+ case Confirm_new_file_accep_id: {
+ Usz new_field_h, new_field_w;
+ if (ged_suggest_nice_grid_size(ged_state.win_h, ged_state.win_w,
+ ged_state.softmargin_y,
+ ged_state.softmargin_x,
+ (int)ged_state.ruler_spacing_y,
+ (int)ged_state.ruler_spacing_x,
+ &new_field_h, &new_field_w)) {
+ undo_history_push(&ged_state.undo_hist, &ged_state.field,
+ ged_state.tick_num);
+ field_resize_raw(&ged_state.field, new_field_h, new_field_w);
+ memset(ged_state.field.buffer, '.',
+ new_field_h * new_field_w * sizeof(Glyph));
+ ged_cursor_confine(&ged_state.ged_cursor, new_field_h,
+ new_field_w);
+ mbuf_reusable_ensure_size(&ged_state.mbuf_r, new_field_h,
+ new_field_w);
+ ged_update_internal_geometry(&ged_state);
+ ged_make_cursor_visible(&ged_state);
+ ged_state.needs_remarking = true;
+ ged_state.is_draw_dirty = true;
+ heapstr_set_cstr(&file_name, "");
+ ged_state.filename = "unnamed"; // slightly redundant
+ qnav_stack_pop();
+ pop_qnav_if_main_menu();
+ }
+ } break;
+ }
}
} break;
}