From a9a93c07c33a51501bb4c4d7416c5b1a0a0820fb Mon Sep 17 00:00:00 2001 From: twanvl Date: Thu, 21 Dec 2006 22:09:42 +0000 Subject: [PATCH] exception/error handling git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@137 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/control/card_list.cpp | 6 +++--- src/gui/control/image_card_list.cpp | 22 +++++++++++++--------- src/gui/thumbnail_thread.cpp | 12 +++++++----- src/script/script_manager.cpp | 8 ++++++++ 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/gui/control/card_list.cpp b/src/gui/control/card_list.cpp index a99ccaa3..c4023086 100644 --- a/src/gui/control/card_list.cpp +++ b/src/gui/control/card_list.cpp @@ -269,9 +269,9 @@ void CardListBase::rebuild() { FOR_EACH(f, new_column_fields) { ColumnSettings& cs = settings.columnSettingsFor(*set->game, *f.second); int align; - if (f.second->card_list_align == ALIGN_RIGHT) align = wxLIST_FORMAT_RIGHT; - else if (f.second->card_list_align == ALIGN_CENTER) align = wxLIST_FORMAT_CENTRE; - else align = wxLIST_FORMAT_LEFT; + if (f.second->card_list_align & ALIGN_RIGHT) align = wxLIST_FORMAT_RIGHT; + else if (f.second->card_list_align & ALIGN_CENTER) align = wxLIST_FORMAT_CENTRE; + else align = wxLIST_FORMAT_LEFT; InsertColumn((long)column_fields.size(), capitalize(f.second->card_list_name), align, cs.width); column_fields.push_back(f.second); } diff --git a/src/gui/control/image_card_list.cpp b/src/gui/control/image_card_list.cpp index d8c85f8f..14bc6cc9 100644 --- a/src/gui/control/image_card_list.cpp +++ b/src/gui/control/image_card_list.cpp @@ -57,15 +57,19 @@ class CardThumbnailRequest : public ThumbnailRequest { , filename(filename) {} virtual Image generate() { - ImageCardList* parent = (ImageCardList*)owner; - Image image; - if (image.LoadFile(*parent->set->openIn(filename))) { - // two step anti aliased resampling - image.Rescale(36, 28); // step 1: no anti aliassing - Image image2(18, 14, false); // step 2: with anti aliassing - resample(image, image2); - return image2; - } else { + try { + ImageCardList* parent = (ImageCardList*)owner; + Image image; + if (image.LoadFile(*parent->set->openIn(filename))) { + // two step anti aliased resampling + image.Rescale(36, 28); // step 1: no anti aliassing + Image image2(18, 14, false); // step 2: with anti aliassing + resample(image, image2); + return image2; + } else { + return Image(); + } + } catch (...) { return Image(); } } diff --git a/src/gui/thumbnail_thread.cpp b/src/gui/thumbnail_thread.cpp index 106dd12b..e4872f46 100644 --- a/src/gui/thumbnail_thread.cpp +++ b/src/gui/thumbnail_thread.cpp @@ -153,11 +153,13 @@ bool ThumbnailThread::done(void* owner) { // store image r.first->store(r.second); // store in cache - String filename = image_cache_dir() + safeFilename(r.first->cache_name) + _(".png"); - r.second.SaveFile(filename, wxBITMAP_TYPE_PNG); - // set modification time - wxFileName fn(filename); - fn.SetTimes(0, &r.first->modified, 0); + if (r.second.Ok()) { + String filename = image_cache_dir() + safeFilename(r.first->cache_name) + _(".png"); + r.second.SaveFile(filename, wxBITMAP_TYPE_PNG); + // set modification time + wxFileName fn(filename); + fn.SetTimes(0, &r.first->modified, 0); + } // remove from name list request_names.erase(r.first); } diff --git a/src/script/script_manager.cpp b/src/script/script_manager.cpp index 02acc874..5bcec7ff 100644 --- a/src/script/script_manager.cpp +++ b/src/script/script_manager.cpp @@ -142,6 +142,14 @@ void SetScriptManager::onAction(const Action& action, bool undone) { TYPE_CASE_(action, ScriptValueEvent) { return; // Don't go into an infinite loop because of our own events } + TYPE_CASE(action, AddCardAction) { + // update the added card specificly + Context& ctx = getContext(action.card); + FOR_EACH(v, action.card->data) { + v->update(ctx); + } + // note: fallthrough + } TYPE_CASE_(action, CardListAction) { updateAllDependend(set.game->dependent_scripts_cards); }