Commit a7306af2 authored by twanvl's avatar twanvl

support for saving sets

parent 12a41e90
...@@ -60,7 +60,7 @@ SetP MSE1FileFormat::importSet(const String& filename) { ...@@ -60,7 +60,7 @@ SetP MSE1FileFormat::importSet(const String& filename) {
set->value<TextValue>(_("copyright")).value = file.ReadLine(); set->value<TextValue>(_("copyright")).value = file.ReadLine();
file.ReadLine(); // border color, ignored file.ReadLine(); // border color, ignored
String stylesheet = file.ReadLine(); 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(); // 'formatN'?, not even used by MSE1 :S, ignored
file.ReadLine(); // 'formatS'?, same, ignored file.ReadLine(); // 'formatS'?, same, ignored
file.ReadLine(); // symbol filename, ignored file.ReadLine(); // symbol filename, ignored
......
...@@ -145,7 +145,6 @@ String Settings::settingsFile() { ...@@ -145,7 +145,6 @@ String Settings::settingsFile() {
} }
IMPLEMENT_REFLECTION(Settings) { IMPLEMENT_REFLECTION(Settings) {
tag.handleAppVersion();
tag.addAlias(300, _("style settings"), _("stylesheet settings")); tag.addAlias(300, _("style settings"), _("stylesheet settings"));
tag.addAlias(300, _("default style settings"), _("default stylesheet settings")); tag.addAlias(300, _("default style settings"), _("default stylesheet settings"));
REFLECT(recent_sets); REFLECT(recent_sets);
......
...@@ -105,5 +105,5 @@ void Reader::handle(StyleSheetP& stylesheet) { ...@@ -105,5 +105,5 @@ void Reader::handle(StyleSheetP& stylesheet) {
stylesheet = StyleSheet::byGameAndName(*game_for_reading(), value); stylesheet = StyleSheet::byGameAndName(*game_for_reading(), value);
} }
void Writer::handle(const StyleSheetP& stylesheet) { void Writer::handle(const StyleSheetP& stylesheet) {
if (stylesheet) handle(stylesheet->name()); if (stylesheet) handle(stylesheet->stylesheetName());
} }
...@@ -159,7 +159,6 @@ void SymbolPart::calculateBounds() { ...@@ -159,7 +159,6 @@ void SymbolPart::calculateBounds() {
// ----------------------------------------------------------------------------- : Symbol // ----------------------------------------------------------------------------- : Symbol
IMPLEMENT_REFLECTION(Symbol) { IMPLEMENT_REFLECTION(Symbol) {
tag.handleAppVersion();
REFLECT(parts); REFLECT(parts);
} }
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include <data/format/formats.hpp> #include <data/format/formats.hpp>
DECLARE_TYPEOF_COLLECTION(SetWindowPanel*); DECLARE_TYPEOF_COLLECTION(SetWindowPanel*);
DECLARE_TYPEOF_COLLECTION(SetWindow*);
DECLARE_TYPEOF_COLLECTION(String);
// ----------------------------------------------------------------------------- : Constructor // ----------------------------------------------------------------------------- : Constructor
...@@ -35,6 +37,7 @@ SetWindow::SetWindow(Window* parent, const SetP& set) ...@@ -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) : wxFrame(parent, wxID_ANY, _("Magic Set Editor"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
, current_panel(nullptr) , current_panel(nullptr)
, find_dialog(nullptr) , find_dialog(nullptr)
, number_of_recent_sets(0)
{ {
SetIcon(wxIcon(_("ICON_APP"))); SetIcon(wxIcon(_("ICON_APP")));
...@@ -135,9 +138,7 @@ SetWindow::SetWindow(Window* parent, const SetP& set) ...@@ -135,9 +138,7 @@ SetWindow::SetWindow(Window* parent, const SetP& set)
if (settings.set_window_maximized) { if (settings.set_window_maximized) {
Maximize(); Maximize();
} }
// SetWindows.push_back(&this); // register this window set_windows.push_back(this); // register this window
// timer.owner = &this;
// timer.start(10);
// don't send update ui events to children // don't send update ui events to children
// note: this still sends events for menu and toolbar items! // note: this still sends events for menu and toolbar items!
wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED); wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED);
...@@ -159,13 +160,12 @@ SetWindow::~SetWindow() { ...@@ -159,13 +160,12 @@ SetWindow::~SetWindow() {
current_panel->destroyUI(GetToolBar(), GetMenuBar()); current_panel->destroyUI(GetToolBar(), GetMenuBar());
// cleanup (see find stuff) // cleanup (see find stuff)
delete find_dialog; delete find_dialog;
// remove from list of main windows // remove from list of set windows
// SetWindows.erase(remove(SetWindows.begin(), SetWindows.end(), &this)); set_windows.erase(remove(set_windows.begin(), set_windows.end(), this));
// stop updating // stop updating
onBeforeChangeSet(); onBeforeChangeSet();
} }
// ----------------------------------------------------------------------------- : Panel managment // ----------------------------------------------------------------------------- : Panel managment
void SetWindow::addPanel(wxMenu* windowMenu, wxToolBar* tabBar, SetWindowPanel* panel, UInt pos, void SetWindow::addPanel(wxMenu* windowMenu, wxToolBar* tabBar, SetWindowPanel* panel, UInt pos,
...@@ -205,6 +205,17 @@ void SetWindow::selectPanel(int id) { ...@@ -205,6 +205,17 @@ void SetWindow::selectPanel(int id) {
fixMinWindowSize(); fixMinWindowSize();
} }
// ----------------------------------------------------------------------------- : Window managment
vector<SetWindow*> SetWindow::set_windows;
bool SetWindow::isOnlyWithSet() {
FOR_EACH(w, set_windows) {
if (w != this && w->set == set) return false;
}
return true;
}
// ----------------------------------------------------------------------------- : Set actions // ----------------------------------------------------------------------------- : Set actions
void SetWindow::onChangeSet() { void SetWindow::onChangeSet() {
...@@ -255,17 +266,15 @@ void SetWindow::fixMinWindowSize() { ...@@ -255,17 +266,15 @@ void SetWindow::fixMinWindowSize() {
} }
// ----------------------------------------------------------------------------- : Window events - close // ----------------------------------------------------------------------------- : Window events - close
void SetWindow::onClose(wxCloseEvent& ev) { void SetWindow::onClose(wxCloseEvent& ev) {
// only ask if we want to save is this is the only window that has the current set opened // only ask if we want to save is this is the only window that has the current set opened
// if (!isOnlyWithSet() || askSaveAndContinue()) { if (!isOnlyWithSet() || askSaveAndContinue()) {
// timer.stop();
Destroy(); Destroy();
// } else { } else {
// ev.Veto(); ev.Veto();
// } }
} }
bool SetWindow::askSaveAndContinue() { bool SetWindow::askSaveAndContinue() {
...@@ -274,27 +283,26 @@ 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); 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) { if (save == wxYES) {
// save the set // save the set
/* try { try {
if (set->needSaveAs()) { if (set->needSaveAs()) {
// need save as // need save as
FileDialog dlg(&this, _("Save a set"), _(""), _(""), export_formats(set->game), wxSAVE | wxOVERWRITE_PROMPT); wxFileDialog dlg(this, _("Save a set"), _(""), _(""), export_formats(*set->game), wxSAVE | wxOVERWRITE_PROMPT);
if (dlg.showModal() == wxID_OK) { if (dlg.ShowModal() == wxID_OK) {
exportSet(set, dlg.path, dlg.filterIndex); export_set(*set, dlg.GetPath(), dlg.GetFilterIndex());
return true; return true;
} else { } else {
return false; return false;
} }
} else { } else {
set->save(); set->save();
set->actions.atSavePoint = true; set->actions.setSavePoint();
return true; return true;
} }
} catch (Error e) { } catch (Error e) {
// something went wrong with saving, don't proceed // something went wrong with saving, don't proceed
handleError(e); handle_error(e);
return false; return false;
} }
*/ return false;/////<<<<removeme
} else if (save == wxNO) { } else if (save == wxNO) {
return true; return true;
} else { // wxCANCEL } else { // wxCANCEL
...@@ -307,16 +315,14 @@ bool SetWindow::askSaveAndContinue() { ...@@ -307,16 +315,14 @@ bool SetWindow::askSaveAndContinue() {
void SetWindow::onUpdateUI(wxUpdateUIEvent& ev) { void SetWindow::onUpdateUI(wxUpdateUIEvent& ev) {
switch (ev.GetId()) { switch (ev.GetId()) {
// file menu // file menu
case ID_FILE_SAVE_AS: ev.Enable(!set->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_IMAGE: ev.Enable(!!current_panel->selectedCard()); break;
case ID_FILE_EXPORT_APPR: ev.Enable(set->game->isMagic()); 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_EXPORT_MWS: ev.Enable(set->game->isMagic()); break;
/*case ID_FILE_INSPECT: { case ID_FILE_EXIT:
// the item just before FileRecent, because FileRecent may not be in the menu yet // update for ID_FILE_RECENT done for a different id, because ID_FILE_RECENT may not be in the menu yet
//updateRecentSets(); updateRecentSets();
// TODO
break; break;
}*/
// undo/redo // undo/redo
case ID_EDIT_UNDO: { case ID_EDIT_UNDO: {
ev.Enable(set->actions.canUndo()); ev.Enable(set->actions.canUndo());
...@@ -344,6 +350,27 @@ void SetWindow::onUpdateUI(wxUpdateUIEvent& ev) { ...@@ -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<IconMenu*>(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 // ----------------------------------------------------------------------------- : Window events - menu - file
...@@ -433,7 +460,7 @@ void SetWindow::onFilePrintPreview(wxCommandEvent&) { ...@@ -433,7 +460,7 @@ void SetWindow::onFilePrintPreview(wxCommandEvent&) {
} }
void SetWindow::onFileRecent(wxCommandEvent& ev) { 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&) { void SetWindow::onFileExit(wxCommandEvent&) {
......
...@@ -35,11 +35,7 @@ class SetWindow : public wxFrame, public SetView { ...@@ -35,11 +35,7 @@ class SetWindow : public wxFrame, public SetView {
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
// --------------------------------------------------- : Data // --------------------------------------------------- : Data
// keep scripts up to date
// ScriptUpdater scriptUpdater;
// Timer timer;
// gui items // gui items
vector<SetWindowPanel*> panels; ///< All panels on this window vector<SetWindowPanel*> panels; ///< All panels on this window
SetWindowPanel* current_panel; SetWindowPanel* current_panel;
...@@ -50,7 +46,7 @@ class SetWindow : public wxFrame, public SetView { ...@@ -50,7 +46,7 @@ class SetWindow : public wxFrame, public SetView {
// data for find/replace // data for find/replace
wxDialog* find_dialog; wxDialog* find_dialog;
wxFindReplaceData find_data; wxFindReplaceData find_data;
// --------------------------------------------------- : Panel managment // --------------------------------------------------- : Panel managment
/// Add a panel to the window, as well as to the menu and tab bar /// 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 { ...@@ -64,13 +60,9 @@ class SetWindow : public wxFrame, public SetView {
// --------------------------------------------------- : Managing multiple main windows // --------------------------------------------------- : Managing multiple main windows
/// All opened main windows /// All opened set windows
static vector<SetWindow*> setWindows; static vector<SetWindow*> set_windows;
/// Is this the first window that has this set?
/** The first window is considered the owner in many cases */
bool isFirstWithSet();
/// Is this the only window that has this set? /// Is this the only window that has this set?
bool isOnlyWithSet(); bool isOnlyWithSet();
...@@ -106,6 +98,9 @@ class SetWindow : public wxFrame, public SetView { ...@@ -106,6 +98,9 @@ class SetWindow : public wxFrame, public SetView {
// --------------------------------------------------- : Window events - update UI // --------------------------------------------------- : Window events - update UI
void onUpdateUI(wxUpdateUIEvent&); void onUpdateUI(wxUpdateUIEvent&);
/// The number of 'recent set' menu items shown
UInt number_of_recent_sets;
void updateRecentSets();
// --------------------------------------------------- : Window events - menu - file // --------------------------------------------------- : Window events - menu - file
void onFileNew (wxCommandEvent&); void onFileNew (wxCommandEvent&);
......
...@@ -412,7 +412,6 @@ void Packaged::open(const String& package) { ...@@ -412,7 +412,6 @@ void Packaged::open(const String& package) {
Package::open(package); Package::open(package);
Reader reader(openIn(typeName()), absoluteFilename() + _("/") + typeName()); Reader reader(openIn(typeName()), absoluteFilename() + _("/") + typeName());
try { try {
reader.handleAppVersion();
reader.handle(*this); reader.handle(*this);
validate(reader.file_app_version); validate(reader.file_app_version);
} catch (const ParseError& err) { } catch (const ParseError& err) {
...@@ -420,10 +419,14 @@ void Packaged::open(const String& package) { ...@@ -420,10 +419,14 @@ void Packaged::open(const String& package) {
} }
} }
void Packaged::save() { void Packaged::save() {
// writeFile(thisT().fileName, thisT()); WITH_DYNAMIC_ARG(writing_package, this);
writeFile(typeName(), *this);
referenceFile(typeName());
Package::save(); Package::save();
} }
void Packaged::saveAs(const String& package) { void Packaged::saveAs(const String& package) {
// writeFile(thisT().fileName, thisT()); WITH_DYNAMIC_ARG(writing_package, this);
writeFile(typeName(), *this);
referenceFile(typeName());
Package::saveAs(package); Package::saveAs(package);
} }
...@@ -19,6 +19,7 @@ Reader::Reader(const InputStreamP& input, const String& filename) ...@@ -19,6 +19,7 @@ Reader::Reader(const InputStreamP& input, const String& filename)
, stream(*input) , stream(*input)
{ {
moveNext(); moveNext();
handleAppVersion();
} }
Reader::Reader(const String& filename) Reader::Reader(const String& filename)
...@@ -28,6 +29,7 @@ Reader::Reader(const String& filename) ...@@ -28,6 +29,7 @@ Reader::Reader(const String& filename)
, stream(*input) , stream(*input)
{ {
moveNext(); moveNext();
handleAppVersion();
} }
void Reader::addAlias(Version end_version, const Char* a, const Char* b) { void Reader::addAlias(Version end_version, const Char* a, const Char* b) {
......
...@@ -21,6 +21,7 @@ Writer::Writer(const OutputStreamP& output) ...@@ -21,6 +21,7 @@ Writer::Writer(const OutputStreamP& output)
, just_opened(false) , just_opened(false)
{ {
stream.WriteString(BYTE_ORDER_MARK); stream.WriteString(BYTE_ORDER_MARK);
handleAppVersion();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment