From 5a43d62920f82bac38490ac92dd9a49edd1d44de Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Wed, 23 Feb 2022 19:41:50 +0100 Subject: Debug and improve preferences editor --- src/MainWindow.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/MainWindow.cpp') diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a1afc7b..83fd964 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -2,7 +2,6 @@ #include "ChessArbiter.hpp" #include "pgnp.hpp" #include "preferences/preferences.hpp" -#include wxDEFINE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent); @@ -10,7 +9,8 @@ wxDEFINE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent); MainWindow::MainWindow() : wxFrame(NULL, wxID_ANY, "OChess: The Open Chess software", - wxDefaultPosition, wxSize(1500, 1000)) { + wxDefaultPosition, wxSize(1500, 1000)), + prefsEditor(NULL) { CreateStatusBar(); SetStatusText("OChess"); @@ -46,6 +46,7 @@ MainWindow::MainWindow() Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGED, &MainWindow::OnPageChange, this, wxID_ANY); Bind(REFRESH_TAB_TITLE, &MainWindow::OnRefreshTabTitle, this, wxID_ANY); + Bind(wxEVT_CLOSE_WINDOW, &MainWindow::OnClose, this); } class AdvancePage : public wxPreferencesPage { @@ -65,9 +66,13 @@ public: }; void MainWindow::OnSettings(wxCommandEvent &event) { - wxPreferencesEditor *edt = new wxPreferencesEditor("Preferences"); - edt->AddPage(new BoardPrefs()); - edt->Show(this); + if (prefsEditor != NULL) { + delete prefsEditor; + } + prefsEditor = new wxPreferencesEditor("Preferences"); + prefsEditor->AddPage(new BoardPrefs()); + prefsEditor->AddPage(new EditorPrefs()); + prefsEditor->Show(this); } void MainWindow::ApplyPreferences() { @@ -79,6 +84,13 @@ void MainWindow::ApplyPreferences() { void MainWindow::OnExit(wxCommandEvent &event) { Close(true); } +void MainWindow::OnClose(wxCloseEvent &e) { + if (prefsEditor != NULL) { + prefsEditor->Dismiss(); + } + e.Skip(); +} + void MainWindow::OnOpen(wxCommandEvent &event) { wxFileDialog openFileDialog(this, _("Open file"), "", "", "PGN files (*.pgn)|*.pgn", @@ -97,9 +109,9 @@ void MainWindow::OnOpen(wxCommandEvent &event) { fen = pgn.GetTagValue("FEN"); } HalfMove *m = new HalfMove(pgnp_moves, fen); - Game *g=new Game(m,fen); - for(std::string &s:pgn.GetTagList()){ - g->SetTag(s,pgn.GetTagValue(s)); + Game *g = new Game(m, fen); + for (std::string &s : pgn.GetTagList()) { + g->SetTag(s, pgn.GetTagValue(s)); } NewGame(g); } catch (std::exception &e) { -- cgit v1.2.3