When CreatePopupMenu() is called each wxMenuItem is added to the vector, however, it seems that CreatePopupMenu() is called each time I click on the taskbar icon. This is giving me the illusion that menu_item->Enable(false) is not working but what seems to be happening is the actual wxMenu is simply being rebuilt each time I click the taskbar.
Is there a way to disable a menu item dynamically and have it remain disabled until a process or another item is clicked?
Again many thanks.
Code: Select all
std::vector<wxMenuItem *> menu_items;
Code: Select all
wxMenu *
SystemTray::CreatePopupMenu()
{
menu_items.clear();
menu = new wxMenu;
scheduled = menu->Append(PU_SCHED_TIMEOUT, _("&Scheduled break log"));
menu_items.push_back(scheduled);
notify = menu->Append(PU_NOTIFY, _("N&otify brief timeout"));
menu_items.push_back(notify);
requested = menu->Append(PU_REQUEST, _("&Request time away"));
menu_items.push_back(requested);
menu->AppendSeparator();
resume = menu->Append(PU_RESUME, _("&Resume work"));
resume->Enable(false);
menu->AppendSeparator();
menu->Append(PU_DAILY_TASKS, _("&View today's tasks"));
menu->Append(PU_SCAN_WORKSTATION, _("&Scan for illegal applications"));
/* OSX has built-in quit menu for the dock menu, but not for the status item */
#if defined (__WXOSX__)
if (OSXIsStatusItem())
#endif
{
menu->AppendSeparator();
menu->Append(PU_EXIT, _("E&xit"));
}
return menu;
}
Code: Select all
Bind(wxEVT_MENU, [=](wxCommandEvent & e) {
show_scheduled_timeout();
disable_timeout_menu_items(*scheduled);
}, PU_SCHED_TIMEOUT);
Code: Select all
void
SystemTray::disable_timeout_menu_items(wxMenuItem & current_item)
{
for (auto item : menu_items)
{
std::cout << ¤t_item << " " << &(*item) << std::endl;
if (¤t_item != &(*item))
{
std::cout << item->IsEnabled() << std::endl;
// if (item->IsEnabled())
// {
// item->Enable(false);
// }
}
}
}
Code: Select all
0x7ff06b64de40 0x7ff06b548630
1
0x7ff06b64de40 0x7ff06b64de40
0x7ff06b64de40 0x7ff06b60f0c0
1