From cd83fa0ac7831932eae9c3051c55e1da88e71108 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonathan=20Neusch=C3=A4fer?= Date: Wed, 28 Dec 2011 23:04:36 +0100 Subject: [PATCH] screen_keydef: split out code to switch views --- src/screen_keydef.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/screen_keydef.c b/src/screen_keydef.c index 87c5067..0836964 100644 --- a/src/screen_keydef.c +++ b/src/screen_keydef.c @@ -159,6 +159,30 @@ keydef_repaint(void) wrefresh(lw->w); } +static void +switch_to_subcmd_mode(int cmd) +{ + assert(subcmd == -1); + + subcmd = cmd; + list_window_reset(lw); + check_subcmd_length(); + + keydef_repaint(); +} + +static void +switch_to_command_mode(void) +{ + assert(subcmd != -1); + + list_window_set_length(lw, command_length); + list_window_set_cursor(lw, subcmd); + subcmd = -1; + + keydef_repaint(); +} + /** * Delete a key from a given command's definition * @param cmd_index the command @@ -379,19 +403,11 @@ keydef_cmd(G_GNUC_UNUSED struct mpdclient *c, command_t cmd) apply_keys(); save_keys(); } else { - subcmd = lw->selected; - list_window_reset(lw); - check_subcmd_length(); - - keydef_repaint(); + switch_to_subcmd_mode(lw->selected); } } else { if (lw->selected == subcmd_item_up) { - list_window_set_length(lw, command_length); - list_window_set_cursor(lw, subcmd); - subcmd = -1; - - keydef_repaint(); + switch_to_command_mode(); } else if (lw->selected == subcmd_item_add) { add_key(subcmd); } else { @@ -402,13 +418,8 @@ keydef_cmd(G_GNUC_UNUSED struct mpdclient *c, command_t cmd) } return true; case CMD_GO_PARENT_DIRECTORY: - if (subcmd != -1) { - list_window_set_length(lw, command_length); - list_window_set_cursor(lw, subcmd); - subcmd = -1; - - keydef_repaint(); - } + if (subcmd != -1) + switch_to_command_mode(); return true; case CMD_DELETE: if (subcmd != -1 && subcmd_item_is_key(lw->selected)) -- 2.30.2