Skip to content

Commit

Permalink
#5808: Map::saveSelected falls back to the currently active map forma…
Browse files Browse the repository at this point in the history
…t if none is specified
  • Loading branch information
codereader committed Nov 14, 2021
1 parent 00fc6d3 commit 0fef59f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 7 additions & 1 deletion radiantcore/map/Map.cpp
Expand Up @@ -721,6 +721,12 @@ void Map::saveSelected(const std::string& filename, const MapFormatPtr& mapForma
format = GlobalMapFormatManager().getMapFormatForFilename(filename);
}

// Fall back to the format of the current map if the selection is empty (#5808)
if (!format)
{
format = getFormat();
}

try
{
MapResource::saveFile(
Expand Down Expand Up @@ -1154,7 +1160,7 @@ void Map::exportSelection(const cmd::ArgumentList& args)
MapFileSelection fileInfo =
MapFileManager::getMapFileSelection(false, _("Export selection"), filetype::TYPE_MAP);

if (!fileInfo.fullPath.empty())
if (!fileInfo.fullPath.empty())
{
GlobalMap().saveSelected(fileInfo.fullPath, fileInfo.mapFormat);
}
Expand Down
21 changes: 18 additions & 3 deletions test/MapExport.cpp
Expand Up @@ -289,14 +289,17 @@ brushDef3
EXPECT_NE(brushTextIndex, std::string::npos) << "Could not locate the exported brush in the expected format";
}

TEST_F(MapExportTest, ExportSelectedWithEmptyFileExtension)
namespace
{

void runExportWithEmptyFileExtension(const std::string& temporaryDataPath,const std::string& command)
{
auto brush = algorithm::createCuboidBrush(GlobalMapModule().findOrInsertWorldspawn(),
AABB(Vector3(0, 0, 0), Vector3(64, 128, 256)), "textures/darkmod/numbers/1");

Node_setSelected(brush, true);

fs::path tempPath = _context.getTemporaryDataPath();
fs::path tempPath = temporaryDataPath;
tempPath /= "export_empty_file_extension";
EXPECT_FALSE(fs::exists(tempPath)) << "File already exists";

Expand All @@ -313,7 +316,7 @@ TEST_F(MapExportTest, ExportSelectedWithEmptyFileExtension)
"" // this can happen if e.g. the *.* filter is active
});
}));
GlobalCommandSystem().executeCommand("SaveSelected");
GlobalCommandSystem().executeCommand(command);

EXPECT_TRUE(fs::exists(tempPath)) << "File still doesn't exist";

Expand All @@ -325,3 +328,15 @@ TEST_F(MapExportTest, ExportSelectedWithEmptyFileExtension)
}

}

TEST_F(MapExportTest, ExportSelectedWithEmptyFileExtension)
{
runExportWithEmptyFileExtension(_context.getTemporaryDataPath(), "SaveSelected");
}

TEST_F(MapExportTest, ExportPrefabWithEmptyFileExtension)
{
runExportWithEmptyFileExtension(_context.getTemporaryDataPath(), "SaveSelectedAsPrefab");
}

}

0 comments on commit 0fef59f

Please sign in to comment.