std::vector<std::string> command_executor::get_menu_images(const std::vector<std::string>& items){ std::vector<std::string> result; bool has_image = false; for(size_t i = 0; i < items.size(); ++i) { std::string const& item = items[i]; const hotkey::hotkey_item hk = hotkey::get_hotkey(item); std::stringstream str; //see if this menu item has an associated image std::string img(get_menu_image(hk.get_id(), i)); if(img.empty() == false) { has_image = true; str << IMAGE_PREFIX << img << COLUMN_SEPARATOR; } if (hk.get_id() == hotkey::HOTKEY_NULL) { str << item.substr(0, item.find_last_not_of(' ') + 1) << COLUMN_SEPARATOR; } else { str << hk.get_description() << COLUMN_SEPARATOR << hk.get_name(); } result.push_back(str.str()); } //If any of the menu items have an image, create an image column if(has_image) for(std::vector<std::string>::iterator i = result.begin(); i != result.end(); ++i) if(*(i->begin()) != IMAGE_PREFIX) i->insert(i->begin(), COLUMN_SEPARATOR); return result; }
std::vector<config> command_executor::get_menu_images(display& disp, const std::vector<std::string>& items) { std::vector<config> result; for(size_t i = 0; i < items.size(); ++i) { std::string const& item = items[i]; const hotkey::HOTKEY_COMMAND hk = hotkey::get_id(item); result.emplace_back(); //see if this menu item has an associated image std::string img(get_menu_image(disp, item, i)); if (img.empty() == false) { result.back()["icon"] = img; } const theme::menu* menu = disp.get_theme().get_menu_item(item); if (hk == hotkey::HOTKEY_NULL) { if (menu) result.back()["label"] = menu->title(); else { std::string label(item.begin(), item.begin() + item.find_last_not_of(' ') + 1); // TODO: To away with the fugly markup, both '=' and 0x01 size_t i = label.find_first_of('='); if(i != std::string::npos) result.back()["label"] = label.substr(i + 1); else { i = label.find_first_of(1); if(i != std::string::npos) { result.back()["details"] = label.substr(i + 1); result.back()["image"] = label.substr(1, i - 1); } else { result.back()["label"] = label; } } } } else { if (menu) result.back()["label"] = menu->title(); else { std::string desc = hotkey::get_description(item); if (hk == HOTKEY_ENDTURN) { const theme::action *b = disp.get_theme().get_action_item("button-endturn"); if (b) { desc = b->title(); } } result.back()["label"] = desc; result.back()["details"] = hotkey::get_names(item); } } } return result; }
std::vector<std::string> command_executor::get_menu_images(display& disp, const std::vector<std::string>& items) { std::vector<std::string> result; bool has_image = false; for (size_t i = 0; i < items.size(); ++i) { std::string const& item = items[i]; const hotkey::HOTKEY_COMMAND hk = hotkey::get_id(item); std::stringstream str; //see if this menu item has an associated image std::string img(get_menu_image(disp, item, i)); if (img.empty() == false) { has_image = true; str << IMAGE_PREFIX << img << COLUMN_SEPARATOR; } const theme::menu* menu = disp.get_theme().get_menu_item(item); if (hk == hotkey::HOTKEY_NULL) { if (menu) str << menu->title(); else str << item.substr(0, item.find_last_not_of(' ') + 1) << COLUMN_SEPARATOR; } else { if (menu) str << menu->title(); else { std::string desc = hotkey::get_description(item); if (hk == HOTKEY_ENDTURN) { const theme::action *b = disp.get_theme().get_action_item("button-endturn"); if (b) { desc = b->title(); } } str << desc << COLUMN_SEPARATOR << hotkey::get_names(item); } } result.push_back(str.str()); } //If any of the menu items have an image, create an image column if (has_image) { for (std::vector<std::string>::iterator i = result.begin(); i != result.end(); ++i) { if (*(i->begin()) != IMAGE_PREFIX) { i->insert(i->begin(), COLUMN_SEPARATOR); } } } return result; }
void command_executor::get_menu_images(display& disp, std::vector<config>& items) { for(size_t i = 0; i < items.size(); ++i) { config& item = items[i]; const std::string& item_id = item["id"]; const hotkey::HOTKEY_COMMAND hk = hotkey::get_id(item_id); //see if this menu item has an associated image std::string img(get_menu_image(disp, item_id, i)); if (img.empty() == false) { item["icon"] = img; } const theme::menu* menu = disp.get_theme().get_menu_item(item_id); if(menu) { item["label"] = menu->title(); } else if(hk != hotkey::HOTKEY_NULL) { std::string desc = hotkey::get_description(item_id); if(hk == HOTKEY_ENDTURN) { const theme::action *b = disp.get_theme().get_action_item("button-endturn"); if (b) { desc = b->title(); } } item["label"] = desc; item["details"] = hotkey::get_names(item_id); } else if(item["label"].empty()) { // If no matching hotkey was found and a custom label wasn't already set, treat // the id as a plaintext description. This is because either type of value can // be written to the id field by the WMI manager. The plaintext description is // used in the case the menu item specifies the relevant entry is *not* a hotkey. item["label"] = item_id; } } }