1 #include "core/advdumper.hpp"
2 #include "core/dispatch.hpp"
4 #include "platform/wxwidgets/menu_dump.hpp"
5 #include "platform/wxwidgets/platform.hpp"
12 std::map
<std::string
, std::string
> modes
;
17 std::map
<std::string
, dumper_info
> existing_dumpers
;
19 struct dumper_menu_struct
23 std::map
<int, std::string
> start_wxids
;
24 std::map
<int, wxMenuItem
*> start_items
;
27 std::map
<std::string
, dumper_menu_struct
> menustructure
;
28 std::string last_processed
;
31 void update_dumperinfo(std::map
<std::string
, dumper_info
>& new_dumpers
, adv_dumper
* d
)
33 struct dumper_info inf
;
36 std::set
<std::string
> mset
= d
->list_submodes();
38 inf
.modes
[i
] = d
->modename(i
);
39 inf
.active
= d
->busy();
40 new_dumpers
[d
->id()] = inf
;
44 class dumper_menu_monitor
: public information_dispatch
47 dumper_menu_monitor(dumper_menu
* dmenu
)
48 : information_dispatch("wxwidgets-dumpmenu")
53 ~dumper_menu_monitor()
57 void on_dumper_update()
59 std::map
<std::string
, dumper_info
> new_dumpers
;
60 std::set
<adv_dumper
*> dset
= adv_dumper::get_dumper_set();
62 update_dumperinfo(new_dumpers
, i
);
63 runuifun([linked
, new_dumpers
]() { if(linked
) linked
->update(new_dumpers
); });
71 dumper_menu::dumper_menu(wxWindow
* win
, int wxid_low
, int wxid_high
)
74 win
->Connect(wxid_low
, wxid_high
, wxEVT_COMMAND_MENU_SELECTED
,
75 wxCommandEventHandler(dumper_menu::on_select
), NULL
, this);
76 wxid_range_low
= wxid_low
;
77 wxid_range_high
= wxid_high
;
78 monitor
= new dumper_menu_monitor(this);
79 std::map
<std::string
, dumper_info
> new_dumpers
;
80 runemufn([&new_dumpers
]() {
81 std::set
<adv_dumper
*> dset
= adv_dumper::get_dumper_set();
83 update_dumperinfo(new_dumpers
, i
);
88 dumper_menu::~dumper_menu()
93 void dumper_menu::on_select(wxCommandEvent
& e
)
96 if(id
< wxid_range_low
|| id
> wxid_range_high
)
98 for(auto i
: menustructure
) {
99 std::string error_str
;
100 adv_dumper
* t
= existing_dumpers
[i
.first
].instance
;
101 if(i
.second
.end_wxid
== id
) {
102 //Execute end of dump operation.
103 runemufn([t
, &error_str
]() {
106 } catch(std::exception
& e
) {
107 error_str
= e
.what();
110 wxMessageBox(towxstring(error_str
), _T("Error ending dump"), wxICON_EXCLAMATION
| wxOK
,
114 if(i
.second
.start_wxids
.count(id
)) {
115 //Execute start of dump operation.
116 std::string mode
= i
.second
.start_wxids
[id
];
117 unsigned d
= t
->mode_details(mode
);
119 if((d
& adv_dumper::target_type_mask
) == adv_dumper::target_type_file
) {
120 wxFileDialog
* d
= new wxFileDialog(pwin
, wxT("Choose file"), wxT("."));
121 if(d
->ShowModal() == wxID_OK
)
122 prefix
= tostdstring(d
->GetPath());
124 } else if((d
& adv_dumper::target_type_mask
) == adv_dumper::target_type_prefix
) {
125 wxFileDialog
* d
= new wxFileDialog(pwin
, wxT("Choose prefix"), wxT("."));
126 if(d
->ShowModal() == wxID_OK
)
127 prefix
= tostdstring(d
->GetPath());
129 } else if((d
& adv_dumper::target_type_mask
) == adv_dumper::target_type_special
) {
131 prefix
= pick_text(pwin
, "Choose target", "Enter target to dump to", "");
136 wxMessageBox(wxT("Unsupported target type"), _T("Dumper error"), wxICON_EXCLAMATION
|
142 runemufn([t
, mode
, prefix
, &error_str
]() {
144 t
->start(mode
, prefix
);
145 } catch(std::exception
& e
) {
146 error_str
= e
.what();
149 wxMessageBox(towxstring(error_str
), _T("Error starting dump"), wxICON_EXCLAMATION
|
156 void dumper_menu::update(const std::map
<std::string
, dumper_info
>& new_dumpers
)
158 //Destroy all old entries.
159 for(auto i
: menustructure
) {
160 struct dumper_menu_struct
& m
= i
.second
;
163 for(auto mi
: m
.start_items
)
168 //And create new ones.
169 int id
= wxid_range_low
;
171 menustructure
.clear();
172 for(auto i
: new_dumpers
) {
174 menustructure
[last_processed
].sep
= AppendSeparator();
175 last_processed
= i
.first
;
177 menustructure
[i
.first
].end_item
= NULL
;
178 menustructure
[i
.first
].end_wxid
= wxID_ANY
;
179 if(!i
.second
.active
) {
180 if(i
.second
.modes
.empty()) {
181 menustructure
[i
.first
].start_items
[id
] = Append(id
, towxstring("Dump " +
182 i
.second
.name
+ "..."));
183 menustructure
[i
.first
].start_wxids
[id
++] = "";
185 for(auto j
: i
.second
.modes
) {
186 menustructure
[i
.first
].start_items
[id
] = Append(id
, towxstring("Dump " +
187 i
.second
.name
+ " (" + j
.second
+ ")..."));
188 menustructure
[i
.first
].start_wxids
[id
++] = j
.first
;
191 menustructure
[i
.first
].end_item
= Append(id
, towxstring("End " + i
.second
.name
));
192 menustructure
[i
.first
].end_wxid
= id
++;
195 existing_dumpers
= new_dumpers
;