Commit 7fad3ad9 authored by twanvl's avatar twanvl

(formating)

parent eac09654
...@@ -15,56 +15,56 @@ DECLARE_TYPEOF_COLLECTION(FileFormatP); ...@@ -15,56 +15,56 @@ DECLARE_TYPEOF_COLLECTION(FileFormatP);
// ----------------------------------------------------------------------------- : Formats // ----------------------------------------------------------------------------- : Formats
// All supported file formats // All supported file formats
vector<FileFormatP> fileFormats; vector<FileFormatP> file_formats;
void initFileFormats() { void init_file_formats() {
//fileFormats.push_back(new_shared<MSE2FileFilter>()); //file_formats.push_back(new_shared<MSE2FileFilter>());
//fileFormats.push_back(new_shared<MSE1FileFilter>()); //file_formats.push_back(new_shared<MSE1FileFilter>());
//fileFormats.push_back(new_shared<MtgEditorFileFilter>()); //file_formats.push_back(new_shared<MtgEditorFileFilter>());
} }
String importFormats() { String import_formats() {
String allExtensions; // type1;type2 String all_extensions; // type1;type2
String typeStrings; // |name1|type1|name2|type2 String type_strings; // |name1|type1|name2|type2
FOR_EACH(f, fileFormats) { FOR_EACH(f, file_formats) {
if (f->canImport()) { if (f->canImport()) {
if (!allExtensions.empty()) allExtensions += _(";"); if (!all_extensions.empty()) all_extensions += _(";");
allExtensions += _("*.") + f->extension(); all_extensions += _("*.") + f->extension();
typeStrings += _("|") + f->name() + _("|*.") + f->extension(); type_strings += _("|") + f->name() + _("|*.") + f->extension();
} }
} }
return _("Set files|") + allExtensions + typeStrings + _("|All files (*.*)|*.*"); return _("Set files|") + all_extensions + type_strings + _("|All files (*.*)|*.*");
} }
String exportFormats(const Game& game) { String export_formats(const Game& game) {
String typeStrings; // name1|type1|name2|type2 String type_strings; // name1|type1|name2|type2
FOR_EACH(f, fileFormats) { FOR_EACH(f, file_formats) {
if (f->canExport(game)) { if (f->canExport(game)) {
if (!typeStrings.empty()) typeStrings += _("|"); if (!type_strings.empty()) type_strings += _("|");
typeStrings += f->name() + _("|*.") + f->extension(); type_strings += f->name() + _("|*.") + f->extension();
} }
} }
return typeStrings; return type_strings;
} }
void exportSet(const Set& set, const String& filename, size_t formatType) { void export_set(const Set& set, const String& filename, size_t format_type) {
FileFormatP format = fileFormats.at(formatType); FileFormatP format = file_formats.at(format_type);
if (!format->canExport(*set.game)) { if (!format->canExport(*set.game)) {
throw InternalError(_("File format doesn't apply to set")); throw InternalError(_("File format doesn't apply to set"));
} }
format->exportSet(set, filename); format->exportSet(set, filename);
} }
SetP importSet(String name) { SetP import_set(String name) {
size_t pos = name.find_last_of(_('.')); size_t pos = name.find_last_of(_('.'));
String extension = pos==String::npos ? _("") : name.substr(pos + 1); String extension = pos==String::npos ? _("") : name.substr(pos + 1);
// determine format // determine format
FOR_EACH(f, fileFormats) { FOR_EACH(f, file_formats) {
if (f->extension() == extension) { if (f->extension() == extension) {
return f->importSet(name); return f->importSet(name);
} }
} }
// default : use first format = MSE2 format // default: use first format = MSE2 format
assert(!fileFormats.empty() && fileFormats[0]->canImport()); assert(!file_formats.empty() && file_formats[0]->canImport());
return fileFormats[0]->importSet(name); return file_formats[0]->importSet(name);
} }
\ No newline at end of file
...@@ -42,18 +42,18 @@ class FileFormat { ...@@ -42,18 +42,18 @@ class FileFormat {
/// Initialize the list of file formats /// Initialize the list of file formats
/** Must be called before any other methods of this header */ /** Must be called before any other methods of this header */
void initFileFormats(); void init_file_formats();
/// List of supported import formats /// List of supported import formats
/** Formated as _("All supported (type1,...)|type1,...|name|type|...|All files(*.*)|*.*"). /** Formated as _("All supported (type1,...)|type1,...|name|type|...|All files(*.*)|*.*").
* For use in file selection dialogs. * For use in file selection dialogs.
*/ */
String importFormats(); String import_formats();
// List of supported export formats that a set in a specific game can be exported. // List of supported export formats that a set in a specific game can be exported.
/** Similair format as importFormats, except for _('all supported') and _('all files') /** Similair format as importFormats, except for 'all supported' and 'all files'
*/ */
String exportFormats(const Game& game); String export_formats(const Game& game);
/// Opens a set with the specified filename. /// Opens a set with the specified filename.
/** File format is chosen based on the extension, default is fileFormats[0] /** File format is chosen based on the extension, default is fileFormats[0]
...@@ -64,12 +64,12 @@ String exportFormats(const Game& game); ...@@ -64,12 +64,12 @@ String exportFormats(const Game& game);
* changing the recent set list could change the filename while we are opening it * changing the recent set list could change the filename while we are opening it
* (which would be bad) * (which would be bad)
*/ */
SetP importSet(String name); SetP import_set(String name);
/// Save a set under the specified name. /// Save a set under the specified name.
/** filterType specifies what format to use for saving, used as index in the list of file formats /** filterType specifies what format to use for saving, used as index in the list of file formats
*/ */
void exportSet(const Set& set, const String& filename, size_t formatType); void export_set(const Set& set, const String& filename, size_t format_type);
// ----------------------------------------------------------------------------- : Export // ----------------------------------------------------------------------------- : Export
......
...@@ -294,7 +294,7 @@ bool SetWindow::askSaveAndContinue() { ...@@ -294,7 +294,7 @@ bool SetWindow::askSaveAndContinue() {
/* try { /* try {
if (set->needSaveAs()) { if (set->needSaveAs()) {
// need save as // need save as
FileDialog dlg(&this, _("Save a set"), _(""), _(""), exportFormats(set->game), wxSAVE | wxOVERWRITE_PROMPT); FileDialog dlg(&this, _("Save a set"), _(""), _(""), export_formats(set->game), wxSAVE | wxOVERWRITE_PROMPT);
if (dlg.showModal() == wxID_OK) { if (dlg.showModal() == wxID_OK) {
exportSet(set, dlg.path, dlg.filterIndex); exportSet(set, dlg.path, dlg.filterIndex);
return true; return true;
...@@ -374,9 +374,9 @@ void SetWindow::onFileNew(wxCommandEvent&) { ...@@ -374,9 +374,9 @@ void SetWindow::onFileNew(wxCommandEvent&) {
void SetWindow::onFileOpen(wxCommandEvent&) { void SetWindow::onFileOpen(wxCommandEvent&) {
if (!askSaveAndContinue()) return; if (!askSaveAndContinue()) return;
wxFileDialog dlg(this, _("Open a set"), _(""), _(""), importFormats(), wxOPEN); wxFileDialog dlg(this, _("Open a set"), _(""), _(""), import_formats(), wxOPEN);
if (dlg.ShowModal() == wxID_OK) { if (dlg.ShowModal() == wxID_OK) {
set = importSet(dlg.GetPath()); set = import_set(dlg.GetPath());
} }
} }
...@@ -391,9 +391,9 @@ void SetWindow::onFileSave(wxCommandEvent& ev) { ...@@ -391,9 +391,9 @@ void SetWindow::onFileSave(wxCommandEvent& ev) {
} }
void SetWindow::onFileSaveAs(wxCommandEvent&) { void SetWindow::onFileSaveAs(wxCommandEvent&) {
wxFileDialog dlg(this, _("Save a set"), _(""), _(""), exportFormats(*set->game), wxSAVE | wxOVERWRITE_PROMPT); wxFileDialog dlg(this, _("Save a set"), _(""), _(""), export_formats(*set->game), wxSAVE | wxOVERWRITE_PROMPT);
if (dlg.ShowModal() == wxID_OK) { if (dlg.ShowModal() == wxID_OK) {
exportSet(*set, dlg.GetPath(), dlg.GetFilterIndex()); export_set(*set, dlg.GetPath(), dlg.GetFilterIndex());
} }
} }
......
...@@ -37,7 +37,7 @@ IMPLEMENT_APP(MSE) ...@@ -37,7 +37,7 @@ IMPLEMENT_APP(MSE)
bool MSE::OnInit() { bool MSE::OnInit() {
try { try {
wxInitAllImageHandlers(); wxInitAllImageHandlers();
initFileFormats(); init_file_formats();
settings.read(); settings.read();
//Window* wnd = new SymbolWindow(nullptr); //Window* wnd = new SymbolWindow(nullptr);
//GameP g = Game::byName(_("magic")) //GameP g = Game::byName(_("magic"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment