diff --git a/src/data/format/mse1.cpp b/src/data/format/mse1.cpp index ac428295..39153706 100644 --- a/src/data/format/mse1.cpp +++ b/src/data/format/mse1.cpp @@ -60,7 +60,7 @@ SetP MSE1FileFormat::importSet(const String& filename) { set->value(_("copyright")).value = file.ReadLine(); file.ReadLine(); // border color, ignored String stylesheet = file.ReadLine(); - file.ReadLine(); // apprentice prefix ('MY'), ignored + set->apprentice_code = file.ReadLine(); // apprentice prefix file.ReadLine(); // 'formatN'?, not even used by MSE1 :S, ignored file.ReadLine(); // 'formatS'?, same, ignored file.ReadLine(); // symbol filename, ignored diff --git a/src/data/settings.cpp b/src/data/settings.cpp index 4705a0de..2f18e899 100644 --- a/src/data/settings.cpp +++ b/src/data/settings.cpp @@ -145,7 +145,6 @@ String Settings::settingsFile() { } IMPLEMENT_REFLECTION(Settings) { - tag.handleAppVersion(); tag.addAlias(300, _("style settings"), _("stylesheet settings")); tag.addAlias(300, _("default style settings"), _("default stylesheet settings")); REFLECT(recent_sets); diff --git a/src/data/stylesheet.cpp b/src/data/stylesheet.cpp index 9151c1ca..e652eef9 100644 --- a/src/data/stylesheet.cpp +++ b/src/data/stylesheet.cpp @@ -105,5 +105,5 @@ void Reader::handle(StyleSheetP& stylesheet) { stylesheet = StyleSheet::byGameAndName(*game_for_reading(), value); } void Writer::handle(const StyleSheetP& stylesheet) { - if (stylesheet) handle(stylesheet->name()); + if (stylesheet) handle(stylesheet->stylesheetName()); } diff --git a/src/data/symbol.cpp b/src/data/symbol.cpp index 8cb24a53..5b57bc47 100644 --- a/src/data/symbol.cpp +++ b/src/data/symbol.cpp @@ -159,7 +159,6 @@ void SymbolPart::calculateBounds() { // ----------------------------------------------------------------------------- : Symbol IMPLEMENT_REFLECTION(Symbol) { - tag.handleAppVersion(); REFLECT(parts); } diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index a6dd97cf..99467257 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -28,6 +28,8 @@ #include DECLARE_TYPEOF_COLLECTION(SetWindowPanel*); +DECLARE_TYPEOF_COLLECTION(SetWindow*); +DECLARE_TYPEOF_COLLECTION(String); // ----------------------------------------------------------------------------- : Constructor @@ -35,6 +37,7 @@ SetWindow::SetWindow(Window* parent, const SetP& set) : wxFrame(parent, wxID_ANY, _("Magic Set Editor"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) , current_panel(nullptr) , find_dialog(nullptr) + , number_of_recent_sets(0) { SetIcon(wxIcon(_("ICON_APP"))); @@ -135,9 +138,7 @@ SetWindow::SetWindow(Window* parent, const SetP& set) if (settings.set_window_maximized) { Maximize(); } -// SetWindows.push_back(&this); // register this window -// timer.owner = &this; -// timer.start(10); + set_windows.push_back(this); // register this window // don't send update ui events to children // note: this still sends events for menu and toolbar items! wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED); @@ -159,13 +160,12 @@ SetWindow::~SetWindow() { current_panel->destroyUI(GetToolBar(), GetMenuBar()); // cleanup (see find stuff) delete find_dialog; - // remove from list of main windows -// SetWindows.erase(remove(SetWindows.begin(), SetWindows.end(), &this)); + // remove from list of set windows + set_windows.erase(remove(set_windows.begin(), set_windows.end(), this)); // stop updating onBeforeChangeSet(); } - // ----------------------------------------------------------------------------- : Panel managment void SetWindow::addPanel(wxMenu* windowMenu, wxToolBar* tabBar, SetWindowPanel* panel, UInt pos, @@ -205,6 +205,17 @@ void SetWindow::selectPanel(int id) { fixMinWindowSize(); } +// ----------------------------------------------------------------------------- : Window managment + +vector SetWindow::set_windows; + +bool SetWindow::isOnlyWithSet() { + FOR_EACH(w, set_windows) { + if (w != this && w->set == set) return false; + } + return true; +} + // ----------------------------------------------------------------------------- : Set actions void SetWindow::onChangeSet() { @@ -255,17 +266,15 @@ void SetWindow::fixMinWindowSize() { } - // ----------------------------------------------------------------------------- : Window events - close void SetWindow::onClose(wxCloseEvent& ev) { // only ask if we want to save is this is the only window that has the current set opened -// if (!isOnlyWithSet() || askSaveAndContinue()) { -// timer.stop(); + if (!isOnlyWithSet() || askSaveAndContinue()) { Destroy(); -// } else { -// ev.Veto(); -// } + } else { + ev.Veto(); + } } bool SetWindow::askSaveAndContinue() { @@ -274,27 +283,26 @@ bool SetWindow::askSaveAndContinue() { int save = wxMessageBox(_("The set has changed\n\nDo you want to save the changes?"), _("Save changes"), wxYES_NO | wxCANCEL | wxICON_EXCLAMATION); if (save == wxYES) { // save the set -/* try { + try { if (set->needSaveAs()) { // need save as - FileDialog dlg(&this, _("Save a set"), _(""), _(""), export_formats(set->game), wxSAVE | wxOVERWRITE_PROMPT); - if (dlg.showModal() == wxID_OK) { - exportSet(set, dlg.path, dlg.filterIndex); + wxFileDialog dlg(this, _("Save a set"), _(""), _(""), export_formats(*set->game), wxSAVE | wxOVERWRITE_PROMPT); + if (dlg.ShowModal() == wxID_OK) { + export_set(*set, dlg.GetPath(), dlg.GetFilterIndex()); return true; } else { return false; } } else { set->save(); - set->actions.atSavePoint = true; + set->actions.setSavePoint(); return true; } } catch (Error e) { // something went wrong with saving, don't proceed - handleError(e); + handle_error(e); return false; } -*/ return false;/////<<<actions.atSavePoint() || set->needSaveAs()); break; + case ID_FILE_SAVE: ev.Enable(!set->actions.atSavePoint() || set->needSaveAs()); break; case ID_FILE_EXPORT_IMAGE: ev.Enable(!!current_panel->selectedCard()); break; case ID_FILE_EXPORT_APPR: ev.Enable(set->game->isMagic()); break; case ID_FILE_EXPORT_MWS: ev.Enable(set->game->isMagic()); break; - /*case ID_FILE_INSPECT: { - // the item just before FileRecent, because FileRecent may not be in the menu yet - //updateRecentSets(); - // TODO + case ID_FILE_EXIT: + // update for ID_FILE_RECENT done for a different id, because ID_FILE_RECENT may not be in the menu yet + updateRecentSets(); break; - }*/ // undo/redo case ID_EDIT_UNDO: { ev.Enable(set->actions.canUndo()); @@ -344,6 +350,27 @@ void SetWindow::onUpdateUI(wxUpdateUIEvent& ev) { } } +static const int FILE_MENU_SIZE_BEFORE_RECENT_SETS = 11; // HACK; we should calculate the position to insert! +void SetWindow::updateRecentSets() { + wxMenuBar* mb = GetMenuBar(); + assert(number_of_recent_sets <= (UInt)settings.recent_sets.size()); // the number of recent sets should only increase + UInt i = 0; + FOR_EACH(file, settings.recent_sets) { + if (i >= settings.max_recent_sets) break; + if (i < number_of_recent_sets) { + // menu item already exists, update it + mb->SetLabel(ID_FILE_RECENT + i, String(_("&")) << (i+1) << _(" ") << file); + } else { + // add new item + int pos = i + FILE_MENU_SIZE_BEFORE_RECENT_SETS; // HUGE HACK, we should calculate the position to insert! + IconMenu* file_menu = static_cast(mb->GetMenu(0)); + file_menu->Insert(pos, ID_FILE_RECENT + i, String(_("&")) << (i+1) << _(" ") << file, wxEmptyString); + } + i++; + } + number_of_recent_sets = (UInt)settings.recent_sets.size(); +} + // ----------------------------------------------------------------------------- : Window events - menu - file @@ -433,7 +460,7 @@ void SetWindow::onFilePrintPreview(wxCommandEvent&) { } void SetWindow::onFileRecent(wxCommandEvent& ev) { -// setSet(import_set(settings.recentSets.at(ev.GetId() - ID_FILE_RECENT))); + setSet(import_set(settings.recent_sets.at(ev.GetId() - ID_FILE_RECENT))); } void SetWindow::onFileExit(wxCommandEvent&) { diff --git a/src/gui/set/window.hpp b/src/gui/set/window.hpp index a70ecf47..05dc35e6 100644 --- a/src/gui/set/window.hpp +++ b/src/gui/set/window.hpp @@ -35,11 +35,7 @@ class SetWindow : public wxFrame, public SetView { DECLARE_EVENT_TABLE(); // --------------------------------------------------- : Data - - // keep scripts up to date -// ScriptUpdater scriptUpdater; -// Timer timer; - + // gui items vector panels; ///< All panels on this window SetWindowPanel* current_panel; @@ -50,7 +46,7 @@ class SetWindow : public wxFrame, public SetView { // data for find/replace wxDialog* find_dialog; wxFindReplaceData find_data; - + // --------------------------------------------------- : Panel managment /// Add a panel to the window, as well as to the menu and tab bar @@ -64,13 +60,9 @@ class SetWindow : public wxFrame, public SetView { // --------------------------------------------------- : Managing multiple main windows - /// All opened main windows - static vector setWindows; - - /// Is this the first window that has this set? - /** The first window is considered the owner in many cases */ - bool isFirstWithSet(); - + /// All opened set windows + static vector set_windows; + /// Is this the only window that has this set? bool isOnlyWithSet(); @@ -106,6 +98,9 @@ class SetWindow : public wxFrame, public SetView { // --------------------------------------------------- : Window events - update UI void onUpdateUI(wxUpdateUIEvent&); + /// The number of 'recent set' menu items shown + UInt number_of_recent_sets; + void updateRecentSets(); // --------------------------------------------------- : Window events - menu - file void onFileNew (wxCommandEvent&); diff --git a/src/util/io/package.cpp b/src/util/io/package.cpp index 5fe7c5e7..2eb1438b 100644 --- a/src/util/io/package.cpp +++ b/src/util/io/package.cpp @@ -412,7 +412,6 @@ void Packaged::open(const String& package) { Package::open(package); Reader reader(openIn(typeName()), absoluteFilename() + _("/") + typeName()); try { - reader.handleAppVersion(); reader.handle(*this); validate(reader.file_app_version); } catch (const ParseError& err) { @@ -420,10 +419,14 @@ void Packaged::open(const String& package) { } } void Packaged::save() { -// writeFile(thisT().fileName, thisT()); + WITH_DYNAMIC_ARG(writing_package, this); + writeFile(typeName(), *this); + referenceFile(typeName()); Package::save(); } void Packaged::saveAs(const String& package) { -// writeFile(thisT().fileName, thisT()); + WITH_DYNAMIC_ARG(writing_package, this); + writeFile(typeName(), *this); + referenceFile(typeName()); Package::saveAs(package); } diff --git a/src/util/io/reader.cpp b/src/util/io/reader.cpp index e2f1e57d..11a0e590 100644 --- a/src/util/io/reader.cpp +++ b/src/util/io/reader.cpp @@ -19,6 +19,7 @@ Reader::Reader(const InputStreamP& input, const String& filename) , stream(*input) { moveNext(); + handleAppVersion(); } Reader::Reader(const String& filename) @@ -28,6 +29,7 @@ Reader::Reader(const String& filename) , stream(*input) { moveNext(); + handleAppVersion(); } void Reader::addAlias(Version end_version, const Char* a, const Char* b) { diff --git a/src/util/io/writer.cpp b/src/util/io/writer.cpp index 8e3933b4..fa56186e 100644 --- a/src/util/io/writer.cpp +++ b/src/util/io/writer.cpp @@ -21,6 +21,7 @@ Writer::Writer(const OutputStreamP& output) , just_opened(false) { stream.WriteString(BYTE_ORDER_MARK); + handleAppVersion(); }