From 95a5c2f42b9551320c145300eb6cbabc28117306 Mon Sep 17 00:00:00 2001 From: twanvl Date: Sun, 10 Dec 2006 16:47:56 +0000 Subject: [PATCH] fixed update ui for NewWindow git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@106 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/format/mse1.cpp | 4 +-- src/data/format/mse2.cpp | 1 + src/data/set.cpp | 8 +++-- src/gui/control/gallery_list.hpp | 1 + src/gui/control/package_list.cpp | 1 + src/gui/new_window.cpp | 53 +++++++++++++------------------- src/gui/new_window.hpp | 11 ++----- src/main.cpp | 8 ++--- 8 files changed, 39 insertions(+), 48 deletions(-) diff --git a/src/data/format/mse1.cpp b/src/data/format/mse1.cpp index 39153706..5fb4b3e2 100644 --- a/src/data/format/mse1.cpp +++ b/src/data/format/mse1.cpp @@ -45,9 +45,7 @@ SetP MSE1FileFormat::importSet(const String& filename) { wxTextInputStream file(f); #endif // create set - SetP set(new Set); - set->game = Game::byName(_("magic")); - set->data.init(set->game->set_fields); + SetP set(new Set(Game::byName(_("magic")))); // file version check String format = file.ReadLine(); diff --git a/src/data/format/mse2.cpp b/src/data/format/mse2.cpp index 35b9f51a..49b52265 100644 --- a/src/data/format/mse2.cpp +++ b/src/data/format/mse2.cpp @@ -26,6 +26,7 @@ class MSE2FileFormat : public FileFormat { return set; } virtual void exportSet(Set& set, const String& filename) { + settings.addRecentFile(filename); set.saveAs(filename); set.actions.setSavePoint();; } diff --git a/src/data/set.cpp b/src/data/set.cpp index ae641062..3711bee5 100644 --- a/src/data/set.cpp +++ b/src/data/set.cpp @@ -31,13 +31,17 @@ Set::Set() Set::Set(const GameP& game) : game(game) , script_manager(new ScriptManager(*this)) -{} +{ + data.init(game->set_fields); +} Set::Set(const StyleSheetP& stylesheet) : stylesheet(stylesheet) , game(stylesheet->game) , script_manager(new ScriptManager(*this)) -{} +{ + data.init(game->set_fields); +} Set::~Set() {} diff --git a/src/gui/control/gallery_list.hpp b/src/gui/control/gallery_list.hpp index 63aa0733..40a31434 100644 --- a/src/gui/control/gallery_list.hpp +++ b/src/gui/control/gallery_list.hpp @@ -64,6 +64,7 @@ class GalleryList : public wxScrolledWindow { size_t findItem(const wxMouseEvent&) const; /// Find the coordinates of an item RealPoint itemPos(size_t item) const; + protected: /// Send an event void sendEvent(WXTYPE type); }; diff --git a/src/gui/control/package_list.cpp b/src/gui/control/package_list.cpp index b3b1a765..25525d56 100644 --- a/src/gui/control/package_list.cpp +++ b/src/gui/control/package_list.cpp @@ -87,6 +87,7 @@ void PackageList::select(const String& name) { if (it->package->name() == name) { selection = it - packages.begin(); update(); + sendEvent(EVENT_GALLERY_SELECT); return; } } diff --git a/src/gui/new_window.cpp b/src/gui/new_window.cpp index 50a110a5..d072e3a4 100644 --- a/src/gui/new_window.cpp +++ b/src/gui/new_window.cpp @@ -30,8 +30,8 @@ NewSetWindow::NewSetWindow(Window* parent) // init controls game_list = new PackageList (this, ID_GAME_LIST); stylesheet_list = new PackageList (this, ID_STYLESHEET_LIST); - game_text = new wxStaticText(this, wxID_ANY, _("&Game type:")); - stylesheet_text = new wxStaticText(this, wxID_ANY, _("&Card style:")); + game_text = new wxStaticText(this, ID_GAME_LIST, _("&Game type:")); + stylesheet_text = new wxStaticText(this, ID_STYLESHEET_LIST, _("&Card style:")); // init sizer wxSizer* s = new wxBoxSizer(wxVERTICAL); s->Add(game_text, 0, wxALL, 4); @@ -41,24 +41,12 @@ NewSetWindow::NewSetWindow(Window* parent) s->Add(CreateButtonSizer(wxOK | wxCANCEL) , 0, wxEXPAND | wxALL, 8); s->SetSizeHints(this); SetSizer(s); - // disable stuff - ok_button = FindWindow(wxID_OK); - assert(ok_button); - enableStyle(false); // force refresh of gameList, otherwise a grey background shows (win XP) SetSize(wxSize(530,320)); // init lists game_list->showData(); game_list->select(settings.default_game); -} - -void NewSetWindow::enableStyle(bool e) { - stylesheet_list->Enable(e); - stylesheet_text->Enable(e); - if (!e) enableOk(e); -} -void NewSetWindow::enableOk(bool e) { - ok_button->Enable(e); + UpdateWindowUI(wxUPDATE_UI_RECURSE); } void NewSetWindow::onGameSelect(wxCommandEvent&) { @@ -67,25 +55,17 @@ void NewSetWindow::onGameSelect(wxCommandEvent&) { GameSettings& gs = settings.gameSettingsFor(*game); stylesheet_list->showData(game->name() + _("-*")); stylesheet_list->select(gs.default_stylesheet); - enableStyle(true); + UpdateWindowUI(wxUPDATE_UI_RECURSE); } -/*void NewSetWindow::onGameDeselect(wxCommandEvent&) { - stylesheet_list->clear(); - enableStyle(false); -} -*/ + void NewSetWindow::onStyleSheetSelect(wxCommandEvent&) { - enableOk(true); // store this as default selection GameP game = game_list ->getSelection(); StyleSheetP stylesheet = stylesheet_list->getSelection(); GameSettings& gs = settings.gameSettingsFor(*game); gs.default_stylesheet = stylesheet->name(); + UpdateWindowUI(wxUPDATE_UI_RECURSE); } -/*void NewSetWindow::onStyleSheetDeselect(wxCommandEvent&) { - enableOk(false); -} -*/ void NewSetWindow::onStyleSheetActivate(wxCommandEvent&) { done(); } @@ -101,10 +81,21 @@ void NewSetWindow::done() { EndModal(wxID_OK); } +void NewSetWindow::onUpdateUI(wxUpdateUIEvent& ev) { + switch (ev.GetId()) { + case ID_STYLESHEET_LIST: + ev.Enable(game_list->hasSelection()); + break; + case wxID_OK: + ev.Enable(stylesheet_list->hasSelection()); + break; + } +} + BEGIN_EVENT_TABLE(NewSetWindow, wxDialog) - EVT_GALLERY_SELECT (ID_GAME_LIST, NewSetWindow::onGameSelect) -// EVT_LIST_ITEM_DESELECTED (ID_GAME_LIST, NewSetWindow::onGameDeselect) - EVT_GALLERY_SELECT (ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetSelect) -// EVT_LIST_ITEM_DESELECTED (ID_STYLESHEET_LIST, NewSetWindow::onStyleDeselect) - EVT_GALLERY_ACTIVATE (ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetActivate) + EVT_GALLERY_SELECT (ID_GAME_LIST, NewSetWindow::onGameSelect) + EVT_GALLERY_SELECT (ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetSelect) + EVT_GALLERY_ACTIVATE(ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetActivate) + EVT_BUTTON (wxID_OK, NewSetWindow::OnOK) + EVT_UPDATE_UI (wxID_ANY, NewSetWindow::onUpdateUI) END_EVENT_TABLE () diff --git a/src/gui/new_window.hpp b/src/gui/new_window.hpp index a458af62..9deeea53 100644 --- a/src/gui/new_window.hpp +++ b/src/gui/new_window.hpp @@ -35,23 +35,18 @@ class NewSetWindow : public wxDialog { PackageList* game_list, *stylesheet_list; wxStaticText* game_text, *stylesheet_text; Window* ok_button; - - // --------------------------------------------------- : enabling stuff - - void enableStyle(bool e); - void enableOk (bool e); - + // --------------------------------------------------- : events void onGameSelect (wxCommandEvent&); -// void onGameDeselect(wxCommandEvent&); void onStyleSheetSelect (wxCommandEvent&); -// void onStyleSheetDeselect(wxCommandEvent&); void onStyleSheetActivate(wxCommandEvent&); virtual void OnOK(wxCommandEvent&); + void onUpdateUI(wxUpdateUIEvent&); + // we are done, close the window void done(); }; diff --git a/src/main.cpp b/src/main.cpp index 995bc2bb..3d208ae8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,10 +49,10 @@ bool MSE::OnInit() { check_updates(); //Window* wnd = new SymbolWindow(nullptr); //GameP g = Game::byName(_("magic")) - SetP s = new_shared(); - s->open(_("test.mse-set")); - Window* wnd = new SetWindow(nullptr, s); - //Window* wnd = new WelcomeWindow(); + //SetP s = new_shared(); + //s->open(_("test.mse-set")); + //Window* wnd = new SetWindow(nullptr, s); + Window* wnd = new WelcomeWindow(); wnd->Show(); return true;