Skip to content

Commit

Permalink
Match submenu item instead of hardcoding indices
Browse files Browse the repository at this point in the history
This fixes #317.
  • Loading branch information
Gumball2415 committed Jan 8, 2025
1 parent 95bdd63 commit 9b0c9de
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Source/FamiTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,23 @@ void CFamiTrackerApp::OnRecentFilesClear() // // //
SAFE_RELEASE(m_pRecentFileList);
m_pRecentFileList = new CRecentFileList(0, _T("Recent File List"), _T("File%d"), MAX_RECENT_FILES);

auto pMenu = m_pMainWnd->GetMenu()->GetSubMenu(0)->GetSubMenu(14);
for (int i = 0; i < MAX_RECENT_FILES; ++i)
pMenu->RemoveMenu(ID_FILE_MRU_FILE1 + i, MF_BYCOMMAND);
pMenu->AppendMenu(MF_STRING, ID_FILE_MRU_FILE1, _T("(File)"));
// Files menu
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);
// check if valid menu state
if (Status != 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)"));
}
}
}
}

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

0 comments on commit 9b0c9de

Please sign in to comment.