diff --git a/src/gui/set/style_panel.cpp b/src/gui/set/style_panel.cpp index 834ea38b..e095c5ee 100644 --- a/src/gui/set/style_panel.cpp +++ b/src/gui/set/style_panel.cpp @@ -13,7 +13,9 @@ #include #include #include +#include #include +#include // ----------------------------------------------------------------------------- : StylePanel @@ -41,14 +43,54 @@ StylePanel::StylePanel(Window* parent, int id) void StylePanel::onChangeSet() { list->showData(set->game->name() + _("-*")); - list->select(set->stylesheet->name()); + list->select(set->stylesheet->name(), false); editor->setSet(set); preview->setSet(set); + card.reset(); + use_for_all->Enable(false); +} + +void StylePanel::onAction(const Action& action, bool undone) { + TYPE_CASE_(action, ChangeSetStyleAction) { + list->select(set->stylesheetFor(card)->name(), false); +// updateSize(); + } + TYPE_CASE(action, ChangeCardStyleAction) { + if (action.card == card) { +// preview->onAction(action, undone); // update the preview control before we determine our new size + list->select(set->stylesheetFor(card)->name(), false); +// updateSize(); + } + } } // ----------------------------------------------------------------------------- : Selection void StylePanel::selectCard(const CardP& card) { + this->card = card; preview->setCard(card); - list->select(set->stylesheetFor(card)->name()); + list->select(set->stylesheetFor(card)->name(), false); + use_for_all->Enable(card && card->stylesheet); } + +// ----------------------------------------------------------------------------- : Events + +void StylePanel::onStyleSelect(wxCommandEvent&) { + if (list->hasSelection()) { + StyleSheetP stylesheet = list->getSelection(); + if (stylesheet == set->stylesheet) { + // select no special style when selecting the same style as the set default + stylesheet = StyleSheetP(); + } + set->actions.add(new ChangeCardStyleAction(card, stylesheet)); + } +} + +void StylePanel::onUseForAll(wxCommandEvent&) { + set->actions.add(new ChangeSetStyleAction(*set, card)); +} + +BEGIN_EVENT_TABLE(StylePanel, wxPanel) + EVT_GALLERY_SELECT(wxID_ANY, StylePanel::onStyleSelect) + EVT_BUTTON (ID_STYLE_USE_FOR_ALL, StylePanel::onUseForAll) +END_EVENT_TABLE() diff --git a/src/gui/set/style_panel.hpp b/src/gui/set/style_panel.hpp index 3bafd708..e2ac871b 100644 --- a/src/gui/set/style_panel.hpp +++ b/src/gui/set/style_panel.hpp @@ -24,15 +24,22 @@ class StylePanel : public SetWindowPanel { StylePanel(Window* parent, int id); virtual void onChangeSet(); + virtual void onAction(const Action&, bool undone); // --------------------------------------------------- : Selection virtual void selectCard(const CardP& card); private: + DECLARE_EVENT_TABLE(); + CardViewer* preview; ///< Card preview PackageList* list; ///< List of stylesheets StylingEditor* editor; ///< Editor for styling information wxButton* use_for_all; + CardP card; ///< Card we are working on + + void onStyleSelect(wxCommandEvent&); + void onUseForAll(wxCommandEvent&); }; // ----------------------------------------------------------------------------- : EOF