Debug and improve preferences editor

This commit is contained in:
Loic Guegan 2022-02-23 19:41:50 +01:00
parent a3c24f27f0
commit 5a43d62920
8 changed files with 182 additions and 10 deletions

View file

@ -2,7 +2,6 @@
#include "ChessArbiter.hpp"
#include "pgnp.hpp"
#include "preferences/preferences.hpp"
#include <wx/preferences.h>
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) {