ref: 183aa6f0638aea9243f1ffba8d26e720bbd0b6f3
parent: a6dc6dfeb77d7aabbbb07b71c294762a7d2009c4
author: cancel <cancel@cancel.fm>
date: Thu Dec 13 20:44:11 EST 2018
Cleanup
--- a/term_util.c
+++ b/term_util.c
@@ -237,3 +237,13 @@
}
Qmenu* qmenu_of(Qblock* qb) { return ORCA_CONTAINER_OF(qb, Qmenu, qblock); }
+
+bool qmenu_top_is_menu(int id) {
+ Qblock* qb = qnav_top_block();
+ if (!qb)
+ return false;
+ if (qb->tag != Qblock_type_qmenu)
+ return false;
+ Qmenu* qm = qmenu_of(qb);
+ return qm->id == id;
+}
--- a/term_util.h
+++ b/term_util.h
@@ -95,6 +95,7 @@
void qblock_print_frame(Qblock* qb, bool active);
void qblock_set_title(Qblock* qb, char const* title);
+
Qmsg* qmsg_push(int height, int width);
WINDOW* qmsg_window(Qmsg* qm);
void qmsg_set_title(Qmsg* qm, char const* title);
@@ -107,5 +108,6 @@
void qmenu_push_to_nav(Qmenu* qm);
bool qmenu_drive(Qmenu* qm, int key, Qmenu_action* out_action);
Qmenu* qmenu_of(Qblock* qb);
+bool qmenu_top_is_menu(int id);
extern Qnav_stack qnav_stack;
--- a/tui_main.c
+++ b/tui_main.c
@@ -1834,6 +1834,13 @@
case Qblock_type_qmenu: {
Qmenu* qm = qmenu_of(qb);
Qmenu_action act;
+ // special case for main menu: pressing the key to open it will close
+ // it again.
+ if (qm->id == Main_menu_id &&
+ (key == CTRL_PLUS('d') || key == KEY_F(1))) {
+ qnav_stack_pop();
+ break;
+ }
if (qmenu_drive(qm, key, &act)) {
switch (act.any.type) {
case Qmenu_action_type_canceled: {
@@ -1974,21 +1981,15 @@
break;
case CTRL_PLUS('d'):
- case KEY_F(1): {
- if (qnav_top_block()) {
- qnav_stack_pop();
- } else {
- push_main_menu();
- }
- } break;
-
+ case KEY_F(1):
+ push_main_menu();
+ break;
case '?':
push_controls_msg();
break;
-
- case CTRL_PLUS('s'): {
+ case CTRL_PLUS('s'):
try_save_with_msg(&ged_state);
- } break;
+ break;
default:
if (key >= CHAR_MIN && key <= CHAR_MAX && is_valid_glyph((Glyph)key)) {