| 21 | } |
| 22 | |
| 23 | int XdFileChooserDialog::Import(const std::string& defName, |
| 24 | XData::XDataPtr& newXData, |
| 25 | std::string& filename, |
| 26 | XData::XDataLoaderPtr& loader, |
| 27 | ReadableEditorDialog* editorDialog) |
| 28 | { |
| 29 | // Import the file: |
| 30 | XData::XDataMap xdMap; |
| 31 | |
| 32 | if (loader->importDef(defName,xdMap)) |
| 33 | { |
| 34 | if (xdMap.size() > 1) |
| 35 | { |
| 36 | // The requested definition has been defined in multiple files. Use the XdFileChooserDialog to pick a file. |
| 37 | // Optimally, the preview renderer would already show the selected definition. |
| 38 | XdFileChooserDialog* fcDialog = new XdFileChooserDialog(defName, xdMap, editorDialog); |
| 39 | |
| 40 | int result = fcDialog->ShowModal(); |
| 41 | |
| 42 | if (result == wxID_OK) |
| 43 | { |
| 44 | XData::XDataMap::iterator ChosenIt = xdMap.find(fcDialog->_chosenFile); |
| 45 | filename = ChosenIt->first; |
| 46 | newXData = ChosenIt->second; |
| 47 | } |
| 48 | |
| 49 | fcDialog->Destroy(); |
| 50 | |
| 51 | return result; |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | filename = xdMap.begin()->first; |
| 56 | newXData = xdMap.begin()->second; |
| 57 | |
| 58 | if (loader->getImportSummary().size() > 1) |
| 59 | { |
| 60 | std::string msg = fmt::format(_("{0} successfully imported."), defName); |
| 61 | msg += "\n\nHowever, there were some problems.\n\n"; |
| 62 | msg += _("Do you want to open the import summary?"); |
| 63 | |
| 64 | wxutil::Messagebox dialog(_("Problems during import"), |
| 65 | msg, |
| 66 | ui::IDialog::MESSAGE_ASK, editorDialog |
| 67 | ); |
| 68 | |
| 69 | if (dialog.run() == ui::IDialog::RESULT_YES) |
| 70 | { |
| 71 | editorDialog->showXdImportSummary(); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | return wxID_OK; |
| 77 | } |
| 78 | |
| 79 | throw ImportFailedException(_("Import failed")); |
| 80 | } |
nothing calls this directly
no test coverage detected