1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Factor deselect_mainmenu out of select_menu_item, do_mainmenu,

mainmenu_mouse_handler, and mainmenu_kbd_handler
This commit is contained in:
Miciah Dashiel Butler Masters 2006-06-02 03:57:53 +00:00 committed by Miciah Dashiel Butler Masters
parent cdcc8c8415
commit f271a06487

View File

@ -64,6 +64,14 @@ static void display_mainmenu(struct terminal *term, struct menu *menu);
static void set_menu_selection(struct menu *menu, int pos); static void set_menu_selection(struct menu *menu, int pos);
static void
deselect_mainmenu(struct terminal *term, struct menu *menu)
{
menu->selected = -1;
del_from_list(menu->win);
add_to_list_end(term->windows, menu->win);
}
static inline int static inline int
count_items(struct menu_item *items) count_items(struct menu_item *items)
{ {
@ -149,11 +157,7 @@ select_menu_item(struct terminal *term, struct menu_item *it, void *data)
break; break;
if (win->handler == mainmenu_handler) { if (win->handler == mainmenu_handler) {
struct menu *menu = win->data; deselect_mainmenu(term, win->data);
menu->selected = -1;
del_from_list(win);
add_to_list_end(term->windows, win);
redraw_terminal(term); redraw_terminal(term);
} else } else
delete_window(win); delete_window(win);
@ -929,15 +933,13 @@ do_mainmenu(struct terminal *term, struct menu_item *items,
#endif #endif
init_hotkeys(term, menu); init_hotkeys(term, menu);
if (init) { if (init) {
menu->selected = -1;
add_window(term, mainmenu_handler, menu); add_window(term, mainmenu_handler, menu);
win = menu->win; win = menu->win;
/* This should be fine because add_window will call /* This should be fine because add_window will call
* mainmenu_handler which will assign the window to menu->win. * mainmenu_handler which will assign the window to menu->win.
*/ */
assert(win); assert(win);
del_from_list(win); deselect_mainmenu(term, menu);
add_to_list_end(term->windows, win);
} else { } else {
foreach (win, term->windows) { foreach (win, term->windows) {
if (win->data == menu) { if (win->data == menu) {
@ -1067,9 +1069,7 @@ mainmenu_mouse_handler(struct menu *menu, struct term_event *ev)
/* Mouse was clicked outside the mainmenu bar */ /* Mouse was clicked outside the mainmenu bar */
if (ev->info.mouse.y) { if (ev->info.mouse.y) {
if (check_mouse_action(ev, B_DOWN)) { if (check_mouse_action(ev, B_DOWN)) {
del_from_list(win); deselect_mainmenu(win->term, menu);
add_to_list_end(win->term->windows, win);
menu->selected = -1;
} }
return; return;
} }
@ -1174,9 +1174,7 @@ mainmenu_kbd_handler(struct menu *menu, struct term_event *ev)
} }
case ACT_MENU_CANCEL: case ACT_MENU_CANCEL:
menu->selected = -1; deselect_mainmenu(win->term, menu);
del_from_list(win);
add_to_list_end(win->term->windows, win);
break; break;
} }