MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / OnSaveAttachment

Method OnSaveAttachment

lib/mdflib/mdfviewer/src/mdfdocument.cpp:207–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205}
206
207void MdfDocument::OnSaveAttachment(wxCommandEvent &) {
208 const auto id = GetSelectedBlockId();
209 const auto *block = GetBlock(id);
210 if (block == nullptr) {
211 return;
212 }
213 const auto* at4 = dynamic_cast<const mdf::detail::At4Block*>(block);
214 if (at4 == nullptr) {
215 return;
216 }
217
218 wxFileDialog save_dialog(wxGetActiveWindow(), "Select the file name for the attachment",
219 "",
220 wxString::FromUTF8(at4->FileName()),
221 "All Files (*.*)|*.*",
222 wxFD_OVERWRITE_PROMPT | wxFD_SAVE);
223 auto ret = save_dialog.ShowModal();
224 if (ret != wxID_OK) {
225 return;
226 }
227 std::string filename = std::string(save_dialog.GetPath().mb_str(wxConvUTF8));
228 const auto ok = reader_->ExportAttachmentData(*at4, filename);
229 if (!ok) {
230 wxMessageBox("Failed to create the file.\nMore information in the log file.",
231 "File Save Error",
232 wxOK | wxCENTRE | wxICON_ERROR);
233 return;
234 }
235
236 std::ostringstream open;
237 open << "Do you want to open the file ?" << std::endl
238 << "File: " << filename;
239 auto o = wxMessageBox(wxString::FromUTF8(open.str()),"Open File",
240 wxYES_NO | wxNO_DEFAULT | wxCENTRE | wxICON_QUESTION);
241 if (o == wxYES) {
242 auto& app = wxGetApp();
243 app.OpenFile(filename);
244 }
245}
246
247void MdfDocument::OnUpdateSaveAttachment(wxUpdateUIEvent &event) {
248 if (!reader_) {

Callers

nothing calls this directly

Calls 4

GetPathMethod · 0.80
ExportAttachmentDataMethod · 0.80
FileNameMethod · 0.45
OpenFileMethod · 0.45

Tested by

no test coverage detected