3 #include <wx/control.h>
4 #include <wx/combobox.h>
6 #include "platform/wxwidgets/menu_projects.hpp"
7 #include "platform/wxwidgets/platform.hpp"
8 #include "library/eatarg.hpp"
9 #include "core/instance.hpp"
10 #include "core/project.hpp"
12 projects_menu::projects_menu(wxWindow
* win
, emulator_instance
& _inst
, int wxid_low
, int wxid_high
,
13 const std::string
& cfg
, std::function
<void(const std::string
& id
)> cb
)
14 : inst(_inst
), hook(*this), rfiles(cfg
, wxid_high
- wxid_low
- 1) //Reserve wxid_low and wxid_high.
18 wxid_range_low
= wxid_low
;
19 wxid_range_high
= wxid_high
;
21 win
->Connect(wxid_low
, wxid_high
, wxEVT_COMMAND_MENU_SELECTED
,
22 wxCommandEventHandler(projects_menu::on_select
), NULL
, this);
23 rfiles
.add_hook(hook
);
27 projects_menu::~projects_menu()
31 void projects_menu::on_select(wxCommandEvent
& e
)
35 if(id
< wxid_range_low
|| id
> wxid_range_high
)
37 if(id
== wxid_range_low
) {
39 auto projects
= inst
.project
->enumerate();
40 std::vector
<std::string
> a
;
41 std::vector
<wxString
> b
;
42 for(auto i
: projects
) {
44 b
.push_back(towxstring(i
.second
));
47 show_message_ok(pwin
, "Load project", "No projects available", wxICON_EXCLAMATION
);
50 wxSingleChoiceDialog
* d2
= new wxSingleChoiceDialog(pwin
, wxT("Select project to switch to:"),
51 wxT("Load project"), b
.size(), &b
[0]);
52 if(d2
->ShowModal() == wxID_CANCEL
) {
56 std::string _id
= a
[d2
->GetSelection()];
58 } else if(id
== wxid_range_high
) {
64 selected_cb(entries
[id
]._id
);
68 void projects_menu::update()
71 auto ents
= rfiles
.get();
72 int id
= wxid_range_low
+ 1; //wxid_range_low is reserved for other.
76 bool has_ents
= false;
79 if(id
>= wxid_range_high
)
82 items
[id
] = Append(id
, towxstring(i
.display()));
86 items
[-1] = AppendSeparator();
87 items
[wxid_range_high
] = Append(wxid_range_high
, wxT("Refresh"));
88 items
[-2] = AppendSeparator();
89 items
[wxid_range_low
] = Append(wxid_range_low
, wxT("Select other..."));