1 #include "core/advdumper.hpp"
2 #include "core/dispatch.hpp"
3 #include "core/project.hpp"
5 #include "platform/wxwidgets/menu_dump.hpp"
6 #include "platform/wxwidgets/platform.hpp"
13 std::map
<std::string
, std::string
> modes
;
18 std::map
<std::string
, dumper_info
> existing_dumpers
;
20 struct dumper_menu_struct
24 std::map
<int, std::string
> start_wxids
;
25 std::map
<int, wxMenuItem
*> start_items
;
28 std::map
<std::string
, dumper_menu_struct
> menustructure
;
29 std::string last_processed
;
32 void update_dumperinfo(std::map
<std::string
, dumper_info
>& new_dumpers
, adv_dumper
* d
)
34 struct dumper_info inf
;
37 std::set
<std::string
> mset
= d
->list_submodes();
39 inf
.modes
[i
] = d
->modename(i
);
40 inf
.active
= d
->busy();
41 new_dumpers
[d
->id()] = inf
;
45 class dumper_menu_monitor
: public information_dispatch
48 dumper_menu_monitor(dumper_menu
* dmenu
)
49 : information_dispatch("wxwidgets-dumpmenu")
54 ~dumper_menu_monitor() throw()
58 void on_dumper_update()
61 std::set
<adv_dumper
*> dset
= adv_dumper::get_dumper_set();
63 update_dumperinfo(new_dumpers
, i
);
64 runuifun([this]() { if(this->linked
) this->linked
->update(this->new_dumpers
); });
68 std::map
<std::string
, dumper_info
> new_dumpers
;
73 dumper_menu::dumper_menu(wxWindow
* win
, int wxid_low
, int wxid_high
)
76 win
->Connect(wxid_low
, wxid_high
, wxEVT_COMMAND_MENU_SELECTED
,
77 wxCommandEventHandler(dumper_menu::on_select
), NULL
, this);
78 wxid_range_low
= wxid_low
;
79 wxid_range_high
= wxid_high
;
80 monitor
= new dumper_menu_monitor(this);
81 std::map
<std::string
, dumper_info
> new_dumpers
;
82 runemufn([&new_dumpers
]() {
83 std::set
<adv_dumper
*> dset
= adv_dumper::get_dumper_set();
85 update_dumperinfo(new_dumpers
, i
);
90 dumper_menu::~dumper_menu()
95 void dumper_menu::on_select(wxCommandEvent
& e
)
98 if(id
< wxid_range_low
|| id
> wxid_range_high
)
100 for(auto i
: menustructure
) {
101 std::string error_str
;
102 adv_dumper
* t
= existing_dumpers
[i
.first
].instance
;
103 if(i
.second
.end_wxid
== id
) {
104 //Execute end of dump operation.
105 runemufn([t
, &error_str
]() {
108 } catch(std::exception
& e
) {
109 error_str
= e
.what();
112 wxMessageBox(towxstring(error_str
), _T("Error ending dump"), wxICON_EXCLAMATION
| wxOK
,
116 if(i
.second
.start_wxids
.count(id
)) {
117 //Execute start of dump operation.
118 std::string mode
= i
.second
.start_wxids
[id
];
119 unsigned d
= t
->mode_details(mode
);
121 if((d
& adv_dumper::target_type_mask
) == adv_dumper::target_type_file
) {
122 wxFileDialog
* d
= new wxFileDialog(pwin
, wxT("Choose file"),
123 towxstring(project_otherpath()), wxT(""), wxT("*.*"), wxFD_SAVE
);
124 std::string modext
= t
->mode_extension(mode
);
125 d
->SetWildcard(towxstring(modext
+ " files|*." + modext
));
126 auto p
= project_get();
128 d
->SetFilename(towxstring(p
->prefix
+ "." + modext
));
129 if(d
->ShowModal() == wxID_OK
)
130 prefix
= tostdstring(d
->GetPath());
132 } else if((d
& adv_dumper::target_type_mask
) == adv_dumper::target_type_prefix
) {
133 wxFileDialog
* d
= new wxFileDialog(pwin
, wxT("Choose prefix"),
134 towxstring(project_otherpath()), wxT(""), wxT("*.*"), wxFD_SAVE
);
135 auto p
= project_get();
137 d
->SetFilename(towxstring(p
->prefix
));
138 if(d
->ShowModal() == wxID_OK
)
139 prefix
= tostdstring(d
->GetPath());
141 } else if((d
& adv_dumper::target_type_mask
) == adv_dumper::target_type_special
) {
143 prefix
= pick_text(pwin
, "Choose target", "Enter target to dump to", "");
148 wxMessageBox(wxT("Unsupported target type"), _T("Dumper error"), wxICON_EXCLAMATION
|
154 runemufn([t
, mode
, prefix
, &error_str
]() {
156 t
->start(mode
, prefix
);
157 } catch(std::exception
& e
) {
158 error_str
= e
.what();
161 wxMessageBox(towxstring(error_str
), _T("Error starting dump"), wxICON_EXCLAMATION
|
168 void dumper_menu::update(const std::map
<std::string
, dumper_info
>& new_dumpers
)
170 //Destroy all old entries.
171 for(auto i
: menustructure
) {
172 struct dumper_menu_struct
& m
= i
.second
;
175 for(auto mi
: m
.start_items
)
180 //And create new ones.
181 int id
= wxid_range_low
;
183 menustructure
.clear();
184 for(auto i
: new_dumpers
) {
186 menustructure
[last_processed
].sep
= AppendSeparator();
187 last_processed
= i
.first
;
189 menustructure
[i
.first
].end_item
= NULL
;
190 menustructure
[i
.first
].end_wxid
= wxID_ANY
;
191 if(!i
.second
.active
) {
192 if(i
.second
.modes
.empty()) {
193 menustructure
[i
.first
].start_items
[id
] = Append(id
, towxstring("Dump " +
194 i
.second
.name
+ "..."));
195 menustructure
[i
.first
].start_wxids
[id
++] = "";
197 for(auto j
: i
.second
.modes
) {
198 menustructure
[i
.first
].start_items
[id
] = Append(id
, towxstring("Dump " +
199 i
.second
.name
+ " (" + j
.second
+ ")..."));
200 menustructure
[i
.first
].start_wxids
[id
++] = j
.first
;
203 menustructure
[i
.first
].end_item
= Append(id
, towxstring("End " + i
.second
.name
));
204 menustructure
[i
.first
].end_wxid
= id
++;
207 existing_dumpers
= new_dumpers
;