Simplify the popup menu. You can reuse the popup menu. So, no need to create/delete each time. Also, deleting stuff from a for each iterator is generally a bad idea.

This commit is contained in:
flash-fire 2017-02-15 22:56:32 -06:00 committed by Ivan
parent 458dbbd15d
commit 0c8bda4f41
2 changed files with 21 additions and 19 deletions

View File

@ -43,6 +43,7 @@ GameViewer::GameViewer(wxWindow* parent) : wxListView(parent)
m_sortColumn = 1;
m_sortAscending = true;
m_popup = new wxMenu();
InitPopupMenu();
Bind(wxEVT_LIST_ITEM_ACTIVATED, &GameViewer::DClick, this);
Bind(wxEVT_LIST_COL_CLICK, &GameViewer::OnColClick, this);
@ -56,6 +57,24 @@ GameViewer::~GameViewer()
SaveSettings();
}
void GameViewer::InitPopupMenu()
{
wxMenuItem* boot_item = new wxMenuItem(m_popup, 0, _T("Boot"));
#if defined (_WIN32)
// wxMenuItem::Set(Get)Font only available for the wxMSW port
wxFont font = GetFont();
font.SetWeight(wxFONTWEIGHT_BOLD);
boot_item->SetFont(font);
#endif
m_popup->Append(boot_item);
m_popup->Append(1, _T("Configure"));
m_popup->Append(2, _T("Remove Game"));
Bind(wxEVT_MENU, &GameViewer::BootGame, this, 0);
Bind(wxEVT_MENU, &GameViewer::ConfigureGame, this, 1);
Bind(wxEVT_MENU, &GameViewer::RemoveGame, this, 2);
}
void GameViewer::DoResize(wxSize size)
{
SetSize(size);
@ -198,25 +217,6 @@ void GameViewer::DClick(wxListEvent& event)
void GameViewer::RightClick(wxListEvent& event)
{
for (wxMenuItem *item : m_popup->GetMenuItems()) {
m_popup->Destroy(item);
}
wxMenuItem* boot_item = new wxMenuItem(m_popup, 0, _T("Boot"));
#if defined (_WIN32)
// wxMenuItem::Set(Get)Font only available for the wxMSW port
wxFont font = GetFont();
font.SetWeight(wxFONTWEIGHT_BOLD);
boot_item->SetFont(font);
#endif
m_popup->Append(boot_item);
m_popup->Append(1, _T("Configure"));
m_popup->Append(2, _T("Remove Game"));
Bind(wxEVT_MENU, &GameViewer::BootGame, this, 0);
Bind(wxEVT_MENU, &GameViewer::ConfigureGame, this, 1);
Bind(wxEVT_MENU, &GameViewer::RemoveGame, this, 2);
PopupMenu(m_popup, event.GetPoint());
}

View File

@ -72,6 +72,8 @@ public:
GameViewer(wxWindow* parent);
~GameViewer();
void InitPopupMenu();
void DoResize(wxSize size);
void LoadGames();