void wxMenu::UpdateAccel(wxMenuItem *item) { if ( item->IsSubMenu() ) { wxMenu *submenu = item->GetSubMenu(); wxMenuItemList::compatibility_iterator node = submenu->GetMenuItems().GetFirst(); while ( node ) { UpdateAccel(node->GetData()); node = node->GetNext(); } } else if ( !item->IsSeparator() ) { // recurse upwards: we should only modify m_accels of the top level // menus, not of the submenus as wxMenuBar doesn't look at them // (alternative and arguable cleaner solution would be to recurse // downwards in GetAccelCount() and CopyAccels()) if ( GetParent() ) { GetParent()->UpdateAccel(item); return; } // find the (new) accel for this item wxAcceleratorEntry *accel = wxGetAccelFromString(item->GetText()); if ( accel ) accel->m_command = item->GetId(); // find the old one int n = FindAccel(item->GetId()); if ( n == wxNOT_FOUND ) { // no old, add new if any if ( accel ) m_accels.Add(accel); else return; // skipping RebuildAccelTable() below } else { // replace old with new or just remove the old one if no new delete m_accels[n]; if ( accel ) m_accels[n] = accel; else m_accels.RemoveAt(n); } if ( IsAttached() ) { GetMenuBar()->RebuildAccelTable(); } } //else: it is a separator, they can't have accels, nothing to do }
void wxMenu::UpdateAccel(wxMenuItem *item) { if ( item->IsSubMenu() ) { wxMenu *submenu = item->GetSubMenu(); wxMenuItemList::compatibility_iterator node = submenu->GetMenuItems().GetFirst(); while ( node ) { UpdateAccel(node->GetData()); node = node->GetNext(); } } else if ( !item->IsSeparator() ) { // find the (new) accel for this item wxAcceleratorEntry *accel = wxGetAccelFromString(item->GetText()); if ( accel ) accel->m_command = item->GetId(); // find the old one int n = FindAccel(item->GetId()); if ( n == wxNOT_FOUND ) { // no old, add new if any if ( accel ) m_accels.Add(accel); else return; // skipping RebuildAccelTable() below } else { // replace old with new or just remove the old one if no new delete m_accels[n]; if ( accel ) m_accels[n] = accel; else m_accels.RemoveAt(n); } if ( IsAttached() ) { GetMenuBar()->RebuildAccelTable(); } } //else: it is a separator, they can't have accels, nothing to do }