Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match submenu item in Files menu instead of hardcoding indices #318

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions Source/FamiTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,24 @@ 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 = 0; nPos < pFilesMenu->GetMenuItemCount(); nPos++)
// check if valid menu state
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