From 21ea45c9c5aa7772ed5b06a40013d8ab31793166 Mon Sep 17 00:00:00 2001 From: GenevensiS <66968533+G-e-n-e-v-e-n-s-i-S@users.noreply.github.com> Date: Wed, 7 Jan 2026 02:41:57 +0100 Subject: [PATCH] add error messages to bulk modification --- src/data/action/value.cpp | 2 +- src/gfx/generated_image.cpp | 4 +- src/gui/bulk_modification_window.cpp | 97 ++++++++++++++++++++++------ 3 files changed, 82 insertions(+), 21 deletions(-) diff --git a/src/data/action/value.cpp b/src/data/action/value.cpp index 4f0b09f1..920c94a4 100644 --- a/src/data/action/value.cpp +++ b/src/data/action/value.cpp @@ -215,7 +215,7 @@ void ScriptStyleEvent::perform(bool) { BulkAction::BulkAction(const vector>& actions, const SetP& set, CardListBase* card_list_window) : actions(actions), set(set), card_list_window(card_list_window) { - if (actions.empty()) throw InternalError(_("BulkAction created with no actions")); + if (actions.empty()) throw ScriptError(_("BulkAction created with no actions")); name_do = actions.front()->getName(false) + _(" ") + _ACTION_("bulk"); name_undo = actions.front()->getName(true) + _(" ") + _ACTION_("bulk"); } diff --git a/src/gfx/generated_image.cpp b/src/gfx/generated_image.cpp index 257b42f4..d0c2d01c 100644 --- a/src/gfx/generated_image.cpp +++ b/src/gfx/generated_image.cpp @@ -695,7 +695,7 @@ ImportedImage::ImportedImage(Set* set, const String& filepath) if (!img.IsOk()) throw ScriptError(_ERROR_1_("import not image", loadpath)); // add the file to the set (or overwrite it if pre-existing), save set - savename = normalize_internal_filename(loadpath); + savename = normalize_internal_filename(loadpath + _(".png")); savename.Replace(":", "-"); savename.Replace("/", "-"); auto outStream = set->openOut(savename); @@ -739,7 +739,7 @@ DownloadedImage::DownloadedImage(Set* set, const String& url) if (!img.IsOk()) throw ScriptError(_ERROR_("web request corrupted")); // add the file to the set (or overwrite it if pre-existing), save set - savename = normalize_internal_filename(loadpath); + savename = normalize_internal_filename(loadpath + _(".png")); savename.Replace(":", "-"); savename.Replace("/", "-"); auto outStream = set->openOut(savename); diff --git a/src/gui/bulk_modification_window.cpp b/src/gui/bulk_modification_window.cpp index 2c750187..5bdbc3fb 100644 --- a/src/gui/bulk_modification_window.cpp +++ b/src/gui/bulk_modification_window.cpp @@ -186,10 +186,10 @@ void BulkModificationWindow::onOk(wxCommandEvent&) { } else { // predicate FOR_EACH(card, set->cards) { Context& ctx = set->getContext(card); - ScriptValueP result = predicate_script->eval(ctx, false); + ScriptValueP result = predicate_script->eval(ctx); if (result->type() != SCRIPT_BOOL) { - queue_message(MESSAGE_ERROR, _ERROR_("bulk modify predicate is not bool")); - EndModal(wxID_ABORT); + wxMessageDialog dial = wxMessageDialog(this, _ERROR_1_("bulk modify predicate is not bool", result->typeName())); + dial.ShowModal(); return; } if (result->toBool()) { @@ -199,8 +199,8 @@ void BulkModificationWindow::onOk(wxCommandEvent&) { } int count = cards.size(); if (count == 0) { - queue_message(MESSAGE_ERROR, _ERROR_("bulk modify no cards")); - EndModal(wxID_ABORT); + wxMessageDialog dial = wxMessageDialog(this, selection_type == 3 ? _ERROR_("bulk modify no cards verify") : _ERROR_("bulk modify no cards")); + dial.ShowModal(); return; } // get the new script values @@ -212,9 +212,12 @@ void BulkModificationWindow::onOk(wxCommandEvent&) { FOR_EACH(card, cards) { Context& ctx = set->getContext(card); ScriptValueP new_value = modification_script->eval(ctx, false); - if (new_value->type() != SCRIPT_STRING) { - queue_message(MESSAGE_ERROR, _ERROR_("bulk modify mod is not string")); - EndModal(wxID_ABORT); + if (new_value->type() == SCRIPT_NIL) { + queue_message(MESSAGE_WARNING, _ERROR_1_("bulk modify mod is nil", card->identification())); + } + else if (new_value->type() != SCRIPT_STRING) { + wxMessageDialog dial = wxMessageDialog(this, _ERROR_1_("bulk modify mod is not string", new_value->typeName())); + dial.ShowModal(); return; } new_values.push_back(new_value->toString()); @@ -244,6 +247,9 @@ void BulkModificationWindow::onOk(wxCommandEvent&) { values.push_back(value); Context& ctx = set->getContext(card); ScriptValueP new_value = modification_script->eval(ctx, false); + if (new_value->type() == SCRIPT_NIL) { + queue_message(MESSAGE_WARNING, _ERROR_1_("bulk modify mod is nil", card->identification())); + } new_values.push_back(new_value); } assert(count == values.size()); @@ -251,6 +257,12 @@ void BulkModificationWindow::onOk(wxCommandEvent&) { // make the modifications (I have lost my battle with c++ templates) if (dynamic_cast(values.front())) { for (int i = 0; i < count; ++i) { + if (new_values[i]->type() == SCRIPT_NIL) continue; + if (new_values[i]->type() != SCRIPT_STRING) { + wxMessageDialog dial = wxMessageDialog(this, _ERROR_1_("bulk modify mod is not string", new_values[i]->typeName())); + dial.ShowModal(); + return; + } TextValue* value = dynamic_cast(values[i]); TextValue::ValueType new_value = new_values[i]->toString(); shared_ptr> action = make_shared>(value, new_value); @@ -260,6 +272,12 @@ void BulkModificationWindow::onOk(wxCommandEvent&) { } else if (dynamic_cast(values.front())) { for (int i = 0; i < count; ++i) { + if (new_values[i]->type() == SCRIPT_NIL) continue; + if (new_values[i]->type() != SCRIPT_STRING) { + wxMessageDialog dial = wxMessageDialog(this, _ERROR_1_("bulk modify mod is not string", new_values[i]->typeName())); + dial.ShowModal(); + return; + } MultipleChoiceValue* value = dynamic_cast(values[i]); MultipleChoiceValue::ValueType new_value = { new_values[i]->toString(), _("") }; shared_ptr> action = make_shared>(value, new_value); @@ -269,6 +287,12 @@ void BulkModificationWindow::onOk(wxCommandEvent&) { } else if (dynamic_cast(values.front())) { for (int i = 0; i < count; ++i) { + if (new_values[i]->type() == SCRIPT_NIL) continue; + if (new_values[i]->type() != SCRIPT_STRING) { + wxMessageDialog dial = wxMessageDialog(this, _ERROR_1_("bulk modify mod is not string", new_values[i]->typeName())); + dial.ShowModal(); + return; + } ChoiceValue* value = dynamic_cast(values[i]); ChoiceValue::ValueType new_value = new_values[i]->toString(); shared_ptr> action = make_shared>(value, new_value); @@ -278,6 +302,12 @@ void BulkModificationWindow::onOk(wxCommandEvent&) { } else if (dynamic_cast(values.front())) { for (int i = 0; i < count; ++i) { + if (new_values[i]->type() == SCRIPT_NIL) continue; + if (new_values[i]->type() != SCRIPT_STRING) { + wxMessageDialog dial = wxMessageDialog(this, _ERROR_1_("bulk modify mod is not string", new_values[i]->typeName())); + dial.ShowModal(); + return; + } PackageChoiceValue* value = dynamic_cast(values[i]); PackageChoiceValue::ValueType new_value = new_values[i]->toString(); shared_ptr> action = make_shared>(value, new_value); @@ -287,41 +317,72 @@ void BulkModificationWindow::onOk(wxCommandEvent&) { } else if (dynamic_cast(values.front())) { for (int i = 0; i < count; ++i) { - ColorValue* value = dynamic_cast(values[i]); - ColorValue::ValueType new_value = new_values[i]->toColor(); - shared_ptr> action = make_shared>(value, new_value); - action->setCard(cards[i]); - actions.push_back(action); + if (new_values[i]->type() == SCRIPT_NIL) continue; + try { + ColorValue::ValueType new_value = new_values[i]->toColor(); + ColorValue* value = dynamic_cast(values[i]); + shared_ptr> action = make_shared>(value, new_value); + action->setCard(cards[i]); + actions.push_back(action); + } + catch (...) { + wxMessageDialog dial = wxMessageDialog(this, _ERROR_1_("bulk modify mod is not color", new_values[i]->typeName())); + dial.ShowModal(); + return; + } } } else if (dynamic_cast(values.front())) { for (int i = 0; i < count; ++i) { - ImageValue* value = dynamic_cast(values[i]); + if (new_values[i]->type() == SCRIPT_NIL) continue; if (ExternalImage* img = dynamic_cast(new_values[i].get())) { + ImageValue* value = dynamic_cast(values[i]); ImageValue::ValueType new_value = LocalFileName::fromReadString(img->toString(), ""); shared_ptr> action = make_shared>(value, new_value); action->setCard(cards[i]); actions.push_back(action); } + else { + wxMessageDialog dial = wxMessageDialog(this, _ERROR_1_("bulk modify mod is not image", new_values[i]->typeName())); + dial.ShowModal(); + return; + } } } else if (dynamic_cast(values.front())) { for (int i = 0; i < count; ++i) { - SymbolValue* value = dynamic_cast(values[i]); + if (new_values[i]->type() == SCRIPT_NIL) continue; if (ExternalImage* img = dynamic_cast(new_values[i].get())) { + SymbolValue* value = dynamic_cast(values[i]); SymbolValue::ValueType new_value = LocalFileName::fromReadString(img->toString(), ""); shared_ptr> action = make_shared>(value, new_value); action->setCard(cards[i]); actions.push_back(action); } + else { + wxMessageDialog dial = wxMessageDialog(this, _ERROR_1_("bulk modify mod is not image", new_values[i]->typeName())); + dial.ShowModal(); + return; + } } } else { - queue_message(MESSAGE_ERROR, _ERROR_("bulk modify script type unknown")); + wxMessageDialog dial = wxMessageDialog(this, _ERROR_1_("bulk modify value type unknown", field_name)); + dial.ShowModal(); + return; } } - set->actions.addAction(make_unique(actions, set, card_list_window), false); - EndModal(wxID_OK); + if (actions.empty()) { + wxMessageDialog dial = wxMessageDialog(this, _ERROR_("bulk modify nothing")); + dial.ShowModal(); + return; + } + else { + set->actions.addAction(make_unique(actions, set, card_list_window), false); + wxMessageDialog dial = wxMessageDialog(this, _ERROR_1_("bulk modify success", String() << actions.size())); + dial.ShowModal(); + EndModal(wxID_OK); + } } BEGIN_EVENT_TABLE(BulkModificationWindow, wxDialog)