From 25457f851239bb589787c82e9adf9414e30b5b22 Mon Sep 17 00:00:00 2001 From: twanvl Date: Thu, 20 Dec 2007 20:03:26 +0000 Subject: [PATCH] Added --export command line flag git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@773 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/images_export_window.cpp | 43 +++++++++++++++++++------------- src/gui/images_export_window.hpp | 16 +++++++++++- src/main.cpp | 27 +++++++++++++++++++- 3 files changed, 67 insertions(+), 19 deletions(-) diff --git a/src/gui/images_export_window.cpp b/src/gui/images_export_window.cpp index 33fdd5d8..28843bd4 100644 --- a/src/gui/images_export_window.cpp +++ b/src/gui/images_export_window.cpp @@ -56,26 +56,13 @@ ImagesExportWindow::ImagesExportWindow(Window* parent, const SetP& set) // ----------------------------------------------------------------------------- : Exporting the images -void ImagesExportWindow::onOk(wxCommandEvent&) { - // Update settings - GameSettings& gs = settings.gameSettingsFor(*set->game); - gs.images_export_filename = format->GetValue(); - int sel = conflicts->GetSelection(); - if (sel == 0) gs.images_export_conflicts = CONFLICT_KEEP_OLD; - else if (sel == 1) gs.images_export_conflicts = CONFLICT_OVERWRITE; - else if (sel == 2) gs.images_export_conflicts = CONFLICT_NUMBER; - else gs.images_export_conflicts = CONFLICT_NUMBER_OVERWRITE; +void ExportCardImages::export(const SetP& set, wxFileName& fn, const String& filename_template, FilenameConflicts conflicts) { // Script - ScriptP filename_script = parse(gs.images_export_filename, nullptr, true); - // Select filename - String name = wxFileSelector(_TITLE_("export images"),_(""), _LABEL_("filename is ignored"),_(""), - _LABEL_("filename is ignored")+_("|*"), wxSAVE, this); - if (name.empty()) return; - wxFileName fn(name); + ScriptP filename_script = parse(filename_template, nullptr, true); // Export std::set used; // for CONFLICT_NUMBER_OVERWRITE FOR_EACH(card, set->cards) { - if (isSelected(card)) { + if (exportCard(card)) { // filename for this card Context& ctx = set->getContext(card); String filename = untag(ctx.eval(*filename_script)->toString()); @@ -85,7 +72,7 @@ void ImagesExportWindow::onOk(wxCommandEvent&) { // does the file exist? if (fn.FileExists()) { // file exists, what to do? - switch (gs.images_export_conflicts) { + switch (conflicts) { case CONFLICT_KEEP_OLD: goto next_card; case CONFLICT_OVERWRITE: break; case CONFLICT_NUMBER: { @@ -111,10 +98,32 @@ void ImagesExportWindow::onOk(wxCommandEvent&) { } next_card:; } +} + +void ImagesExportWindow::onOk(wxCommandEvent&) { + // Update settings + GameSettings& gs = settings.gameSettingsFor(*set->game); + gs.images_export_filename = format->GetValue(); + int sel = conflicts->GetSelection(); + if (sel == 0) gs.images_export_conflicts = CONFLICT_KEEP_OLD; + else if (sel == 1) gs.images_export_conflicts = CONFLICT_OVERWRITE; + else if (sel == 2) gs.images_export_conflicts = CONFLICT_NUMBER; + else gs.images_export_conflicts = CONFLICT_NUMBER_OVERWRITE; + // Select filename + String name = wxFileSelector(_TITLE_("export images"),_(""), _LABEL_("filename is ignored"),_(""), + _LABEL_("filename is ignored")+_("|*"), wxSAVE, this); + if (name.empty()) return; + wxFileName fn(name); + // Export + export(set, fn, gs.images_export_filename, gs.images_export_conflicts); // Done EndModal(wxID_OK); } +bool ImagesExportWindow::exportCard(const CardP& card) const { + return isSelected(card); +} + BEGIN_EVENT_TABLE(ImagesExportWindow,CardSelectWindow) EVT_BUTTON (wxID_OK, ImagesExportWindow::onOk) diff --git a/src/gui/images_export_window.hpp b/src/gui/images_export_window.hpp index 90506010..0f50f886 100644 --- a/src/gui/images_export_window.hpp +++ b/src/gui/images_export_window.hpp @@ -11,11 +11,23 @@ #include #include +#include +class wxFileName; + +// ----------------------------------------------------------------------------- : ImagesExportWindow + +/// Export the cards in a set +class ExportCardImages { + public: + void export(const SetP& set, wxFileName& filename, const String& filename_template, FilenameConflicts conflicts); + protected: + virtual bool exportCard(const CardP& card) const { return true; } +}; // ----------------------------------------------------------------------------- : ImagesExportWindow /// A window for selecting a subset of the cards from a set to export to images -class ImagesExportWindow : public CardSelectWindow { +class ImagesExportWindow : public CardSelectWindow, private ExportCardImages { public: ImagesExportWindow(Window* parent, const SetP& set); @@ -24,6 +36,8 @@ class ImagesExportWindow : public CardSelectWindow { void onOk(wxCommandEvent&); + virtual bool exportCard(const CardP& card) const; + wxTextCtrl* format; wxChoice* conflicts; }; diff --git a/src/main.cpp b/src/main.cpp index e41de97b..7cf543ac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -139,12 +140,36 @@ int MSE::OnRun() { + _(" -v --version \tShow version information.\n") + _(" --symbol-editor \tShow the symbol editor instead of the welcome window.\n") + _(" --create-installer\n") - + _(" FILE [FILE]...\tCreate an instaler named FILE, containing the listed packges.\n") ); + + _(" FILE [FILE]...\tCreate an instaler named FILE, containing the listed packges.\n") + + _(" --export\n") + + _(" FILE IMAGE \tExport the cards in a set to image files,\n") + + _(" \tIMAGE is the same format as for 'export all card images'.\n") ); return EXIT_SUCCESS; } else if (arg == _("--version") || arg == _("-v")) { // dump version write_stdout( _("Magic Set Editor\nVersion ") + app_version.toString() + version_suffix ); return EXIT_SUCCESS; + } else if (arg == _("--export")) { + if (argc <= 2) { + handle_error(Error(_("No input file specified for --export"))); + return EXIT_FAILURE; + } + SetP set = import_set(argv[2]); + // path + String out = argc >= 3 ? argv[3] : settings.gameSettingsFor(*set->game).images_export_filename; + String path = _("."); + size_t pos = out.find_last_of(_("/\\")); + if (pos != String::npos) { + path = out.substr(0, pos); + if (!wxDirExists(path)) wxMkdir(path); + path += _("/x"); + out = out.substr(pos + 1); + } + wxFileName fn(path); + // export + ExportCardImages export; + export.export(set, fn, out, CONFLICT_NUMBER_OVERWRITE); + return EXIT_SUCCESS; } else { handle_error(_("Invalid command line argument:\n") + String(argv[1])); }