void AccelEditor::InitCommands() { m_commands.DeleteAllItems(); m_hItems.RemoveAll(); m_alreadyAffected.SetWindowText(""); AddCommandsFromMenu(m_pMenuSrc, TVI_ROOT); AddCommandsFromTable(); }
void KeyBinder::AddCommandsFromMenuBar(wxMenuBar* menuBar) { int numMenus = menuBar->GetMenuCount(); for (int i = 0; i < numMenus; ++i) { AddCommandsFromMenu(menuBar->GetLabelTop(i), menuBar->GetMenu(i)); } }
// recursive calls void AccelEditor::AddCommandsFromMenu(CMenu *pMenu, HTREEITEM hParent) { UINT nIndexMax = pMenu->GetMenuItemCount(); for (UINT nIndex = 0; nIndex < nIndexMax; ++nIndex) { UINT nID = pMenu->GetMenuItemID(nIndex); if (nID == 0) continue; // menu separator or invalid cmd - ignore it if (nID == (UINT)-1) { // possibly a submenu CMenu *pSubMenu = pMenu->GetSubMenu(nIndex); if (pSubMenu != NULL) { CString tempStr; pMenu->GetMenuString(nIndex, tempStr, MF_BYPOSITION); tempStr.Remove('&'); HTREEITEM newItem = m_commands.InsertItem(tempStr, hParent); AddCommandsFromMenu(pSubMenu, newItem); } } else { // normal menu item // generate the strings CString command; pMenu->GetMenuString(nIndex, command, MF_BYPOSITION); int nPos = command.ReverseFind('\t'); if (nPos != -1) { command.Delete(nPos, command.GetLength() - nPos); } command.Remove('&'); HTREEITEM newItem = m_commands.InsertItem(command, hParent); m_commands.SetItemData(newItem, nID); m_hItems.AddTail(newItem); } } }