Skip to content

Commit

Permalink
Add loop break and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumball2415 committed Jan 9, 2025
1 parent 9b0c9de commit 4de0240
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Source/FamiTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,19 +455,20 @@ void CFamiTrackerApp::OnRecentFilesClear() // // //
auto pFilesMenu = m_pMainWnd->GetMenu()->GetSubMenu(0);

// Try and find Recent Files submenu
for (int nPos = pFilesMenu->GetMenuItemCount(); nPos > 0; --nPos) {
UINT Status = pFilesMenu->GetMenuState(nPos, MF_BYPOSITION);
for (int nPos = 0; nPos < pFilesMenu->GetMenuItemCount(); nPos++)
// check if valid menu state
if (Status != UINT(-1)) {
if (pFilesMenu->GetMenuState(nPos, MF_BYPOSITION) != UINT(-1)) {
// check if it has a submenu and the first item is ID_RECENTFILES_CLEAR
auto pSubMenu = pFilesMenu->GetSubMenu(nPos);
if (pSubMenu != nullptr && pSubMenu->GetMenuItemID(0) == ID_RECENTFILES_CLEAR) {
for (int i = 0; i < MAX_RECENT_FILES; ++i)
pSubMenu->RemoveMenu(ID_FILE_MRU_FILE1 + i, MF_BYCOMMAND);
pSubMenu->AppendMenu(MF_STRING, ID_FILE_MRU_FILE1, _T("(File)"));
return;
}
}
}

throw std::runtime_error("Could not find \"ID_RECENTFILES_CLEAR\"");
}

void CFamiTrackerApp::OnUpdateRecentFiles(CCmdUI *pCmdUI) // // //
Expand Down

0 comments on commit 4de0240

Please sign in to comment.