| 2276 | } |
| 2277 | |
| 2278 | void bind_command_to_key(command_type cmd, int key) |
| 2279 | { |
| 2280 | KeymapContext context = context_for_command(cmd); |
| 2281 | string command_name = command_to_name(cmd); |
| 2282 | |
| 2283 | if (context == KMC_NONE || command_name == "CMD_NO_CMD" |
| 2284 | || !VALID_BIND_COMMAND(cmd)) |
| 2285 | { |
| 2286 | if (command_name == "CMD_NO_CMD") |
| 2287 | { |
| 2288 | mprf(MSGCH_ERROR, "Cannot bind command #%d to a key.", |
| 2289 | (int) cmd); |
| 2290 | return; |
| 2291 | } |
| 2292 | |
| 2293 | mprf(MSGCH_ERROR, "Cannot bind command '%s' to a key.", |
| 2294 | command_name.c_str()); |
| 2295 | return; |
| 2296 | } |
| 2297 | #ifdef USE_TILE_WEB |
| 2298 | else if ((context == KMC_MENU || context == KMC_MENU_MULTISELECT) |
| 2299 | && tiles.is_controlled_from_web()) |
| 2300 | { |
| 2301 | // disable because they interact badly with webtiles client code. |
| 2302 | // TODO: is there any way to get these to work on webtiles? |
| 2303 | mprf(MSGCH_ERROR, "Ignoring menu bindkey of %s for webtiles client", |
| 2304 | command_name.c_str()); |
| 2305 | return; |
| 2306 | } |
| 2307 | #endif |
| 2308 | |
| 2309 | if (is_userfunction(key)) |
| 2310 | { |
| 2311 | mprf(MSGCH_ERROR, "Cannot bind user function keys to a command."); |
| 2312 | return; |
| 2313 | } |
| 2314 | |
| 2315 | if (is_synthetic_key(key)) |
| 2316 | { |
| 2317 | mprf(MSGCH_ERROR, "Cannot bind synthetic keys to a command."); |
| 2318 | return; |
| 2319 | } |
| 2320 | |
| 2321 | if (!_allow_rebinding(key, context)) |
| 2322 | { |
| 2323 | mprf(MSGCH_ERROR, "Key %d in context %d cannot be rebound.", |
| 2324 | key, (int) context); |
| 2325 | return; |
| 2326 | } |
| 2327 | |
| 2328 | // We're good. |
| 2329 | key_to_cmd_map &key_map = _keys_to_cmds[context]; |
| 2330 | cmd_to_key_map &cmd_map = _cmds_to_keys[context]; |
| 2331 | |
| 2332 | key_map[key] = cmd; |
| 2333 | cmd_map[cmd] = key; |
| 2334 | } |
| 2335 |
no test coverage detected