| 3466 | } |
| 3467 | |
| 3468 | void OnCommand(wxCommandEvent &evt) |
| 3469 | { |
| 3470 | if (evt.GetId() == IDSD_CHANGENUMROWS) |
| 3471 | { |
| 3472 | long l = 0; |
| 3473 | wxString result = wxGetTextFromUser("Enter number of data rows", "Edit Table", |
| 3474 | wxString::Format("%d", Grid->GetNumberRows()), this); |
| 3475 | if (result.IsEmpty()) return; |
| 3476 | |
| 3477 | if (!result.ToLong(&l)) |
| 3478 | return; |
| 3479 | |
| 3480 | if (l > 0) |
| 3481 | { |
| 3482 | Grid->ResizeGrid(l, 1); |
| 3483 | } |
| 3484 | else |
| 3485 | wxMessageBox("Invalid number of rows or non-numeric entry."); |
| 3486 | } |
| 3487 | else if (evt.GetId() == IDSD_COPY) |
| 3488 | Grid->Copy(true); |
| 3489 | else if (evt.GetId() == IDSD_PASTE) |
| 3490 | Grid->Paste(wxExtGridCtrl::PASTE_ALL_RESIZE_ROWS); |
| 3491 | else if (evt.GetId() == IDSD_IMPORT) |
| 3492 | { |
| 3493 | wxFileDialog dlg(this, "Select data file to import"); |
| 3494 | if (dlg.ShowModal() != wxID_OK) return; |
| 3495 | FILE *fp = fopen(dlg.GetPath().c_str(), "r"); |
| 3496 | if (!fp) |
| 3497 | { |
| 3498 | wxMessageBox("Could not open file for reading:\n\n" + dlg.GetPath()); |
| 3499 | return; |
| 3500 | } |
| 3501 | wxArrayString *arr = GetData(); |
| 3502 | arr->Clear(); |
| 3503 | char buf[128]; |
| 3504 | while (fgets(buf, 127, fp) != NULL) |
| 3505 | { |
| 3506 | buf[strcspn(buf, "\r\n")] = 0; |
| 3507 | arr->push_back(buf); |
| 3508 | } |
| 3509 | fclose(fp); |
| 3510 | SetData(arr); |
| 3511 | } |
| 3512 | else if (evt.GetId() == IDSD_EXPORT) |
| 3513 | { |
| 3514 | wxFileDialog dlg(this, "Select data file to export to", wxEmptyString, wxEmptyString, "*.*", wxFD_SAVE | wxFD_OVERWRITE_PROMPT); |
| 3515 | if (dlg.ShowModal() != wxID_OK) return; |
| 3516 | |
| 3517 | FILE *fp = fopen(dlg.GetPath().c_str(), "w"); |
| 3518 | if (!fp) |
| 3519 | { |
| 3520 | wxMessageBox("Could not open file for writing."); |
| 3521 | return; |
| 3522 | } |
| 3523 | |
| 3524 | for (size_t i = 0; i<mData->Count(); i++) |
| 3525 | fprintf(fp, "%s\n", (const char *)mData->Item(i).c_str()); |
nothing calls this directly
no test coverage detected