Hotkeys: properly named hotkey_command id and command members

This commit is contained in:
Charles Dang 2022-05-24 01:57:27 -04:00
parent bd663177d2
commit 776a127c57
12 changed files with 59 additions and 64 deletions

View file

@ -1150,7 +1150,7 @@ namespace { // Private helpers for move_unit()
// Suggest "continue move"?
if ( playing_team_is_viewing_ && sighted_stop_ && !resources::whiteboard->is_executing_actions() ) {
// See if the "Continue Move" action has an associated hotkey
std::string name = hotkey::get_names(hotkey::hotkey_command::get_command_by_command(hotkey::HOTKEY_CONTINUE_MOVE).command);
std::string name = hotkey::get_names(hotkey::hotkey_command::get_command_by_command(hotkey::HOTKEY_CONTINUE_MOVE).id);
if ( !name.empty() ) {
utils::string_map symbols;
symbols["hotkey"] = name;

View file

@ -452,7 +452,7 @@ void controller_base::show_menu(
const std::string& id = c["id"];
const hotkey::hotkey_command& command = hotkey::get_hotkey_command(id);
if(cmd_exec->can_execute_command(command) && (!context_menu || in_context_menu(command.id))) {
if(cmd_exec->can_execute_command(command) && (!context_menu || in_context_menu(command.command))) {
items.emplace_back("id", id);
}
}

View file

@ -239,7 +239,7 @@ void editor_controller::custom_tods_dialog()
bool editor_controller::can_execute_command(const hotkey::hotkey_command& cmd, int index) const
{
using namespace hotkey; //reduce hotkey:: clutter
switch (cmd.id) {
switch(cmd.command) {
case HOTKEY_NULL:
if (index >= 0) {
unsigned i = static_cast<unsigned>(index);
@ -587,7 +587,7 @@ hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND
bool editor_controller::do_execute_command(const hotkey::hotkey_command& cmd, int index, bool press, bool release)
{
hotkey::HOTKEY_COMMAND command = cmd.id;
hotkey::HOTKEY_COMMAND command = cmd.command;
SCOPE_ED;
using namespace hotkey;
@ -1011,8 +1011,8 @@ void editor_controller::show_menu(const std::vector<config>& items_arg, int xloc
const std::string& id = c["id"];
const hotkey::hotkey_command& command = hotkey::get_hotkey_command(id);
if((can_execute_command(command) && (!context_menu || in_context_menu(command.id)))
|| command.id == hotkey::HOTKEY_NULL)
if((can_execute_command(command) && (!context_menu || in_context_menu(command.command)))
|| command.command == hotkey::HOTKEY_NULL)
{
items.emplace_back("id", id);
}

View file

@ -755,7 +755,7 @@ void preferences_dialog::post_build(window& window)
hotkey_list.register_translatable_sorting_option(0, [this](const int i) { return visible_hotkeys_[i]->description.str(); });
// Hotkey column
hotkey_list.register_sorting_option(1, [this](const int i) { return hotkey::get_names(visible_hotkeys_[i]->command); });
hotkey_list.register_sorting_option(1, [this](const int i) { return hotkey::get_names(visible_hotkeys_[i]->id); });
// Scope columns
hotkey_list.register_sorting_option(2, [this](const int i) { return !visible_hotkeys_[i]->scope[hotkey::SCOPE_GAME]; });
@ -815,14 +815,14 @@ listbox& preferences_dialog::setup_hotkey_list()
}
visible_hotkeys_.push_back(&hotkey_item);
if(filesystem::file_exists(game_config::path + "/images/icons/action/" + hotkey_item.command + "_25.png")) {
row_icon = "icons/action/" + hotkey_item.command + "_25.png~CROP(3,3,18,18)";
if(filesystem::file_exists(game_config::path + "/images/icons/action/" + hotkey_item.id + "_25.png")) {
row_icon = "icons/action/" + hotkey_item.id + "_25.png~CROP(3,3,18,18)";
} else {
row_icon = default_icon;
}
row_action = hotkey_item.description;
row_hotkey = hotkey::get_names(hotkey_item.command);
row_hotkey = hotkey::get_names(hotkey_item.id);
row_is_g = hotkey_item.scope[hotkey::SCOPE_GAME] ? text_game_feature_on : "";
row_is_g_markup = "true";
@ -847,7 +847,7 @@ void preferences_dialog::add_hotkey_callback(listbox& hotkeys)
const hotkey::hotkey_command& hotkey_item = *visible_hotkeys_[row_number];
gui2::dialogs::hotkey_bind bind_dlg(hotkey_item.command);
gui2::dialogs::hotkey_bind bind_dlg(hotkey_item.id);
bind_dlg.show();
hotkey::hotkey_ptr newhk = bind_dlg.get_new_binding();
@ -867,7 +867,7 @@ void preferences_dialog::add_hotkey_callback(listbox& hotkeys)
hotkey::scope_changer scope_restorer;
hotkey::set_active_scopes(hotkey_item.scope);
if(oldhk && oldhk->get_command() == hotkey_item.command) {
if(oldhk && oldhk->get_command() == hotkey_item.id) {
return;
}
@ -889,7 +889,7 @@ void preferences_dialog::add_hotkey_callback(listbox& hotkeys)
// We need to recalculate all hotkey names in because we might have removed a hotkey from another command.
for(std::size_t i = 0; i < hotkeys.get_item_count(); ++i) {
const hotkey::hotkey_command& hotkey_item_row = *visible_hotkeys_[i];
find_widget<label>(hotkeys.get_row_grid(i), "lbl_hotkey", false).set_label(hotkey::get_names(hotkey_item_row.command));
find_widget<label>(hotkeys.get_row_grid(i), "lbl_hotkey", false).set_label(hotkey::get_names(hotkey_item_row.id));
}
}
@ -916,8 +916,8 @@ void preferences_dialog::remove_hotkey_callback(listbox& hotkeys)
}
const hotkey::hotkey_command& hotkey_item = *visible_hotkeys_[row_number];
hotkey::clear_hotkeys(hotkey_item.command);
find_widget<label>(hotkeys.get_row_grid(row_number), "lbl_hotkey", false).set_label(hotkey::get_names(hotkey_item.command));
hotkey::clear_hotkeys(hotkey_item.id);
find_widget<label>(hotkeys.get_row_grid(row_number), "lbl_hotkey", false).set_label(hotkey::get_names(hotkey_item.id));
}
void preferences_dialog::hotkey_filter_callback() const

View file

@ -530,7 +530,7 @@ void styled_widget::signal_handler_show_tooltip(const event::ui_event event,
utils::string_map symbols;
symbols["hotkey"] = hotkey::get_names(
hotkey::hotkey_command::get_command_by_command(
hotkey::GLOBAL__HELPTIP).command);
hotkey::GLOBAL__HELPTIP).id);
tip = tooltip_ + utils::interpolate_variables_into_string(
settings::has_helptip_message, &symbols);

View file

@ -72,7 +72,7 @@ bool command_executor::do_execute_command(const hotkey_command& cmd, int /*inde
{
// hotkey release handling
if (release) {
switch(cmd.id) {
switch(cmd.command) {
// release a scroll key, un-apply scrolling in the given direction
case HOTKEY_SCROLL_UP:
scroll_up(false);
@ -94,7 +94,7 @@ bool command_executor::do_execute_command(const hotkey_command& cmd, int /*inde
}
// handling of hotkeys which activate even on hold events
switch(cmd.id) {
switch(cmd.command) {
case HOTKEY_REPEAT_RECRUIT:
repeat_recruit();
return true;
@ -119,7 +119,7 @@ bool command_executor::do_execute_command(const hotkey_command& cmd, int /*inde
}
// hotkey press handling
switch(cmd.id) {
switch(cmd.command) {
case HOTKEY_CYCLE_UNITS:
cycle_units();
break;
@ -626,7 +626,7 @@ void command_executor::execute_command_wrap(const command_executor::queued_comma
return; // none of the commands here respond to a key release
}
switch (command.command->id) {
switch(command.command->command) {
case HOTKEY_FULLSCREEN:
CVideo::get_singleton().toggle_fullscreen();
break;
@ -664,7 +664,7 @@ void command_executor::execute_command_wrap(const command_executor::queued_comma
}
break;
default:
DBG_G << "command_executor: unknown command number " << command.command->id << ", ignoring.\n";
DBG_G << "command_executor: unknown command number " << command.command->command << ", ignoring.\n";
break;
}
}
@ -709,7 +709,7 @@ void command_executor_default::set_button_state()
if (!can_execute) continue;
enabled = true;
ACTION_STATE state = get_action_state(command_obj.id, -1);
ACTION_STATE state = get_action_state(command_obj.command, -1);
switch (state) {
case ACTION_SELECTED:
case ACTION_ON:

View file

@ -36,9 +36,9 @@ namespace hotkey
{
struct hotkey_command_temp
{
HOTKEY_COMMAND id;
HOTKEY_COMMAND command;
std::string_view command;
std::string_view id;
/** description, tooltip are untranslated */
std::string_view description;
@ -392,10 +392,10 @@ bool remove_wml_hotkey(const std::string& id)
{
const hotkey::hotkey_command& command = get_hotkey_command(id);
if(command.id == hotkey::HOTKEY_NULL) {
if(command.command == hotkey::HOTKEY_NULL) {
LOG_G << "remove_wml_hotkey: command with id=" + id + " doesn't exist\n";
return false;
} else if(command.id != hotkey::HOTKEY_WML) {
} else if(command.command != hotkey::HOTKEY_WML) {
LOG_G << "remove_wml_hotkey: command with id=" + id + " cannot be removed because it is no wml menu hotkey\n";
return false;
} else {
@ -405,7 +405,7 @@ bool remove_wml_hotkey(const std::string& id)
// the end, since this function is used to removed WML hotkeys, which are added after
// the built-ins.
for(auto itor = known_hotkeys.rbegin(); itor != known_hotkeys.rend(); ++itor) {
if(itor->command == id) {
if(itor->id == id) {
known_hotkeys.erase(std::next(itor).base());
break;
}
@ -415,7 +415,7 @@ bool remove_wml_hotkey(const std::string& id)
command_map.clear();
for(std::size_t index = 0; index < known_hotkeys.size(); ++index) {
command_map[known_hotkeys[index].command] = index;
command_map[known_hotkeys[index].id] = index;
}
return true;
@ -424,7 +424,7 @@ bool remove_wml_hotkey(const std::string& id)
bool has_hotkey_command(const std::string& id)
{
return get_hotkey_command(id).id != hotkey::HOTKEY_NULL;
return get_hotkey_command(id).command != hotkey::HOTKEY_NULL;
}
void add_wml_hotkey(const std::string& id, const t_string& description, const config& default_hotkey)
@ -459,11 +459,11 @@ void add_wml_hotkey(const std::string& id, const t_string& description, const co
}
hotkey_command::hotkey_command(const hotkey_command_temp& temp_command)
: id(temp_command.id)
, command(temp_command.command)
: command(temp_command.command)
, id(temp_command.id)
, description(std::string(temp_command.description), "wesnoth-lib")
, hidden(temp_command.hidden)
, toggle(toggle_commands.count(temp_command.id) > 0)
, toggle(toggle_commands.count(temp_command.command) > 0)
, scope(temp_command.scope)
, category(temp_command.category)
, tooltip(std::string(temp_command.tooltip), "wesnoth-lib")
@ -478,8 +478,8 @@ hotkey_command::hotkey_command(hotkey::HOTKEY_COMMAND cmd,
hotkey::hk_scopes scop,
hotkey::HOTKEY_CATEGORY cat,
const t_string& toolt)
: id(cmd)
, command(id_)
: command(cmd)
, id(id_)
, description(desc)
, hidden(hid)
, toggle(tog)
@ -496,10 +496,11 @@ const hotkey_command& hotkey_command::null_command()
bool hotkey_command::null() const
{
if(id == HOTKEY_NULL || command == "null") {
if(command == HOTKEY_NULL || id == "null") {
const hotkey_command& null_cmd = null_command();
if(id == null_cmd.id && command == null_cmd.command && scope == null_cmd.scope && description == null_cmd.description) {
if(command == null_cmd.command && id == null_cmd.id && scope == null_cmd.scope
&& description == null_cmd.description) {
return true;
} else {
ERR_G << "the hotkey command seems to be the null command but it is not 100% sure. This shouldn't happen";
@ -513,7 +514,7 @@ bool hotkey_command::null() const
const hotkey_command& hotkey_command::get_command_by_command(hotkey::HOTKEY_COMMAND command)
{
for(hotkey_command& cmd : known_hotkeys) {
if(cmd.id == command) {
if(cmd.command == command) {
return cmd;
}
}
@ -533,8 +534,8 @@ const hotkey_command& get_hotkey_null()
void delete_all_wml_hotkeys()
{
while(known_hotkeys.back().id == hotkey::HOTKEY_WML) {
command_map.erase(known_hotkeys.back().command);
while(known_hotkeys.back().command == hotkey::HOTKEY_WML) {
command_map.erase(known_hotkeys.back().id);
known_hotkeys.pop_back();
}
@ -570,10 +571,10 @@ void init_hotkey_commands()
auto& h = known_hotkeys.emplace_back(cmd);
// Note the known_hotkeys index associated with this command.
command_map[h.command] = i++;
command_map[h.id] = i++;
// Record this hotkey's id in the appropriate category list.
hotkeys_by_category[h.category].push_back(h.id);
hotkeys_by_category[h.category].push_back(h.command);
}
}
@ -584,7 +585,7 @@ void clear_hotkey_commands()
HOTKEY_COMMAND get_id(const std::string& command)
{
return get_hotkey_command(command).id;
return get_hotkey_command(command).command;
}
const std::map<HOTKEY_CATEGORY, std::string>& get_category_names()

View file

@ -244,15 +244,11 @@ struct hotkey_command
hotkey_command(const hotkey_command&) = default;
hotkey_command& operator=(const hotkey_command&) = default;
/**
* the names are strange: the "hotkey::HOTKEY_COMMAND" is named id, and the string to identify the object is called "command"
* there is some inconstancy with that names in this file.
* This binds the command to a function. Does not need to be unique.
*/
HOTKEY_COMMAND id;
/** The command associated with this hotkey. Does not need to be unique. */
HOTKEY_COMMAND command;
/** The command is unique. */
std::string command;
/** The unique ID. */
std::string id;
// since the wml_menu hotkey_command s can have different textdomains we need t_string now.
t_string description;

View file

@ -221,7 +221,7 @@ void play_controller::hotkey_handler::toggle_accelerated_speed()
if (preferences::turbo())
{
utils::string_map symbols;
symbols["hk"] = hotkey::get_names(hotkey::hotkey_command::get_command_by_command(hotkey::HOTKEY_ACCELERATED).command);
symbols["hk"] = hotkey::get_names(hotkey::hotkey_command::get_command_by_command(hotkey::HOTKEY_ACCELERATED).id);
gui()->announce(_("Accelerated speed enabled!") + "\n" + VGETTEXT("(press $hk to disable)", symbols), font::NORMAL_COLOR, ao);
}
else
@ -252,7 +252,7 @@ void play_controller::hotkey_handler::scroll_right(bool on)
bool play_controller::hotkey_handler::do_execute_command(const hotkey::hotkey_command& cmd, int index, bool press, bool release)
{
hotkey::HOTKEY_COMMAND command = cmd.id;
hotkey::HOTKEY_COMMAND command = cmd.command;
if(index >= 0) {
unsigned i = static_cast<unsigned>(index);
if(i < savenames_.size() && !savenames_[i].empty()) {
@ -265,9 +265,9 @@ bool play_controller::hotkey_handler::do_execute_command(const hotkey::hotkey_co
}
}
int prefixlen = wml_menu_hotkey_prefix.length();
if(command == hotkey::HOTKEY_WML && cmd.command.compare(0, prefixlen, wml_menu_hotkey_prefix) == 0)
if(command == hotkey::HOTKEY_WML && cmd.id.compare(0, prefixlen, wml_menu_hotkey_prefix) == 0)
{
std::string name = cmd.command.substr(prefixlen);
std::string name = cmd.id.substr(prefixlen);
const map_location& hex = mouse_handler_.get_last_hex();
return gamestate().get_wml_menu_items().fire_item(
@ -285,7 +285,7 @@ bool play_controller::hotkey_handler::can_execute_command(const hotkey::hotkey_c
return true;
}
}
switch(cmd.id) {
switch(cmd.command) {
// Commands we can always do:
case hotkey::HOTKEY_LEADER:
@ -467,7 +467,7 @@ void play_controller::hotkey_handler::show_menu(const std::vector<config>& items
const std::string& id = item["id"];
const hotkey::hotkey_command& command = hotkey::get_hotkey_command(id);
if(id == "wml" || (can_execute_command(command) && (!context_menu || in_context_menu(command.id)))) {
if(id == "wml" || (can_execute_command(command) && (!context_menu || in_context_menu(command.command)))) {
items.emplace_back("id", id);
}
}

View file

@ -45,7 +45,7 @@ void playmp_controller::hotkey_handler::stop_network(){
bool playmp_controller::hotkey_handler::can_execute_command(const hotkey::hotkey_command& cmd, int index) const
{
hotkey::HOTKEY_COMMAND command = cmd.id;
hotkey::HOTKEY_COMMAND command = cmd.command;
bool res = true;
switch (command){
case hotkey::HOTKEY_ENDTURN:

View file

@ -139,7 +139,7 @@ void playsingle_controller::hotkey_handler::whiteboard_toggle() {
whiteboard_manager_->set_active(!whiteboard_manager_->is_active());
if (whiteboard_manager_->is_active()) {
std::string hk = hotkey::get_names(hotkey::hotkey_command::get_command_by_command(hotkey::HOTKEY_WB_TOGGLE).command);
std::string hk = hotkey::get_names(hotkey::hotkey_command::get_command_by_command(hotkey::HOTKEY_WB_TOGGLE).id);
utils::string_map symbols;
symbols["hotkey"] = hk;
@ -196,18 +196,18 @@ hotkey::ACTION_STATE playsingle_controller::hotkey_handler::get_action_state(hot
bool playsingle_controller::hotkey_handler::can_execute_command(const hotkey::hotkey_command& cmd, int index) const
{
hotkey::HOTKEY_COMMAND command = cmd.id;
hotkey::HOTKEY_COMMAND command = cmd.command;
bool res = true;
switch (command){
case hotkey::HOTKEY_WML:
{
int prefixlen = wml_menu_hotkey_prefix.length();
if(cmd.command.compare(0, prefixlen, wml_menu_hotkey_prefix) != 0) {
if(cmd.id.compare(0, prefixlen, wml_menu_hotkey_prefix) != 0) {
return false;
}
game_events::wmi_manager::item_ptr item = gamestate().get_wml_menu_items().get_item(cmd.command.substr(prefixlen));
game_events::wmi_manager::item_ptr item = gamestate().get_wml_menu_items().get_item(cmd.id.substr(prefixlen));
if(!item) {
return false;
}

View file

@ -210,9 +210,7 @@ REPLAY_RETURN replay_controller::play_side_impl()
}
bool replay_controller::can_execute_command(const hotkey::hotkey_command& cmd, int) const
{
hotkey::HOTKEY_COMMAND command = cmd.id;
switch(command) {
switch(cmd.command) {
case hotkey::HOTKEY_REPLAY_SKIP_ANIMATION:
return true;
case hotkey::HOTKEY_REPLAY_SHOW_EVERYTHING: