void Accelerators::ParseMenu(wxMenu* menu) { wxMenuItemList& items = menu->GetMenuItems(); for(unsigned int c = 0; c < items.size(); c++) { wxMenuItem* item = items[c]; if(item->IsSubMenu()) { ParseMenu(item->GetSubMenu()); } else { ParseMenu(item); } } }
CContextMenuAddon::CContextMenuAddon(const cp_extension_t *ext) : CAddon(ext) { cp_cfg_element_t* menu = CAddonMgr::GetInstance().GetExtElement(ext->configuration, "menu"); if (menu) { int tmp = 0; ParseMenu(menu, "", tmp); } else { //backwards compatibility. add first item definition ELEMENTS items; if (CAddonMgr::GetInstance().GetExtElements(ext->configuration, "item", items)) { cp_cfg_element_t *item = items[0]; std::string visCondition = CAddonMgr::GetInstance().GetExtValue(item, "visible"); if (visCondition.empty()) visCondition = "false"; std::string parent = CAddonMgr::GetInstance().GetExtValue(item, "parent") == "kodi.core.manage" ? CContextMenuManager::MANAGE.m_groupId : CContextMenuManager::MAIN.m_groupId; auto label = CAddonMgr::GetInstance().GetExtValue(item, "label"); if (StringUtils::IsNaturalNumber(label)) label = g_localizeStrings.GetAddonString(ID(), atoi(label.c_str())); CContextMenuItem menuItem = CContextMenuItem::CreateItem(label, parent,LibPath(), g_infoManager.Register(visCondition, 0)); m_items.push_back(menuItem); } } }
void rc2wxr::Convert(wxString wxrfile, wxString rcfile) { m_rc.Open(rcfile); m_filesize=m_rc.Length(); if( (m_wxr = wxFopen( wxrfile, _T("wt") )) == NULL ) { return; } wxString tok,prevtok; while (!m_done) { tok=GetToken(); if (tok==_T("DIALOG")) { ParseDialog(prevtok); } if (tok==_T("MENU")) { ParseMenu(prevtok); } prevtok=tok; } fclose(m_wxr); m_rc.Close(); }
/** Parse a dynamic menu (called from menu code). */ Menu *ParseDynamicMenu(const char *command) { Menu *menu = NULL; TokenNode *start = ParseMenuIncludeHelper(NULL, command); if(JLIKELY(start)) { menu = ParseMenu(start); ReleaseTokens(start); } return menu; }
void BundlePane::ParseMenu(unsigned int bundleId, const PListArray& itemsArray, const PListDict& submenuDict, const wxTreeItemId& parentItem, const map<wxString, const BundleItemData*>& actionMap) { const bool hasSubmenus = submenuDict.IsOk(); PListDict subDict; for (unsigned int i = 0; i < itemsArray.GetSize(); ++i) { const char* item = itemsArray.GetString(i); if (item[0] == '-') { m_bundleTree->AppendItem(parentItem, wxT("---- separator ----"), 8, -1, new BundleItemData(BUNDLE_SEPARATOR, bundleId)); } else { // Look for submenu if (hasSubmenus && submenuDict.GetDict(item, subDict)) { const wxString name = subDict.wxGetString("name"); const wxString uuid(item, wxConvUTF8); const wxTreeItemId subItem = m_bundleTree->AppendItem(parentItem, name, 6, -1, new BundleItemData(BUNDLE_SUBDIR, bundleId, uuid)); PListArray subArray; if (subDict.GetArray("items", subArray)) { ParseMenu(bundleId, subArray, submenuDict, subItem, actionMap); } continue; } const wxString uuid(item, wxConvUTF8); // Look for action map<wxString, const BundleItemData*>::const_iterator s = actionMap.find(uuid); if (s != actionMap.end()) { const BundleItemData& ba = *s->second; if (ba.m_type == BUNDLE_COMMAND || ba.m_type == BUNDLE_SNIPPET) { const PListDict itemDict = m_plistHandler.Get(ba.m_type, ba.m_bundleId, ba.m_itemId); const wxString name = itemDict.wxGetString("name"); BundleItemData* itemData = new BundleItemData(ba); itemData->m_isMenuItem = true; const int imageId = (ba.m_type == BUNDLE_COMMAND) ? 1 : 2; m_bundleTree->AppendItem(parentItem, name, imageId, -1, itemData); } continue; } // Unknown item const wxTreeItemId unknownItem = m_bundleTree->AppendItem(parentItem, _("unsupported action"), 7, -1, new BundleItemData(BUNDLE_NONE, bundleId, uuid)); wxFont font = m_bundleTree->GetItemFont(unknownItem); font.SetStyle(wxFONTSTYLE_ITALIC); m_bundleTree->SetItemFont(unknownItem, font); } } }
/** Parse a root menu. */ void ParseRootMenu(const TokenNode *start) { Menu *menu; char *onroot; menu = ParseMenu(start); onroot = FindAttribute(start->attributes, ONROOT_ATTRIBUTE); if(!onroot) { onroot = "123"; } SetRootMenu(onroot, menu); }
void CContextMenuAddon::ParseMenu(cp_cfg_element_t* elem, const std::string& parent, int& anonGroupCount) { auto menuId = CAddonMgr::GetInstance().GetExtValue(elem, "@id"); auto menuLabel = CAddonMgr::GetInstance().GetExtValue(elem, "label"); if (StringUtils::IsNaturalNumber(menuLabel)) menuLabel = g_localizeStrings.GetAddonString(ID(), atoi(menuLabel.c_str())); if (menuId.empty()) { //anonymous group. create a new unique internal id. std::stringstream ss; ss << ID() << ++anonGroupCount; menuId = ss.str(); } m_items.push_back(CContextMenuItem::CreateGroup(menuLabel, parent, menuId)); ELEMENTS subMenus; if (CAddonMgr::GetInstance().GetExtElements(elem, "menu", subMenus)) for (const auto& subMenu : subMenus) ParseMenu(subMenu, menuId, anonGroupCount); ELEMENTS items; if (CAddonMgr::GetInstance().GetExtElements(elem, "item", items)) { for (const auto& item : items) { auto visCondition = CAddonMgr::GetInstance().GetExtValue(item, "visible"); auto library = CAddonMgr::GetInstance().GetExtValue(item, "@library"); auto label = CAddonMgr::GetInstance().GetExtValue(item, "label"); if (StringUtils::IsNaturalNumber(label)) label = g_localizeStrings.GetAddonString(ID(), atoi(label.c_str())); if (!label.empty() && !library.empty() && !visCondition.empty()) { auto menu = CContextMenuItem::CreateItem(label, menuId, URIUtils::AddFileToFolder(Path(), library), g_infoManager.Register(visCondition, 0)); m_items.push_back(menu); } } } }
void Accelerators::ParseBundlesMenu(wxMenuItem* item) { // Non-bundle items can be processed like normal menu items const type_info& typeInfo = typeid(*item); if(typeInfo == typeid(wxMenuItem)) { ParseMenu(item); return; } BundleMenuItem* bItem = (BundleMenuItem*) item; // now check if there is a custom shortcut map<wxString, wxString>::iterator iterator; iterator = m_customBindings.find(normalize(bItem->GetLabel())); if(iterator != m_customBindings.end()) { wxString accel = iterator->second.Trim(); bItem->SetCustomAccel(accel); } else { bItem->SetCustomAccel(wxT("")); } }
// toplevel entry for menu parser Menu * MakeRootMenu(const char *menu_id, const char *path, const char *default_menu, bool pop) { Menu *m = NULL; char IDString[MAX_PATH]; struct menu_src src; src.level = 0; src.default_menu = default_menu; src.popup = pop; if (false == add_inc_level(&src, path)) { if (NULL == default_menu) return m; } m = ParseMenu(&src, NULL, Core_IDString(IDString, menu_id)); while (src.level) dec_inc_level(&src); return m; }
/** * Traverses the menubar. * For each menu item, it grabs the binding from the menu * and it checks if there is a custom binding for that menu item. */ void Accelerators::ParseMenu() { std::map<int, KeyChord*>::iterator iterator; for(iterator = m_chords.begin(); iterator != m_chords.end(); iterator++) { KeyChord* chord = iterator->second; std::map<int, KeyBinding*>::iterator iterator2; for(iterator2 = chord->bindings.begin(); iterator2 != chord->bindings.end(); iterator2++) { KeyBinding* binding = iterator2->second; delete binding; } delete chord; } std::map<int, KeyBinding*>::iterator iterator2; for(iterator2 = m_bindings.begin(); iterator2 != m_bindings.end(); iterator2++) { KeyBinding* binding = iterator2->second; delete binding; } m_chords.clear(); m_bindings.clear(); for(unsigned int c = 0; c < m_definedBindings.size(); c++) { // If the original binding is inserted, and it also appears on the menu, it will be deleted when the menu is reparsed and lead to a later segfault InsertBinding(new KeyBinding(m_definedBindings[c]->accel, m_definedBindings[c]->id)); } m_needDefault = m_defaultBindings.size() == 0; wxMenuBar* menuBar = m_editorFrame->GetMenuBar(); if(!menuBar) return; const unsigned int bundles = menuBar->FindMenu(_("&Bundles")); for(unsigned int c = 0; c < menuBar->GetMenuCount(); c++) { if(c == bundles) ParseBundlesMenu(menuBar->GetMenu(c)); else ParseMenu(menuBar->GetMenu(c)); } }
void BundlePane::LoadBundles() { // Add an empty root node (will not be shown) m_bundleTree->DeleteAllItems(); const wxTreeItemId rootItem = m_bundleTree->AddRoot(wxEmptyString); const vector<unsigned int> bundles = m_plistHandler.GetBundles(); for (unsigned int i = 0; i < bundles.size(); ++i) { const unsigned int bundleId = bundles[i]; // Add Bundle Root const PListDict infoDict = m_plistHandler.GetBundleInfo(bundleId); const wxString bundleName = infoDict.wxGetString("name"); const wxTreeItemId bundleItem = m_bundleTree->AppendItem(rootItem, bundleName, 0, -1, new BundleItemData(bundleId)); // Add the menu const wxTreeItemId menuItem = m_bundleTree->AppendItem(bundleItem, _("Menu"), 6, -1, new BundleItemData(BUNDLE_MENU, bundleId)); map<wxString, const BundleItemData*> actionMap; // Add commands const vector<unsigned int> commands = m_plistHandler.GetList(BUNDLE_COMMAND, bundleId); for (unsigned int c = 0; c < commands.size(); ++c) { const unsigned int commandId = commands[c]; const PListDict cmdDict = m_plistHandler.Get(BUNDLE_COMMAND, bundleId, commandId); const wxString cmdName = cmdDict.wxGetString("name"); const wxString uuid = cmdDict.wxGetString("uuid"); BundleItemData* itemData = new BundleItemData(BUNDLE_COMMAND, bundleId, commandId, uuid); actionMap[uuid] = itemData; m_bundleTree->AppendItem(bundleItem, cmdName, 1, -1, itemData); } // Add snippets const vector<unsigned int> snippets = m_plistHandler.GetList(BUNDLE_SNIPPET, bundleId); for (unsigned int n = 0; n < snippets.size(); ++n) { const unsigned int snippetId = snippets[n]; const PListDict snipDict = m_plistHandler.Get(BUNDLE_SNIPPET, bundleId, snippetId); const wxString snipName = snipDict.wxGetString("name"); const wxString uuid = snipDict.wxGetString("uuid"); BundleItemData* itemData = new BundleItemData(BUNDLE_SNIPPET, bundleId, snippetId, uuid); actionMap[uuid] = itemData; m_bundleTree->AppendItem(bundleItem, snipName, 2, -1, itemData); } // Add DragCommands const vector<unsigned int> dragCommands = m_plistHandler.GetList(BUNDLE_DRAGCMD, bundleId); for (unsigned int d = 0; d < dragCommands.size(); ++d) { const unsigned int commandId = dragCommands[d]; const PListDict cmdDict = m_plistHandler.Get(BUNDLE_DRAGCMD, bundleId, commandId); const wxString cmdName = cmdDict.wxGetString("name"); m_bundleTree->AppendItem(bundleItem, cmdName, 3, -1, new BundleItemData(BUNDLE_DRAGCMD, bundleId, commandId)); } // Add Preferences const vector<unsigned int> preferences = m_plistHandler.GetList(BUNDLE_PREF, bundleId); for (unsigned int p = 0; p < preferences.size(); ++p) { const unsigned int prefId = preferences[p]; const PListDict prefDict = m_plistHandler.Get(BUNDLE_PREF, bundleId, prefId); const wxString name = prefDict.wxGetString("name"); m_bundleTree->AppendItem(bundleItem, name, 4, -1, new BundleItemData(BUNDLE_PREF, bundleId, prefId)); } // Add Languages const vector<unsigned int> languages = m_plistHandler.GetList(BUNDLE_LANGUAGE, bundleId); for (unsigned int l = 0; l < languages.size(); ++l) { const unsigned int langId = languages[l]; const PListDict langDict = m_plistHandler.Get(BUNDLE_LANGUAGE, bundleId, langId); const wxString name = langDict.wxGetString("name"); m_bundleTree->AppendItem(bundleItem, name, 5, -1, new BundleItemData(BUNDLE_LANGUAGE, bundleId, langId)); } // Check if there is a menu PListDict menuDict; if (infoDict.GetDict("mainMenu", menuDict)) { PListArray itemsArray; if (menuDict.GetArray("items", itemsArray)) { PListDict submenuDict; menuDict.GetDict("submenus", submenuDict); // Parse the menu ParseMenu(bundleId, itemsArray, submenuDict, menuItem, actionMap); } } else { // If there is no main menu structure, we use the ordering PListArray itemsArray; if (infoDict.GetArray("ordering", itemsArray)) { // Parse the menu ParseMenu(bundleId, itemsArray, PListDict(), menuItem, actionMap); } } m_bundleTree->SortChildren(bundleItem); } m_bundleTree->SortChildren(rootItem); }
// recursive parsing of menu file static Menu* ParseMenu(struct menu_src *src, const char *title, const char *IDString) { char line[4000]; char data[4000]; char buffer[4000]; char command[40]; char label[MAX_PATH]; Menu *pMenu, *pSub; MenuItem *pItem; int f, e_cmd; const char *p_label, *p_data, *cp, *p_cmd; pMenu = NULL; for(;;) { p_label = NULL; p_data = data; if (0 == src->level) { // read default menu from string NextToken(line, &src->default_menu, "\n"); } else { f = ReadNextCommand(src->fp[src->level-1], line, sizeof(line)); if (!f) { if (src->level > 1) { dec_inc_level(src); continue; // continue from included file } e_cmd = e_no_end; goto skip; } } cp = replace_environment_strings(line, sizeof line); //dbg_printf("Menu %08x line:%s", pMenu, line); // get the command if (false == get_string_within(command, sizeof command, &cp, "[]")) continue; // search the command e_cmd = get_string_index(command, menu_cmds); if (get_string_within(label, sizeof label, &cp, "()")) p_label = label; if (false == get_string_within(data, sizeof data, &cp, "{}")) p_data = label; skip: if (NULL == pMenu) { if (e_begin == e_cmd) { // If the line contains [begin] we create the menu // If no menu title has been defined, display Blackbox version... #ifdef BBXMENU if (src->default_menu) strcpy(label, "bbXMenu"); else #endif if (0 == label[0] && src->default_menu) p_label = GetBBVersion(); pMenu = MakeNamedMenu(p_label, IDString, src->popup); continue; } if (NULL == title) title = NLS0("missing [begin]"); pMenu = MakeNamedMenu(title, IDString, src->popup); } pItem = NULL; switch (e_cmd) { //==================== // [begin] is like [submenu] when within the menu case e_begin: case e_submenu: sprintf(buffer, "%s_%s", IDString, label); strlwr(buffer + strlen(IDString)); pSub = ParseMenu(src, p_data, buffer); if (pSub) pItem = MakeSubmenu(pMenu, pSub, label); else pItem = MakeMenuNOP(pMenu, label); break; //==================== case e_no_end: MakeMenuNOP(pMenu, NLS0("missing [end]")); case e_end: MenuOption(pMenu, BBMENU_ISDROPTARGET); return pMenu; //==================== case e_include: { char dir[MAX_PATH]; file_directory(dir, src->path[src->level-1]); replace_shellfolders_from_base(buffer, p_data, false, dir); if (false == add_inc_level(src, buffer)) { replace_shellfolders(buffer, p_data, false); if (false == add_inc_level(src, buffer)) MakeMenuNOP(pMenu, NLS0("[include] failed")); } continue; } //==================== // a [nop] item will insert an inactive item with optional text case e_nop: pItem = MakeMenuNOP(pMenu, label); break; // a insert separator, we treat [sep] like [nop] with no label case e_sep1: case e_sep2: pItem = MakeMenuNOP(pMenu, NULL); break; //==================== // a [path] item is pointing to a dynamic folder... case e_path: p_cmd = get_special_command(&p_data, buffer, sizeof buffer); pItem = MakeMenuItemPath(pMenu, label, p_data, p_cmd); break; // a [insertpath] item will insert items from a folder... case e_insertpath: p_cmd = get_special_command(&p_data, buffer, sizeof buffer); pItem = MakeMenuItemPath(pMenu, NULL, p_data, p_cmd); break; // a [stylemenu] item is pointing to a dynamic style folder... case e_stylesmenu: pItem = MakeMenuItemPath(pMenu, label, p_data, MM_STYLE_BROAM); break; // a [styledir] item will insert styles from a folder... case e_stylesdir: pItem = MakeMenuItemPath(pMenu, NULL, p_data, MM_STYLE_BROAM); break; // a [rcmenu] item is pointing to a dynamic rc files folder... case e_rcmenu: pItem = MakeMenuItemPath(pMenu, label, p_data, MM_EDIT_BROAM); break; case e_themesmenu: pItem = MakeMenuItemPath(pMenu, label, p_data, MM_THEME_BROAM); break; //==================== // special items... case e_workspaces: pItem = MakeSubmenu(pMenu, MakeDesktopMenu(0, src->popup), p_label); break; case e_icons: pItem = MakeSubmenu(pMenu, MakeDesktopMenu(1, src->popup), p_label); break; case e_tasks: pItem = MakeSubmenu(pMenu, MakeDesktopMenu(2, src->popup), p_label); break; case e_config: pItem = MakeSubmenu(pMenu, MakeConfigMenu(src->popup), p_label); break; //==================== case e_exec: if ('@' == data[0]) { pItem = MakeMenuItem(pMenu, label, data, false); MenuItemOption(pItem, BBMENUITEM_UPDCHECK); } else { goto core_broam; } break; //==================== case e_other: f = get_workspace_number(command); // check for 'workspace1..' if (-1 != f) { pItem = MakeSubmenu(pMenu, MakeTaskFolder(f, src->popup), p_label); } else { p_data = data; goto core_broam; } break; //==================== // everything else is converted to a '@BBCore.xxx' broam core_broam: f = sprintf(buffer, "@bbCore.%s", command); strlwr(buffer+8); if (p_data[0]) sprintf(buffer + f, " %s", p_data); pItem = MakeMenuItem(pMenu, label[0]?label:command, buffer, false); break; } //#ifdef BBOPT_MENUICONS if ( Settings_menu.iconSize ) { if (pItem && get_string_within(label, sizeof label, &cp, "<>")) MenuItemOption(pItem, BBMENUITEM_SETICON, label); } //#endif } }