From 8f0cd8f3f680186a08fcccf616db7546099db8a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonathan=20Neusch=C3=A4fer?= Date: Sat, 24 Dec 2011 18:28:06 +0100 Subject: [PATCH] screen_keydef: better distinction of adding and replacing keys --- src/screen_keydef.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/screen_keydef.c b/src/screen_keydef.c index 92c5d3c..87c5067 100644 --- a/src/screen_keydef.c +++ b/src/screen_keydef.c @@ -189,13 +189,16 @@ delete_key(int cmd_index, int key_index) check_key_bindings(cmds, NULL, 0); } +/* assigns a new key to a key slot */ static void -assign_new_key(int cmd_index, int key_index) +overwrite_key(int cmd_index, int key_index) { int key; char *buf; command_t cmd; + assert(key_index < MAX_COMMAND_KEYS); + buf = g_strdup_printf(_("Enter new key for %s: "), cmds[cmd_index].name); key = screen_getch(buf); g_free(buf); @@ -228,6 +231,14 @@ assign_new_key(int cmd_index, int key_index) check_key_bindings(cmds, NULL, 0); } +/* assign a new key to a new slot */ +static void +add_key(int cmd_index) +{ + if (subcmd_n_keys < MAX_COMMAND_KEYS) + overwrite_key(cmd_index, subcmd_n_keys); +} + static const char * list_callback(unsigned idx, G_GNUC_UNUSED void *data) { @@ -381,10 +392,12 @@ keydef_cmd(G_GNUC_UNUSED struct mpdclient *c, command_t cmd) subcmd = -1; keydef_repaint(); + } else if (lw->selected == subcmd_item_add) { + add_key(subcmd); } else { - /* TODO: subcmd_item_add should be handled - separately, just for clarity */ - assign_new_key(subcmd, subcmd_item_to_key_id(lw->selected)); + /* just to be sure ;-) */ + assert(subcmd_item_is_key(lw->selected)); + overwrite_key(subcmd, subcmd_item_to_key_id(lw->selected)); } } return true; -- 2.30.2