| 628 | } |
| 629 | |
| 630 | bool Map::save(const MapFormatPtr& mapFormat) |
| 631 | { |
| 632 | if (_saveInProgress) return false; // safeguard |
| 633 | |
| 634 | if (_resource->isReadOnly()) |
| 635 | { |
| 636 | rError() << "This map is read-only and cannot be saved." << std::endl; |
| 637 | return false; |
| 638 | } |
| 639 | |
| 640 | // Check if the map file has been modified in the meantime |
| 641 | if (_resource->fileOnDiskHasBeenModifiedSinceLastSave() && |
| 642 | !radiant::FileOverwriteConfirmation::SendAndReceiveAnswer( |
| 643 | fmt::format(_("The file {0} has been modified since it was last saved,\nperhaps by another application. " |
| 644 | "Do you really want to overwrite the file?"), _mapName), _("File modification detected"))) |
| 645 | { |
| 646 | return false; |
| 647 | } |
| 648 | |
| 649 | _saveInProgress = true; |
| 650 | |
| 651 | emitMapEvent(MapSaving); |
| 652 | |
| 653 | util::ScopeTimer timer("map save"); |
| 654 | |
| 655 | bool success = false; |
| 656 | |
| 657 | // Save the actual map resource |
| 658 | try |
| 659 | { |
| 660 | _resource->save(mapFormat); |
| 661 | |
| 662 | // Clear the modified flag |
| 663 | setModified(false); |
| 664 | |
| 665 | success = true; |
| 666 | } |
| 667 | catch (IMapResource::OperationException & ex) |
| 668 | { |
| 669 | radiant::NotificationMessage::SendError(ex.what()); |
| 670 | } |
| 671 | |
| 672 | emitMapEvent(MapSaved); |
| 673 | OperationMessage::Send(_("Map saved")); |
| 674 | |
| 675 | _saveInProgress = false; |
| 676 | |
| 677 | // Redraw the views, sometimes the backbuffer containing |
| 678 | // the previous frame will remain visible |
| 679 | SceneChangeNotify(); |
| 680 | |
| 681 | return success; |
| 682 | } |
| 683 | |
| 684 | void Map::createNewMap() |
| 685 | { |
no test coverage detected