| 1811 | } |
| 1812 | |
| 1813 | utility::Uuid Module::insert_menu_item( |
| 1814 | const std::string &menu_model_name, |
| 1815 | const std::string &menu_text, |
| 1816 | const std::string &menu_path, |
| 1817 | const float menu_item_position, |
| 1818 | Attribute *attr, |
| 1819 | const bool divider, |
| 1820 | const utility::Uuid &hotkey, |
| 1821 | const std::string &user_data, |
| 1822 | const std::string &custom_menu_qml) { |
| 1823 | try { |
| 1824 | auto central_models_data_actor = |
| 1825 | self()->home_system().registry().template get<caf::actor>( |
| 1826 | global_ui_model_data_registry); |
| 1827 | |
| 1828 | utility::JsonStore menu_item_data; |
| 1829 | if (attr) { |
| 1830 | if (!custom_menu_qml.empty()) { |
| 1831 | attr->set_role_data(Attribute::QmlCode, custom_menu_qml); |
| 1832 | } |
| 1833 | menu_item_data = attribute_menu_item_data(attr); |
| 1834 | // For now using this 'RESKIN' dummy token to stop menus from 'old' skin |
| 1835 | // messing things up for the reskin. Alternatively (hack alert) if we |
| 1836 | // want to use the value of the attribute itself to set the menu item |
| 1837 | // name we start the menu path with USE_ATTR_VALUE |
| 1838 | std::string new_menu_path; |
| 1839 | if (menu_text == "USE_ATTR_VALUE") { |
| 1840 | new_menu_path = "USE_ATTR_VALUE|" + menu_model_name + "|" + menu_path + "|" + |
| 1841 | attr->get_role_data<std::string>(Attribute::Value); |
| 1842 | } else { |
| 1843 | new_menu_path = "RESKIN|" + menu_model_name + "|" + menu_path + "|" + menu_text; |
| 1844 | } |
| 1845 | if (attr->has_role_data(Attribute::MenuPaths)) { |
| 1846 | auto paths = |
| 1847 | attr->get_role_data<std::vector<std::string>>(Attribute::MenuPaths); |
| 1848 | paths.push_back(new_menu_path); |
| 1849 | attr->set_role_data(Attribute::MenuPaths, paths); |
| 1850 | } else { |
| 1851 | attr->set_role_data( |
| 1852 | Attribute::MenuPaths, std::vector<std::string>({new_menu_path})); |
| 1853 | } |
| 1854 | |
| 1855 | } else if (!custom_menu_qml.empty()) { |
| 1856 | |
| 1857 | menu_item_data["menu_item_type"] = "custom"; |
| 1858 | menu_item_data["custom_menu_qml"] = custom_menu_qml; |
| 1859 | menu_item_data["uuid"] = utility::Uuid::generate(); |
| 1860 | |
| 1861 | } else { |
| 1862 | // a menu item that is not linked by to an attribute - it simply |
| 1863 | // has a uuid which, when the user clicks on the menu item, we run |
| 1864 | // a callback to menu_item_activated virtual method |
| 1865 | menu_item_data["menu_item_type"] = divider ? "divider" : "button"; |
| 1866 | menu_item_data["uuid"] = utility::Uuid::generate(); |
| 1867 | } |
| 1868 | |
| 1869 | if (attr && menu_text == "USE_ATTR_VALUE") { |
| 1870 | menu_item_data["name"] = attr->get_role_data<std::string>(Attribute::Value); |
no test coverage detected