Skip to content

Commit

Permalink
Merge pull request #318 from Dn-Programming-Core-Management/fix-recen…
Browse files Browse the repository at this point in the history
…t-files-nullptr

Match submenu item in Files menu instead of hardcoding indices
  • Loading branch information
Gumball2415 authored Jan 10, 2025
2 parents 95bdd63 + 4de0240 commit 6ee0043
Showing 1 changed file with 18 additions and 4 deletions.
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

0 comments on commit 6ee0043

Please sign in to comment.