Code

screen_keydef: better distinction of adding and replacing keys
authorJonathan Neuschäfer <j.neuschaefer@gmx.net>
Sat, 24 Dec 2011 17:28:06 +0000 (18:28 +0100)
committerJonathan Neuschäfer <j.neuschaefer@gmx.net>
Sat, 24 Dec 2011 17:28:06 +0000 (18:28 +0100)
src/screen_keydef.c

index 92c5d3c1ed037a8cbb07bfd4398729b2aeb1e8dc..87c5067c301864539b1cd56b94e0f3678f737f27 100644 (file)
@@ -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;