Fix calling wxFileHistory::Load() more than once.

Don't add all the items in the history to the menu again, remove the old ones
if we had already added them.

Closes #16588.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78013 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-10-12 20:48:56 +00:00
parent c0548a02fd
commit 96c301bb71
2 changed files with 32 additions and 0 deletions

View File

@@ -78,6 +78,9 @@ private:
// this to ensure the same normalization is used everywhere.
static wxString NormalizeFileName(const wxFileName& filename);
// Remove any existing entries from the associated menus.
void RemoveExistingHistory();
wxDECLARE_NO_COPY_CLASS(wxFileHistoryBase);
};

View File

@@ -215,6 +215,8 @@ void wxFileHistoryBase::RemoveMenu(wxMenu *menu)
#if wxUSE_CONFIG
void wxFileHistoryBase::Load(const wxConfigBase& config)
{
RemoveExistingHistory();
m_fileHistory.Clear();
wxString buf;
@@ -275,4 +277,31 @@ void wxFileHistoryBase::AddFilesToMenu(wxMenu* menu)
}
}
void wxFileHistoryBase::RemoveExistingHistory()
{
size_t count = m_fileHistory.GetCount();
if ( !count )
return;
for ( wxList::compatibility_iterator node = m_fileMenus.GetFirst();
node;
node = node->GetNext() )
{
wxMenu * const menu = static_cast<wxMenu *>(node->GetData());
// Notice that we remove count+1 items from the menu as we also remove
// the separator preceding them.
for ( size_t n = 0; n <= count; n++ )
{
const wxMenuItemList::compatibility_iterator
nodeLast = menu->GetMenuItems().GetLast();
if ( nodeLast )
{
wxMenuItem * const lastMenuItem = nodeLast->GetData();
menu->Delete(lastMenuItem);
}
}
}
}
#endif // wxUSE_FILE_HISTORY