Skip to content

Commit

Permalink
ModelFormatManager registers known modelexport formats to FileTypeReg…
Browse files Browse the repository at this point in the history
…istry for use in Export Model Dialog.
  • Loading branch information
codereader committed Aug 15, 2017
1 parent 51aada0 commit 42f57aa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
13 changes: 13 additions & 0 deletions radiant/model/ModelFormatManager.cpp
@@ -1,6 +1,7 @@
#include "ModelFormatManager.h"

#include "itextstream.h"
#include "ifiletypes.h"
#include "ipreferencesystem.h"
#include <boost/algorithm/string/case_conv.hpp>

Expand Down Expand Up @@ -47,6 +48,18 @@ void ModelFormatManager::postModuleInitialisation()
}

page.appendCombo(_("Export Format for scaled Models"), RKEY_DEFAULT_MODEL_EXPORT_FORMAT, choices, true);

// Register all exporter extensions to the FileTypeRegistry

for (const ExporterMap::value_type& pair : _exporters)
{
std::string extLower = boost::algorithm::to_lower_copy(pair.second->getExtension());

GlobalFiletypes().registerPattern("modelexport", FileTypePattern(
pair.second->getDisplayName(),
extLower,
"*." + extLower));
}
}
}

Expand Down
29 changes: 26 additions & 3 deletions radiant/ui/modelexport/ExportAsModelDialog.cpp
Expand Up @@ -14,6 +14,7 @@
#include "registry/registry.h"
#include "wxutil/dialog/MessageBox.h"
#include "wxutil/ChoiceHelper.h"
#include "wxutil/PathEntry.h"
#include "map/algorithm/Export.h"

namespace ui
Expand Down Expand Up @@ -54,6 +55,8 @@ void ExportAsModelDialog::populateWindow()
wxChoice* formatChoice = findNamedObject<wxChoice>(this, "ExportDialogFormatChoice");
formatChoice->Clear();

formatChoice->Bind(wxEVT_CHOICE, sigc::mem_fun(this, &ExportAsModelDialog::onFormatSelection));

// Push the available formats to the wxChoice control
GlobalModelFormatManager().foreachExporter([&](const model::IModelExporterPtr& exporter)
{
Expand All @@ -72,7 +75,16 @@ void ExportAsModelDialog::populateWindow()
wxutil::ChoiceHelper::SelectItemByStoredString(formatChoice, recentFormat);
}

findNamedObject<wxFilePickerCtrl>(this, "ExportDialogFilePicker")->SetPath(recentPath);
// Replace the filepicker control with our own PathEntry
wxWindow* existing = findNamedObject<wxWindow>(this, "ExportDialogFilePicker");

wxutil::PathEntry* pathEntry = new wxutil::PathEntry(existing->GetParent(), "modelexport");
pathEntry->setValue(recentPath);
pathEntry->SetName("ExportDialogFilePicker");
pathEntry->setDefaultExtension(recentFormat);

existing->GetContainingSizer()->Replace(existing, pathEntry);
existing->Destroy();

bool skipCaulk = registry::getValue<bool>(RKEY_MODEL_EXPORT_SKIP_CAULK);
findNamedObject<wxCheckBox>(this, "ExportDialogSkipCaulk")->SetValue(skipCaulk);
Expand All @@ -91,7 +103,7 @@ void ExportAsModelDialog::onExport(wxCommandEvent& ev)

options.centerObjects = findNamedObject<wxCheckBox>(this, "ExportDialogCenterObjects")->GetValue();
options.skipCaulk = findNamedObject<wxCheckBox>(this, "ExportDialogSkipCaulk")->GetValue();
options.outputFilename = findNamedObject<wxFilePickerCtrl>(this, "ExportDialogFilePicker")->GetPath();
options.outputFilename = findNamedObject<wxutil::PathEntry>(this, "ExportDialogFilePicker")->getValue();
options.outputFormat = wxutil::ChoiceHelper::GetSelectedStoredString(findNamedObject<wxChoice>(this, "ExportDialogFormatChoice"));

if (options.outputFilename.empty())
Expand Down Expand Up @@ -124,6 +136,17 @@ void ExportAsModelDialog::onCancel(wxCommandEvent& ev)
EndModal(wxID_CANCEL);
}

void ExportAsModelDialog::onFormatSelection(wxCommandEvent& ev)
{
std::string selectedFormat = wxutil::ChoiceHelper::GetSelectedStoredString(
findNamedObject<wxChoice>(this, "ExportDialogFormatChoice"));

if (!selectedFormat.empty())
{
findNamedObject<wxutil::PathEntry>(this, "ExportDialogFilePicker")->setDefaultExtension(selectedFormat);
}
}

bool ExportAsModelDialog::_onDeleteEvent()
{
// Remember stuff even when X is pressed
Expand All @@ -138,7 +161,7 @@ void ExportAsModelDialog::saveOptionsToRegistry()
wxutil::ChoiceHelper::GetSelectedStoredString(findNamedObject<wxChoice>(this, "ExportDialogFormatChoice")));

registry::setValue(RKEY_MODEL_EXPORT_OUTPUT_PATH,
findNamedObject<wxFilePickerCtrl>(this, "ExportDialogFilePicker")->GetPath());
findNamedObject<wxutil::PathEntry>(this, "ExportDialogFilePicker")->getValue());

registry::setValue(RKEY_MODEL_EXPORT_SKIP_CAULK,
findNamedObject<wxCheckBox>(this, "ExportDialogSkipCaulk")->GetValue());
Expand Down
1 change: 1 addition & 0 deletions radiant/ui/modelexport/ExportAsModelDialog.h
Expand Up @@ -26,6 +26,7 @@ class ExportAsModelDialog :

void onExport(wxCommandEvent& ev);
void onCancel(wxCommandEvent& ev);
void onFormatSelection(wxCommandEvent& ev);

void saveOptionsToRegistry();
};
Expand Down

0 comments on commit 42f57aa

Please sign in to comment.