/
FilterMenu.cpp
61 lines (46 loc) · 1.07 KB
/
FilterMenu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "FilterMenu.h"
#include "iuimanager.h"
#include "ieventmanager.h"
#include <wx/menu.h>
#include "wxutil/menu/IconTextMenuItem.h"
namespace ui
{
namespace
{
const char* const MENU_ICON = "iconFilter16.png";
}
FilterMenu::FilterMenu() :
_menu(new wxutil::PopupMenu)
{
// Visit the filters in the FilterSystem to populate the menu
GlobalFilterSystem().forEachFilter(*this);
}
FilterMenu::~FilterMenu()
{
for (auto i : _filterItems)
{
IEventPtr event = GlobalEventManager().findEvent(i.first);
if (event)
{
event->disconnectMenuItem(i.second);
}
}
_menu = nullptr;
}
void FilterMenu::visit(const std::string& filterName)
{
wxMenuItem* item = _menu->Append(new wxutil::IconTextMenuItem(filterName, MENU_ICON));
item->SetCheckable(true);
std::string eventName = GlobalFilterSystem().getFilterEventName(filterName);
IEventPtr event = GlobalEventManager().findEvent(eventName);
if (event)
{
event->connectMenuItem(item);
}
_filterItems.insert(std::make_pair(eventName, item));
}
wxMenu* FilterMenu::getMenuWidget()
{
return _menu;
}
} // namespace