diff options
author | William Wilgus <wilgus.william@gmail.com> | 2022-02-24 00:26:40 -0500 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2022-02-24 00:26:40 -0500 |
commit | bba0564ec161fd23f614b4c4da00da4a5e414615 (patch) | |
tree | 01b3b44b1a2505d57c34caa3ee7afaf4a4c2a480 /apps/plugins | |
parent | 295ec3790d191c41006d04b41db878dc1091b117 (diff) | |
download | rockbox-bba0564ec161fd23f614b4c4da00da4a5e414615.tar.gz rockbox-bba0564ec161fd23f614b4c4da00da4a5e414615.zip |
keyremap plugin use yes_no prompts, bugfix
use the supplied yes_no dialogs for file delete, key reset, save prompt
return to root menu automatically after loading a file
fix bug where deleting the last file in the list exited the menu
Change-Id: Ib98f6b200b9dee3e4350ad4d7ef80bbb95c77481
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/keyremap.c | 54 |
1 files changed, 22 insertions, 32 deletions
diff --git a/apps/plugins/keyremap.c b/apps/plugins/keyremap.c index 593dc5a3b0..0a6b705e9d 100644 --- a/apps/plugins/keyremap.c +++ b/apps/plugins/keyremap.c | |||
@@ -130,7 +130,7 @@ MENU_ITEM(M_LOADKEYS, "Load Keymaps", 1), | |||
130 | MENU_ITEM(M_DELKEYS, "Delete Keymaps", 1), | 130 | MENU_ITEM(M_DELKEYS, "Delete Keymaps", 1), |
131 | MENU_ITEM(M_TMPCORE, "Temp Core Remap", 1), | 131 | MENU_ITEM(M_TMPCORE, "Temp Core Remap", 1), |
132 | MENU_ITEM(M_SETCORE, "Set Core Remap", 1), | 132 | MENU_ITEM(M_SETCORE, "Set Core Remap", 1), |
133 | MENU_ITEM(M_DELCORE, "Delete Core Remap", 1), | 133 | MENU_ITEM(M_DELCORE, "Remove Core Remap", 1), |
134 | MENU_ITEM(M_EXIT, ID2P(LANG_MENU_QUIT), 0), | 134 | MENU_ITEM(M_EXIT, ID2P(LANG_MENU_QUIT), 0), |
135 | MENU_ITEM(M_ACTIONS, "Actions", LAST_ACTION_PLACEHOLDER), | 135 | MENU_ITEM(M_ACTIONS, "Actions", LAST_ACTION_PLACEHOLDER), |
136 | MENU_ITEM(M_BUTTONS, "Buttons", -1), /* Set at runtime in plugin_start: */ | 136 | MENU_ITEM(M_BUTTONS, "Buttons", -1), /* Set at runtime in plugin_start: */ |
@@ -578,6 +578,8 @@ static int keyremap_load_file(const char *filename) | |||
578 | if (offset == 0 || entries <= 0) | 578 | if (offset == 0 || entries <= 0) |
579 | { | 579 | { |
580 | logf("keyremap: error reading offset"); | 580 | logf("keyremap: error reading offset"); |
581 | count = -15; | ||
582 | goto fail; | ||
581 | } | 583 | } |
582 | logf("keyremap found context: %d file offset: %d entries: %d", | 584 | logf("keyremap found context: %d file offset: %d entries: %d", |
583 | context, offset, entries); | 585 | context, offset, entries); |
@@ -591,18 +593,18 @@ static int keyremap_load_file(const char *filename) | |||
591 | bytes = rb->read(fd, &entry, sizeof(struct button_mapping)); | 593 | bytes = rb->read(fd, &entry, sizeof(struct button_mapping)); |
592 | if (bytes == sizeof(struct button_mapping)) | 594 | if (bytes == sizeof(struct button_mapping)) |
593 | { | 595 | { |
594 | int action = entry.action_code; | 596 | int act = entry.action_code; |
595 | int button = entry.button_code; | 597 | int button = entry.button_code; |
596 | int prebtn = entry.pre_button_code; | 598 | int prebtn = entry.pre_button_code; |
597 | 599 | ||
598 | if (action == (int)CONTEXT_STOPSEARCHING || button == BUTTON_NONE) | 600 | if (act == (int)CONTEXT_STOPSEARCHING || button == BUTTON_NONE) |
599 | { | 601 | { |
600 | logf("keyremap: entry invalid"); | 602 | logf("keyremap: entry invalid"); |
601 | goto fail; | 603 | goto fail; |
602 | } | 604 | } |
603 | logf("keyremap: found ctx: %d, act: %d btn: %d pbtn: %d", | 605 | logf("keyremap: found ctx: %d, act: %d btn: %d pbtn: %d", |
604 | context, action, button, prebtn); | 606 | context, act, button, prebtn); |
605 | keymap_add_button_entry(context, action, button, prebtn); | 607 | keymap_add_button_entry(context, act, button, prebtn); |
606 | } | 608 | } |
607 | else | 609 | else |
608 | goto fail; | 610 | goto fail; |
@@ -958,13 +960,7 @@ int menu_action_root(int *action, int selected_item, bool* exit, struct gui_sync | |||
958 | } | 960 | } |
959 | else if (cur->menuid == MENU_ID(M_RESETKEYS)) | 961 | else if (cur->menuid == MENU_ID(M_RESETKEYS)) |
960 | { | 962 | { |
961 | rb->splashf(HZ / 2, "Delete Current?"); | 963 | if (rb->yesno_pop("Delete Current Entries?") == true) |
962 | int usract = ACTION_NONE; | ||
963 | while (usract <= ACTION_UNKNOWN) | ||
964 | { | ||
965 | usract = rb->get_action(CONTEXT_STD, HZ / 10); | ||
966 | } | ||
967 | if (usract == ACTION_STD_OK) | ||
968 | { | 964 | { |
969 | keyremap_reset_buffer(); | 965 | keyremap_reset_buffer(); |
970 | } | 966 | } |
@@ -1051,9 +1047,9 @@ int menu_action_setkeys(int *action, int selected_item, bool* exit, struct gui_s | |||
1051 | if (ctx_data.act_map[i].display_pos == selected_item - 1) | 1047 | if (ctx_data.act_map[i].display_pos == selected_item - 1) |
1052 | { | 1048 | { |
1053 | int context = ctx_data.act_map[i].context; | 1049 | int context = ctx_data.act_map[i].context; |
1054 | int action = ctx_data.act_map[i].map.action_code; | 1050 | int act = ctx_data.act_map[i].map.action_code; |
1055 | int button = ctx_data.act_map[i].map.button_code; | 1051 | int button = ctx_data.act_map[i].map.button_code; |
1056 | int prebtn = ctx_data.act_map[i].map.pre_button_code; | 1052 | int prebtn = ctx_data.act_map[i].map.pre_button_code; |
1057 | 1053 | ||
1058 | if (col < 0) | 1054 | if (col < 0) |
1059 | { | 1055 | { |
@@ -1071,7 +1067,7 @@ int menu_action_setkeys(int *action, int selected_item, bool* exit, struct gui_s | |||
1071 | else if (col == 1) /* Action */ | 1067 | else if (col == 1) /* Action */ |
1072 | { | 1068 | { |
1073 | const struct mainmenu *mainm = &mainmenu[M_ACTIONS]; | 1069 | const struct mainmenu *mainm = &mainmenu[M_ACTIONS]; |
1074 | synclist_set_update(mainm->index, action, mainm->items, 1); | 1070 | synclist_set_update(mainm->index, act, mainm->items, 1); |
1075 | rb->gui_synclist_draw(lists); | 1071 | rb->gui_synclist_draw(lists); |
1076 | goto default_handler; | 1072 | goto default_handler; |
1077 | } | 1073 | } |
@@ -1203,23 +1199,23 @@ int menu_action_listfiles(int *action, int selected_item, bool* exit, struct gui | |||
1203 | 1199 | ||
1204 | if (lists->data == MENU_ID(M_DELKEYS)) | 1200 | if (lists->data == MENU_ID(M_DELKEYS)) |
1205 | { | 1201 | { |
1206 | rb->splashf(HZ / 2, "Delete %s ?", buf); | 1202 | const char *lines[] = {ID2P(LANG_DELETE), buf}; |
1207 | int action = ACTION_NONE; | 1203 | const struct text_message message={lines, 2}; |
1208 | while (action <= ACTION_UNKNOWN) | 1204 | if (rb->gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES) |
1209 | { | ||
1210 | action = rb->get_action(CONTEXT_STD, HZ / 10); | ||
1211 | } | ||
1212 | if (action == ACTION_STD_OK) | ||
1213 | { | 1205 | { |
1214 | rb->remove(buf); | 1206 | rb->remove(buf); |
1215 | cur->items--; | 1207 | cur->items--; |
1216 | lists->nb_items--; | 1208 | lists->nb_items--; |
1209 | *action = ACTION_NONE; | ||
1217 | } | 1210 | } |
1218 | } | 1211 | } |
1219 | else if (lists->data == MENU_ID(M_LOADKEYS)) | 1212 | else if (lists->data == MENU_ID(M_LOADKEYS)) |
1220 | { | 1213 | { |
1221 | keyremap_load_file(buf); | 1214 | if (keyremap_load_file(buf) > 0) |
1222 | rb->splashf(HZ * 2, "Loaded %s ", buf); | 1215 | { |
1216 | rb->splashf(HZ * 2, "Loaded %s ", buf); | ||
1217 | *action = ACTION_STD_CANCEL; | ||
1218 | } | ||
1223 | } | 1219 | } |
1224 | } | 1220 | } |
1225 | } | 1221 | } |
@@ -1425,13 +1421,7 @@ int menu_action_cb(int *action, int selected_item, bool* exit, struct gui_syncli | |||
1425 | if (keymap != NULL && keyset.crc32 != rb->crc_32(keymap, | 1421 | if (keymap != NULL && keyset.crc32 != rb->crc_32(keymap, |
1426 | entries * sizeof(struct button_mapping), 0xFFFFFFFF)) | 1422 | entries * sizeof(struct button_mapping), 0xFFFFFFFF)) |
1427 | { | 1423 | { |
1428 | rb->splashf(HZ / 2, "Save?"); | 1424 | if (rb->yesno_pop("Save Keymap?") == true) |
1429 | int action = ACTION_NONE; | ||
1430 | while (action <= ACTION_UNKNOWN) | ||
1431 | { | ||
1432 | action = rb->get_action(CONTEXT_STD, HZ / 10); | ||
1433 | } | ||
1434 | if (action == ACTION_STD_OK) | ||
1435 | { | 1425 | { |
1436 | keyremap_save_user_keys(true); | 1426 | keyremap_save_user_keys(true); |
1437 | goto default_handler; | 1427 | goto default_handler; |