3 #include <wx/control.h>
4 #include <wx/combobox.h>
5 #include <wx/statline.h>
7 #include "core/advdumper.hpp"
8 #include "core/dispatch.hpp"
9 #include "core/instance.hpp"
10 #include "core/project.hpp"
11 #include "core/ui-services.hpp"
13 #include "platform/wxwidgets/menu_dump.hpp"
14 #include "platform/wxwidgets/platform.hpp"
18 dumper_factory_base
* instance
;
21 std::map
<std::string
, std::string
> modes
;
26 struct dumper_menu_struct
30 std::map
<int, std::string
> start_wxids
;
31 std::map
<int, wxMenuItem
*> start_items
;
34 std::map
<std::string
, dumper_menu_struct
> menustructure
;
35 std::string last_processed
;
40 class dumper_menu_monitor
: public master_dumper::notifier
43 dumper_menu_monitor(dumper_menu
* dmenu
)
48 ~dumper_menu_monitor() throw()
52 void dumpers_updated() throw()
54 runuifun([this]() { if(this->linked
) this->linked
->update(); });
56 void dump_status_change() throw()
64 dumper_menu::dumper_menu(wxWindow
* win
, emulator_instance
& _inst
, int wxid_low
, int wxid_high
)
69 win
->Connect(wxid_low
, wxid_high
, wxEVT_COMMAND_MENU_SELECTED
,
70 wxCommandEventHandler(dumper_menu::on_select
), NULL
, this);
71 wxid_range_low
= wxid_low
;
72 wxid_range_high
= wxid_high
;
73 monitor
= new dumper_menu_monitor(this);
74 inst
.mdumper
->add_notifier(*monitor
);
78 dumper_menu::~dumper_menu()
80 inst
.mdumper
->drop_notifier(*monitor
);
84 void dumper_menu::on_select(wxCommandEvent
& e
)
88 if(id
< wxid_range_low
|| id
> wxid_range_high
)
90 for(auto i
: menustructure
) {
91 dumper_factory_base
* t
= existing_dumpers
[i
.first
].factory
;
92 if(i
.second
.end_wxid
== id
) {
93 UI_end_dump(inst
, *t
);
96 if(i
.second
.start_wxids
.count(id
)) {
97 //Execute start of dump operation.
98 std::string mode
= i
.second
.start_wxids
[id
];
99 unsigned d
= t
->mode_details(mode
);
101 if((d
& dumper_factory_base::target_type_mask
) == dumper_factory_base::target_type_file
) {
102 wxFileDialog
* d
= new wxFileDialog(pwin
, wxT("Choose file"),
103 towxstring(UI_get_project_otherpath(inst
)), wxT(""), wxT("*.*"),
105 std::string modext
= t
->mode_extension(mode
);
106 d
->SetWildcard(towxstring(modext
+ " files|*." + modext
));
107 auto p
= inst
.project
->get();
109 d
->SetFilename(towxstring(p
->prefix
+ "." + modext
));
110 if(d
->ShowModal() == wxID_OK
)
111 prefix
= tostdstring(d
->GetPath());
113 } else if((d
& dumper_factory_base::target_type_mask
) ==
114 dumper_factory_base::target_type_prefix
) {
115 wxFileDialog
* d
= new wxFileDialog(pwin
, wxT("Choose prefix"),
116 towxstring(UI_get_project_otherpath(inst
)), wxT(""), wxT("*.*"),
118 auto p
= inst
.project
->get();
120 d
->SetFilename(towxstring(p
->prefix
));
121 if(d
->ShowModal() == wxID_OK
)
122 prefix
= tostdstring(d
->GetPath());
124 } else if((d
& dumper_factory_base::target_type_mask
) ==
125 dumper_factory_base::target_type_special
) {
127 prefix
= pick_text(pwin
, "Choose target", "Enter target to dump to", "");
132 wxMessageBox(wxT("Unsupported target type"), _T("Dumper error"), wxICON_EXCLAMATION
|
139 UI_start_dump(inst
, *t
, mode
, prefix
);
140 } catch(std::exception
& e
) {
141 show_exception(this->pwin
, "Error starting dump", "", e
);
148 void dumper_menu::update()
151 dumper_information dinfo
= UI_get_dumpers(inst
);
152 //Destroy all old entries.
153 for(auto i
: menustructure
) {
154 struct dumper_menu_struct
& m
= i
.second
;
157 for(auto mi
: m
.start_items
)
162 //And create new ones.
163 int id
= wxid_range_low
;
165 menustructure
.clear();
166 for(auto i
: dinfo
.dumpers
) {
167 //Skip dumper called "NULL" unless actually active, since it doesn't really work.
168 if(i
.second
.hidden
&& !i
.second
.active
)
171 menustructure
[last_processed
].sep
= AppendSeparator();
172 last_processed
= i
.first
;
174 menustructure
[i
.first
].end_item
= NULL
;
175 menustructure
[i
.first
].end_wxid
= wxID_ANY
;
176 if(!i
.second
.active
) {
177 if(i
.second
.modes
.empty()) {
178 menustructure
[i
.first
].start_items
[id
] = Append(id
, towxstring("Dump " +
179 i
.second
.name
+ "..."));
180 menustructure
[i
.first
].start_wxids
[id
++] = "";
182 for(auto j
: i
.second
.modes
) {
183 menustructure
[i
.first
].start_items
[id
] = Append(id
, towxstring("Dump " +
184 i
.second
.name
+ " (" + j
.second
+ ")..."));
185 menustructure
[i
.first
].start_wxids
[id
++] = j
.first
;
188 menustructure
[i
.first
].end_item
= Append(id
, towxstring("End " + i
.second
.name
));
189 menustructure
[i
.first
].end_wxid
= id
++;
192 existing_dumpers
= dinfo
.dumpers
;