Skip to content

Commit

Permalink
Move some string constants to filetypes namespace in ifiletypes.h
Browse files Browse the repository at this point in the history
Tweak model exporter display names to avoid double extensions showing up in the FileChooser dialog.
  • Loading branch information
codereader committed Aug 16, 2017
1 parent 42f57aa commit 535c54c
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 20 deletions.
11 changes: 11 additions & 0 deletions include/ifiletypes.h
Expand Up @@ -70,6 +70,17 @@ class IFileTypeRegistry :
virtual FileTypePatterns getPatternsForType(const std::string& fileType) = 0;
};

namespace filetype
{

// Some well-known file type constants
const char* const TYPE_MAP = "map";
const char* const TYPE_PREFAB = "prefab";
const char* const TYPE_REGION = "region";
const char* const TYPE_MODEL_EXPORT = "modelexport";

}

inline IFileTypeRegistry& GlobalFiletypes()
{
// Cache the reference locally
Expand Down
2 changes: 1 addition & 1 deletion libs/wxutil/FileChooser.cpp
Expand Up @@ -70,7 +70,7 @@ void FileChooser::construct()

for (FileTypePatterns::const_iterator i = patterns.begin(); i != patterns.end(); ++i)
{
if (!_open && _fileType == "map")
if (!_open && _fileType == filetype::TYPE_MAP)
{
std::set<map::MapFormatPtr> formats = GlobalMapFormatManager().getMapFormatList(i->extension);

Expand Down
2 changes: 1 addition & 1 deletion plugins/model/AseExporter.cpp
Expand Up @@ -19,7 +19,7 @@ IModelExporterPtr AseExporter::clone()

const std::string& AseExporter::getDisplayName() const
{
static std::string _extension("ASCII Scene Export (.ase)");
static std::string _extension("ASCII Scene Export");
return _extension;
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/model/Lwo2Exporter.cpp
Expand Up @@ -72,7 +72,7 @@ IModelExporterPtr Lwo2Exporter::clone()

const std::string& Lwo2Exporter::getDisplayName() const
{
static std::string _extension("Lightwave Object File (.lwo)");
static std::string _extension("Lightwave Object File");
return _extension;
}

Expand Down
14 changes: 7 additions & 7 deletions radiant/map/Map.cpp
Expand Up @@ -655,7 +655,7 @@ bool Map::saveAs()
if (_saveInProgress) return false; // safeguard

MapFileSelection fileInfo =
MapFileManager::getMapFileSelection(false, _("Save Map"), "map", getMapName());
MapFileManager::getMapFileSelection(false, _("Save Map"), filetype::TYPE_MAP, getMapName());

if (!fileInfo.fullPath.empty())
{
Expand Down Expand Up @@ -695,7 +695,7 @@ bool Map::saveCopyAs()
}

MapFileSelection fileInfo =
MapFileManager::getMapFileSelection(false, _("Save Copy As..."), "map", _lastCopyMapName);
MapFileManager::getMapFileSelection(false, _("Save Copy As..."), filetype::TYPE_MAP, _lastCopyMapName);

if (!fileInfo.fullPath.empty())
{
Expand All @@ -713,7 +713,7 @@ bool Map::saveCopyAs()
void Map::loadPrefabAt(const Vector3& targetCoords)
{
/*MapFileSelection fileInfo =
MapFileManager::getMapFileSelection(true, _("Load Prefab"), "prefab");*/
MapFileManager::getMapFileSelection(true, _("Load Prefab"), filetype::TYPE_PREFAB);*/

ui::PrefabSelector::Result result = ui::PrefabSelector::ChoosePrefab();

Expand Down Expand Up @@ -802,7 +802,7 @@ void Map::openMap(const cmd::ArgumentList& args)
return;

// Get the map file name to load
MapFileSelection fileInfo = MapFileManager::getMapFileSelection(true, _("Open map"), "map");
MapFileSelection fileInfo = MapFileManager::getMapFileSelection(true, _("Open map"), filetype::TYPE_MAP);

if (!fileInfo.fullPath.empty())
{
Expand All @@ -816,7 +816,7 @@ void Map::openMap(const cmd::ArgumentList& args)
void Map::importMap(const cmd::ArgumentList& args)
{
MapFileSelection fileInfo =
MapFileManager::getMapFileSelection(true, _("Import map"), "map");
MapFileManager::getMapFileSelection(true, _("Import map"), filetype::TYPE_MAP);

if (!fileInfo.fullPath.empty())
{
Expand Down Expand Up @@ -845,7 +845,7 @@ void Map::saveMap(const cmd::ArgumentList& args)
void Map::exportMap(const cmd::ArgumentList& args)
{
MapFileSelection fileInfo =
MapFileManager::getMapFileSelection(false, _("Export selection"), "map");
MapFileManager::getMapFileSelection(false, _("Export selection"), filetype::TYPE_MAP);

if (!fileInfo.fullPath.empty())
{
Expand All @@ -860,7 +860,7 @@ void Map::loadPrefab(const cmd::ArgumentList& args) {
void Map::saveSelectedAsPrefab(const cmd::ArgumentList& args)
{
MapFileSelection fileInfo =
MapFileManager::getMapFileSelection(false, _("Save selected as Prefab"), "prefab");
MapFileManager::getMapFileSelection(false, _("Save selected as Prefab"), filetype::TYPE_PREFAB);

if (!fileInfo.fullPath.empty())
{
Expand Down
10 changes: 5 additions & 5 deletions radiant/map/MapFileManager.cpp
Expand Up @@ -18,8 +18,8 @@ namespace map
MapFileManager::MapFileManager()
{
// Load the default values
_lastDirs["map"] = GlobalRegistry().get(RKEY_MAP_PATH);
_lastDirs["prefab"] = GlobalRegistry().get(RKEY_PREFAB_PATH);
_lastDirs[filetype::TYPE_MAP] = GlobalRegistry().get(RKEY_MAP_PATH);
_lastDirs[filetype::TYPE_PREFAB] = GlobalRegistry().get(RKEY_PREFAB_PATH);
}

// Instance owner method
Expand All @@ -32,9 +32,9 @@ MapFileManager& MapFileManager::getInstance()
void MapFileManager::registerFileTypes()
{
// Register the map file extension in the FileTypeRegistry
GlobalFiletypes().registerPattern("map", FileTypePattern(_("Map"), "map", "*.map"));
GlobalFiletypes().registerPattern("region", FileTypePattern(_("Region"), "reg", "*.reg"));
GlobalFiletypes().registerPattern("prefab", FileTypePattern(_("Prefab"), "pfb", "*.pfb"));
GlobalFiletypes().registerPattern(filetype::TYPE_MAP, FileTypePattern(_("Map"), "map", "*.map"));
GlobalFiletypes().registerPattern(filetype::TYPE_REGION, FileTypePattern(_("Region"), "reg", "*.reg"));
GlobalFiletypes().registerPattern(filetype::TYPE_PREFAB, FileTypePattern(_("Prefab"), "pfb", "*.pfb"));
}

// Utility method to select a map file
Expand Down
3 changes: 2 additions & 1 deletion radiant/map/RegionManager.cpp
Expand Up @@ -6,6 +6,7 @@
#include "ientity.h"
#include "ieclass.h"
#include "imainframe.h"
#include "ifiletypes.h"
#include "iscenegraph.h"
#include "iselection.h"
#include "ieventmanager.h"
Expand Down Expand Up @@ -333,7 +334,7 @@ void RegionManager::saveRegion(const cmd::ArgumentList& args)
{
// Query the desired filename from the user
MapFileSelection fileInfo =
MapFileManager::getMapFileSelection(false, _("Export region"), "region");
MapFileManager::getMapFileSelection(false, _("Export region"), filetype::TYPE_REGION);

if (!fileInfo.fullPath.empty())
{
Expand Down
2 changes: 1 addition & 1 deletion radiant/model/ModelFormatManager.cpp
Expand Up @@ -55,7 +55,7 @@ void ModelFormatManager::postModuleInitialisation()
{
std::string extLower = boost::algorithm::to_lower_copy(pair.second->getExtension());

GlobalFiletypes().registerPattern("modelexport", FileTypePattern(
GlobalFiletypes().registerPattern(filetype::TYPE_MODEL_EXPORT, FileTypePattern(
pair.second->getDisplayName(),
extLower,
"*." + extLower));
Expand Down
10 changes: 8 additions & 2 deletions radiant/ui/modelexport/ExportAsModelDialog.cpp
Expand Up @@ -3,13 +3,15 @@
#include "i18n.h"
#include "imodel.h"
#include "iselection.h"
#include "ifiletypes.h"

#include <stdexcept>
#include <sigc++/functors/mem_fun.h>
#include <wx/checkbox.h>
#include <wx/filepicker.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <boost/algorithm/string/case_conv.hpp>

#include "registry/registry.h"
#include "wxutil/dialog/MessageBox.h"
Expand Down Expand Up @@ -60,8 +62,12 @@ void ExportAsModelDialog::populateWindow()
// Push the available formats to the wxChoice control
GlobalModelFormatManager().foreachExporter([&](const model::IModelExporterPtr& exporter)
{
// Generate the display name "<exporterName> (.<ext>)"
std::string displayName = exporter->getDisplayName();
displayName += " (." + boost::algorithm::to_lower_copy(exporter->getExtension()) + ")";

// Store the exporter extension as client data
formatChoice->Append(exporter->getDisplayName(), new wxStringClientData(exporter->getExtension()));
formatChoice->Append(displayName, new wxStringClientData(exporter->getExtension()));
});

// Select the first format for starters
Expand All @@ -78,7 +84,7 @@ void ExportAsModelDialog::populateWindow()
// Replace the filepicker control with our own PathEntry
wxWindow* existing = findNamedObject<wxWindow>(this, "ExportDialogFilePicker");

wxutil::PathEntry* pathEntry = new wxutil::PathEntry(existing->GetParent(), "modelexport");
wxutil::PathEntry* pathEntry = new wxutil::PathEntry(existing->GetParent(), filetype::TYPE_MODEL_EXPORT);
pathEntry->setValue(recentPath);
pathEntry->SetName("ExportDialogFilePicker");
pathEntry->setDefaultExtension(recentFormat);
Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/prefabselector/PrefabPopulator.cpp
Expand Up @@ -55,7 +55,7 @@ void PrefabPopulator::visitFile(const std::string& filename)
wxThread::ExitCode PrefabPopulator::Entry()
{
// Get the first extension from the list of possible patterns (e.g. *.pfb or *.map)
FileTypePatterns patterns = GlobalFiletypes().getPatternsForType("prefab");
FileTypePatterns patterns = GlobalFiletypes().getPatternsForType(filetype::TYPE_PREFAB);

std::string defaultExt = "";

Expand Down

0 comments on commit 535c54c

Please sign in to comment.