From: Jonathan Neuschäfer Date: Sat, 24 Dec 2011 17:28:06 +0000 (+0100) Subject: screen_keydef: better distinction of adding and replacing keys X-Git-Tag: release-0.20~16 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8f0cd8f3f680186a08fcccf616db7546099db8a3;p=ncmpc.git screen_keydef: better distinction of adding and replacing keys --- 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;