diff --git a/include/imap.h b/include/imap.h index ead5357757..feedb12f72 100644 --- a/include/imap.h +++ b/include/imap.h @@ -135,6 +135,9 @@ class IMap : */ virtual std::string getMapName() const = 0; + // Returns true if this map is still unnamed (never saved yet) + virtual bool isUnnamed() const = 0; + /** * Signal fired when the name of this map is changing. */ diff --git a/radiant/Makefile.am b/radiant/Makefile.am index b7255bee08..0f8e7d7efb 100644 --- a/radiant/Makefile.am +++ b/radiant/Makefile.am @@ -192,5 +192,6 @@ darkradiant_SOURCES = main.cpp \ settings/Win32Registry.cpp \ settings/LocalisationModule.cpp \ settings/LocalisationProvider.cpp \ + map/AutoSaver.cpp \ map/StartupMapLoader.cpp \ log/Console.cpp diff --git a/radiantcore/map/AutoSaver.cpp b/radiant/map/AutoSaver.cpp similarity index 95% rename from radiantcore/map/AutoSaver.cpp rename to radiant/map/AutoSaver.cpp index 928a246818..8a92b5922d 100644 --- a/radiantcore/map/AutoSaver.cpp +++ b/radiant/map/AutoSaver.cpp @@ -21,7 +21,6 @@ #include #include "string/string.h" #include "string/convert.h" -#include "map/Map.h" #include "module/StaticModule.h" #include "messages/NotificationMessage.h" #include "messages/AutomaticMapSaveRequest.h" @@ -141,7 +140,7 @@ void AutoMapSaver::saveSnapshot() rMessage() << "Autosaving snapshot to " << filename << std::endl; // Dump to map to the next available filename - GlobalMap().saveDirect(filename); + GlobalCommandSystem().executeCommand("SaveMapCopyAs", filename); handleSnapshotSizeLimit(existingSnapshots, snapshotPath, mapName); } @@ -255,7 +254,7 @@ void AutoMapSaver::checkSave() if (_enabled) { // only snapshot if not working on an unnamed map - if (_snapshotsEnabled && !GlobalMap().isUnnamed()) + if (_snapshotsEnabled && !GlobalMapModule().isUnnamed()) { try { @@ -268,7 +267,7 @@ void AutoMapSaver::checkSave() } else { - if (GlobalMap().isUnnamed()) + if (GlobalMapModule().isUnnamed()) { // Get the maps path (within the mod path) std::string autoSaveFilename = GlobalGameManager().getMapPath(); @@ -283,12 +282,12 @@ void AutoMapSaver::checkSave() rMessage() << "Autosaving unnamed map to " << autoSaveFilename << std::endl; // Invoke the save call - GlobalMap().saveDirect(autoSaveFilename); + GlobalCommandSystem().executeCommand("SaveMapCopyAs", autoSaveFilename); } else { // Construct the new filename (e.g. "test_autosave.map") - std::string filename = GlobalMap().getMapName(); + std::string filename = GlobalMapModule().getMapName(); std::string extension = os::getExtension(filename); // Cut off the extension @@ -299,7 +298,7 @@ void AutoMapSaver::checkSave() rMessage() << "Autosaving map to " << filename << std::endl; // Invoke the save call - GlobalMap().saveDirect(filename); + GlobalCommandSystem().executeCommand("SaveMapCopyAs", filename); } } } @@ -387,7 +386,7 @@ void AutoMapSaver::initialiseModule(const IApplicationContext& ctx) )); // Get notified when the map is loaded afresh - _signalConnections.push_back(GlobalMap().signal_mapEvent().connect( + _signalConnections.push_back(GlobalMapModule().signal_mapEvent().connect( sigc::mem_fun(*this, &AutoMapSaver::onMapEvent) )); diff --git a/radiantcore/map/AutoSaver.h b/radiant/map/AutoSaver.h similarity index 100% rename from radiantcore/map/AutoSaver.h rename to radiant/map/AutoSaver.h diff --git a/radiantcore/Makefile.am b/radiantcore/Makefile.am index 5037cc1a7f..f42527c193 100644 --- a/radiantcore/Makefile.am +++ b/radiantcore/Makefile.am @@ -144,7 +144,6 @@ libradiantcore_la_SOURCES = Radiant.cpp \ map/namespace/ComplexName.cpp \ map/namespace/Namespace.cpp \ map/namespace/NamespaceFactory.cpp \ - map/AutoSaver.cpp \ map/CounterManager.cpp \ map/EditingStopwatch.cpp \ map/EditingStopwatchInfoFileModule.cpp \ diff --git a/radiantcore/map/Map.cpp b/radiantcore/map/Map.cpp index d1cc4732bd..32380c0eee 100644 --- a/radiantcore/map/Map.cpp +++ b/radiantcore/map/Map.cpp @@ -571,22 +571,34 @@ bool Map::saveAs() void Map::saveCopyAs() { - // Let's see if we can remember a - if (_lastCopyMapName.empty()) { + // Let's see if we can remember a map name from a previous save + if (_lastCopyMapName.empty()) + { _lastCopyMapName = getMapName(); } - MapFileSelection fileInfo = - MapFileManager::getMapFileSelection(false, _("Save Copy As..."), filetype::TYPE_MAP, _lastCopyMapName); + auto fileInfo = MapFileManager::getMapFileSelection(false, + _("Save Copy As..."), filetype::TYPE_MAP, _lastCopyMapName); if (!fileInfo.fullPath.empty()) { - // Remember the last name - _lastCopyMapName = fileInfo.fullPath; + saveCopyAs(fileInfo.fullPath, fileInfo.mapFormat); + } +} - // Return the result of the actual save method - saveDirect(fileInfo.fullPath, fileInfo.mapFormat); +void Map::saveCopyAs(const std::string& absolutePath, const MapFormatPtr& mapFormat) +{ + if (absolutePath.empty()) + { + rWarning() << "Map::saveCopyAs: path must not be empty" << std::endl; + return; } + + // Remember the last name + _lastCopyMapName = absolutePath; + + // Return the result of the actual save method + saveDirect(absolutePath, mapFormat); } void Map::loadPrefabAt(const cmd::ArgumentList& args) @@ -640,7 +652,16 @@ void Map::loadPrefabAt(const cmd::ArgumentList& args) void Map::saveMapCopyAs(const cmd::ArgumentList& args) { - GlobalMap().saveCopyAs(); + if (args.size() == 0 || args[0].getString().empty()) + { + // Use the overload without arguments, it will ask for a file name + GlobalMap().saveCopyAs(); + } + else + { + // Pass the first argument we got + GlobalMap().saveCopyAs(args[0].getString()); + } } void Map::registerCommands() @@ -653,7 +674,7 @@ void Map::registerCommands() GlobalCommandSystem().addCommand("SaveSelectedAsPrefab", Map::saveSelectedAsPrefab); GlobalCommandSystem().addCommand("SaveMap", Map::saveMap); GlobalCommandSystem().addCommand("SaveMapAs", Map::saveMapAs); - GlobalCommandSystem().addCommand("SaveMapCopyAs", Map::saveMapCopyAs); + GlobalCommandSystem().addCommand("SaveMapCopyAs", Map::saveMapCopyAs, { cmd::ARGTYPE_STRING | cmd::ARGTYPE_OPTIONAL }); GlobalCommandSystem().addCommand("ExportMap", Map::exportMap); GlobalCommandSystem().addCommand("SaveSelected", Map::exportSelection); GlobalCommandSystem().addCommand("ReloadSkins", map::algorithm::reloadSkins); diff --git a/radiantcore/map/Map.h b/radiantcore/map/Map.h index 0565c5930f..f8612b1bcc 100644 --- a/radiantcore/map/Map.h +++ b/radiantcore/map/Map.h @@ -84,7 +84,7 @@ class Map : /** greebo: Returns true if the map has not been named yet. */ - bool isUnnamed() const; + bool isUnnamed() const override; /** greebo: Updates the name of the map (and triggers an update * of the mainframe window title) @@ -125,6 +125,13 @@ class Map : */ void saveCopyAs(); + /** + * Saves a copy of the current map to the given path, using the + * given format (which may be an empty reference, in which case the map format + * will be guessed from the filename). + */ + void saveCopyAs(const std::string& absolutePath, const MapFormatPtr& mapFormat = MapFormatPtr()); + /** greebo: Saves the current selection to the target . */ void saveSelected(const std::string& filename, const MapFormatPtr& mapFormat = MapFormatPtr()); diff --git a/tools/msvc/DarkRadiant.vcxproj b/tools/msvc/DarkRadiant.vcxproj index fcf057782a..5ad6c23f05 100644 --- a/tools/msvc/DarkRadiant.vcxproj +++ b/tools/msvc/DarkRadiant.vcxproj @@ -205,6 +205,7 @@ + Create @@ -392,6 +393,7 @@ + diff --git a/tools/msvc/DarkRadiant.vcxproj.filters b/tools/msvc/DarkRadiant.vcxproj.filters index e81f13555b..b632e9c161 100644 --- a/tools/msvc/DarkRadiant.vcxproj.filters +++ b/tools/msvc/DarkRadiant.vcxproj.filters @@ -670,6 +670,9 @@ src\ui + + src\map + @@ -1290,6 +1293,9 @@ src\ui\common + + src\map + diff --git a/tools/msvc/DarkRadiantCore.vcxproj b/tools/msvc/DarkRadiantCore.vcxproj index c398d68e18..46ca05c273 100644 --- a/tools/msvc/DarkRadiantCore.vcxproj +++ b/tools/msvc/DarkRadiantCore.vcxproj @@ -101,7 +101,6 @@ - @@ -802,11 +801,9 @@ - - diff --git a/tools/msvc/DarkRadiantCore.vcxproj.filters b/tools/msvc/DarkRadiantCore.vcxproj.filters index b8ed5d5739..b42f3cb427 100644 --- a/tools/msvc/DarkRadiantCore.vcxproj.filters +++ b/tools/msvc/DarkRadiantCore.vcxproj.filters @@ -925,9 +925,6 @@ src\map\infofile - - src\map - src\map @@ -1953,18 +1950,12 @@ src\map\infofile - - src\map - src\map src\map - - src\map - src\map