Commit 7fad3ad9 authored by twanvl's avatar twanvl

(formating)

parent eac09654
......@@ -15,56 +15,56 @@ DECLARE_TYPEOF_COLLECTION(FileFormatP);
// ----------------------------------------------------------------------------- : Formats
// All supported file formats
vector<FileFormatP> fileFormats;
vector<FileFormatP> file_formats;
void initFileFormats() {
//fileFormats.push_back(new_shared<MSE2FileFilter>());
//fileFormats.push_back(new_shared<MSE1FileFilter>());
//fileFormats.push_back(new_shared<MtgEditorFileFilter>());
void init_file_formats() {
//file_formats.push_back(new_shared<MSE2FileFilter>());
//file_formats.push_back(new_shared<MSE1FileFilter>());
//file_formats.push_back(new_shared<MtgEditorFileFilter>());
}
String importFormats() {
String allExtensions; // type1;type2
String typeStrings; // |name1|type1|name2|type2
FOR_EACH(f, fileFormats) {
String import_formats() {
String all_extensions; // type1;type2
String type_strings; // |name1|type1|name2|type2
FOR_EACH(f, file_formats) {
if (f->canImport()) {
if (!allExtensions.empty()) allExtensions += _(";");
allExtensions += _("*.") + f->extension();
typeStrings += _("|") + f->name() + _("|*.") + f->extension();
if (!all_extensions.empty()) all_extensions += _(";");
all_extensions += _("*.") + 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 typeStrings; // name1|type1|name2|type2
FOR_EACH(f, fileFormats) {
String export_formats(const Game& game) {
String type_strings; // name1|type1|name2|type2
FOR_EACH(f, file_formats) {
if (f->canExport(game)) {
if (!typeStrings.empty()) typeStrings += _("|");
typeStrings += f->name() + _("|*.") + f->extension();
if (!type_strings.empty()) type_strings += _("|");
type_strings += f->name() + _("|*.") + f->extension();
}
}
return typeStrings;
return type_strings;
}
void exportSet(const Set& set, const String& filename, size_t formatType) {
FileFormatP format = fileFormats.at(formatType);
void export_set(const Set& set, const String& filename, size_t format_type) {
FileFormatP format = file_formats.at(format_type);
if (!format->canExport(*set.game)) {
throw InternalError(_("File format doesn't apply to set"));
}
format->exportSet(set, filename);
}
SetP importSet(String name) {
SetP import_set(String name) {
size_t pos = name.find_last_of(_('.'));
String extension = pos==String::npos ? _("") : name.substr(pos + 1);
// determine format
FOR_EACH(f, fileFormats) {
FOR_EACH(f, file_formats) {
if (f->extension() == extension) {
return f->importSet(name);
}
}
// default : use first format = MSE2 format
assert(!fileFormats.empty() && fileFormats[0]->canImport());
return fileFormats[0]->importSet(name);
// default: use first format = MSE2 format
assert(!file_formats.empty() && file_formats[0]->canImport());
return file_formats[0]->importSet(name);
}
\ No newline at end of file
......@@ -42,18 +42,18 @@ class FileFormat {
/// Initialize the list of file formats
/** Must be called before any other methods of this header */
void initFileFormats();
void init_file_formats();
/// List of supported import formats
/** Formated as _("All supported (type1,...)|type1,...|name|type|...|All files(*.*)|*.*").
* 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.
/** 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.
/** File format is chosen based on the extension, default is fileFormats[0]
......@@ -64,12 +64,12 @@ String exportFormats(const Game& game);
* changing the recent set list could change the filename while we are opening it
* (which would be bad)
*/
SetP importSet(String name);
SetP import_set(String 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
*/
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
......
......@@ -294,7 +294,7 @@ bool SetWindow::askSaveAndContinue() {
/* try {
if (set->needSaveAs()) {
// 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) {
exportSet(set, dlg.path, dlg.filterIndex);
return true;
......@@ -374,9 +374,9 @@ void SetWindow::onFileNew(wxCommandEvent&) {
void SetWindow::onFileOpen(wxCommandEvent&) {
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) {
set = importSet(dlg.GetPath());
set = import_set(dlg.GetPath());
}
}
......@@ -391,9 +391,9 @@ void SetWindow::onFileSave(wxCommandEvent& ev) {
}
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) {
exportSet(*set, dlg.GetPath(), dlg.GetFilterIndex());
export_set(*set, dlg.GetPath(), dlg.GetFilterIndex());
}
}
......
......@@ -37,7 +37,7 @@ IMPLEMENT_APP(MSE)
bool MSE::OnInit() {
try {
wxInitAllImageHandlers();
initFileFormats();
init_file_formats();
settings.read();
//Window* wnd = new SymbolWindow(nullptr);
//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