aboutsummaryrefslogtreecommitdiff
path: root/src/MainWindow.cpp
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-02-23 19:41:50 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-02-23 19:41:50 +0100
commit5a43d62920f82bac38490ac92dd9a49edd1d44de (patch)
tree291fa23e50c16d2d4a6f5e04a4944eebb233388c /src/MainWindow.cpp
parenta3c24f27f081e49b9a814aba61d298f1d0a5d0fa (diff)
Debug and improve preferences editor
Diffstat (limited to 'src/MainWindow.cpp')
-rw-r--r--src/MainWindow.cpp28
1 files changed, 20 insertions, 8 deletions
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 <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) {