diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index f9d5905..bc417b6 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -56,6 +56,10 @@ MainWindow::MainWindow() Bind(REFRESH_TAB_TITLE, &MainWindow::OnRefreshTabTitle, this, wxID_ANY); Bind(NEW_GAME_EVENT, &MainWindow::OnNewGame, this, wxID_ANY); Bind(wxEVT_CLOSE_WINDOW, &MainWindow::OnClose, this); + + /*BaseTab *bt = new BaseTab((wxFrame *)notebook, "/home/loic/hartwig.pgn"); + notebook->AddPage(bt, bt->GetLabel()); + notebook->SetSelection(notebook->GetPageIndex(bt));*/ } void MainWindow::OnSettings(wxCommandEvent &event) { @@ -77,6 +81,14 @@ void MainWindow::ApplyPreferences() { void MainWindow::OnExit(wxCommandEvent &event) { Close(true); } +std::vector MainWindow::ListTabInfos() { + std::vector tinfos; + for (int i = 0; i < notebook->GetPageCount(); i++) { + tinfos.push_back(dynamic_cast(notebook->GetPage(i))); + } + return (tinfos); +} + void MainWindow::OnClose(wxCloseEvent &e) { if (prefsEditor != NULL) { prefsEditor->Dismiss(); diff --git a/src/MainWindow.hpp b/src/MainWindow.hpp index 0faa556..9a9fc41 100644 --- a/src/MainWindow.hpp +++ b/src/MainWindow.hpp @@ -1,3 +1,5 @@ +#pragma once + #include "base_tab/BaseTab.hpp" #include "game_tab/GameTab.hpp" #include "ochess.hpp" @@ -28,4 +30,5 @@ class MainWindow : public wxFrame { public: MainWindow(); void ApplyPreferences(); + std::vector ListTabInfos(); }; \ No newline at end of file diff --git a/src/base_tab/AppendGameDialog.cpp b/src/base_tab/AppendGameDialog.cpp new file mode 100644 index 0000000..8a76028 --- /dev/null +++ b/src/base_tab/AppendGameDialog.cpp @@ -0,0 +1,28 @@ +#include "AppendGameDialog.hpp" +#include "MainWindow.hpp" +#include "ochess.hpp" + +AppendGameDialog::AppendGameDialog(wxWindow *parent, GameBase *base) + : AppendGameDialogBF(parent), base(base) { + + tinfos = MAINWIN->ListTabInfos(); + for (TabInfos *i : tinfos) { + wxWindow *win = dynamic_cast(i); + game_list->Append(win->GetLabel()); + } + + Bind(wxEVT_BUTTON, &AppendGameDialog::OnCancel, this, + ID_DIALOG_CANCEL_BUTTON); + Bind(wxEVT_BUTTON, &AppendGameDialog::OnImport, this, + ID_DIALOG_IMPORT_BUTTON); +} + +void AppendGameDialog::OnCancel(wxCommandEvent &event) { this->Close(); } + +void AppendGameDialog::OnImport(wxCommandEvent &event) { + std::vector to_ignore; + std::vector new_games_bases; + std::vector new_games; + + this->Close(); +} \ No newline at end of file diff --git a/src/base_tab/AppendGameDialog.hpp b/src/base_tab/AppendGameDialog.hpp new file mode 100644 index 0000000..551676e --- /dev/null +++ b/src/base_tab/AppendGameDialog.hpp @@ -0,0 +1,12 @@ +#include "AppendGameDialogBF.h" +#include "gamebase/GameBase.hpp" + +class AppendGameDialog : public AppendGameDialogBF { + GameBase *base; + std::vector tinfos; + +public: + AppendGameDialog(wxWindow *parent, GameBase *base); + void OnCancel(wxCommandEvent &event); + void OnImport(wxCommandEvent &event); +}; \ No newline at end of file diff --git a/src/base_tab/AppendGameDialogBF.cpp b/src/base_tab/AppendGameDialogBF.cpp new file mode 100644 index 0000000..3f777ef --- /dev/null +++ b/src/base_tab/AppendGameDialogBF.cpp @@ -0,0 +1,50 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 3.10.1-40-g8042f487) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "AppendGameDialogBF.h" + +/////////////////////////////////////////////////////////////////////////// + +AppendGameDialogBF::AppendGameDialogBF( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* main_sizer; + main_sizer = new wxBoxSizer( wxVERTICAL ); + + main_label = new wxStaticText( this, wxID_ANY, wxT("Please select games to import:"), wxDefaultPosition, wxDefaultSize, 0 ); + main_label->Wrap( -1 ); + main_sizer->Add( main_label, 0, wxALL|wxEXPAND, 5 ); + + game_list = new wxListBox( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_MULTIPLE ); + main_sizer->Add( game_list, 1, wxALL|wxEXPAND, 5 ); + + wxBoxSizer* bSizer5; + bSizer5 = new wxBoxSizer( wxHORIZONTAL ); + + + bSizer5->Add( 0, 0, 1, wxEXPAND, 5 ); + + cancel_button = new wxButton( this, ID_DIALOG_CANCEL_BUTTON, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer5->Add( cancel_button, 0, wxALL, 5 ); + + import_button = new wxButton( this, ID_DIALOG_IMPORT_BUTTON, wxT("Import"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer5->Add( import_button, 0, wxALL, 5 ); + + + main_sizer->Add( bSizer5, 0, wxEXPAND, 5 ); + + + this->SetSizer( main_sizer ); + this->Layout(); + + this->Centre( wxBOTH ); +} + +AppendGameDialogBF::~AppendGameDialogBF() +{ +} diff --git a/src/base_tab/AppendGameDialogBF.h b/src/base_tab/AppendGameDialogBF.h new file mode 100644 index 0000000..a2c1871 --- /dev/null +++ b/src/base_tab/AppendGameDialogBF.h @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 3.10.1-40-g8042f487) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + +#define ID_DIALOG_CANCEL_BUTTON 1000 +#define ID_DIALOG_IMPORT_BUTTON 1001 + +/////////////////////////////////////////////////////////////////////////////// +/// Class AppendGameDialogBF +/////////////////////////////////////////////////////////////////////////////// +class AppendGameDialogBF : public wxDialog +{ + private: + + protected: + wxStaticText* main_label; + wxListBox* game_list; + wxButton* cancel_button; + wxButton* import_button; + + public: + + AppendGameDialogBF( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 388,263 ), long style = wxDEFAULT_DIALOG_STYLE ); + + ~AppendGameDialogBF(); + +}; + diff --git a/src/base_tab/BasePanelBF.cpp b/src/base_tab/BasePanelBF.cpp index 96ced01..8af03b6 100644 --- a/src/base_tab/BasePanelBF.cpp +++ b/src/base_tab/BasePanelBF.cpp @@ -36,21 +36,12 @@ BasePanelBF::BasePanelBF( wxWindow* parent, wxWindowID id, const wxPoint& pos, c wxBoxSizer* bottom_sizer; bottom_sizer = new wxBoxSizer( wxHORIZONTAL ); - append_choice_label = new wxStaticText( this, wxID_ANY, wxT("Import games from:"), wxDefaultPosition, wxDefaultSize, 0 ); - append_choice_label->Wrap( -1 ); - bottom_sizer->Add( append_choice_label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - wxArrayString append_choiceChoices; - append_choice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, append_choiceChoices, 0 ); - append_choice->SetSelection( 0 ); - bottom_sizer->Add( append_choice, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - append_button = new wxButton( this, wxID_ANY, wxT("Append"), wxDefaultPosition, wxDefaultSize, 0 ); - bottom_sizer->Add( append_button, 0, wxALL, 5 ); - bottom_sizer->Add( 0, 0, 1, wxEXPAND, 5 ); + import_button = new wxButton( this, ID_IMPORT_BUTTON, wxT("Import games"), wxDefaultPosition, wxDefaultSize, 0 ); + bottom_sizer->Add( import_button, 0, wxALL, 5 ); + delete_button = new wxButton( this, ID_DELETE_BUTTON, wxT("Delete selection"), wxDefaultPosition, wxDefaultSize, 0 ); bottom_sizer->Add( delete_button, 0, wxALL, 5 ); diff --git a/src/base_tab/BasePanelBF.h b/src/base_tab/BasePanelBF.h index 1b74915..e00fc46 100644 --- a/src/base_tab/BasePanelBF.h +++ b/src/base_tab/BasePanelBF.h @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -29,7 +28,8 @@ #define ID_SAVE_BUTTON 1000 #define ID_EXPORT_BUTTON 1001 -#define ID_DELETE_BUTTON 1002 +#define ID_IMPORT_BUTTON 1002 +#define ID_DELETE_BUTTON 1003 /////////////////////////////////////////////////////////////////////////////// /// Class BasePanelBF @@ -43,9 +43,7 @@ class BasePanelBF : public wxPanel wxButton* save_button; wxButton* export_button; wxStaticLine* separator_1; - wxStaticText* append_choice_label; - wxChoice* append_choice; - wxButton* append_button; + wxButton* import_button; wxButton* delete_button; wxListCtrl* game_list; diff --git a/src/base_tab/BaseTab.cpp b/src/base_tab/BaseTab.cpp index f7cf48f..3816b59 100644 --- a/src/base_tab/BaseTab.cpp +++ b/src/base_tab/BaseTab.cpp @@ -1,5 +1,6 @@ #include "BaseTab.hpp" #include +#include "AppendGameDialog.hpp" BaseTab::BaseTab(wxFrame *parent, std::string base_file) : BasePanelBF(parent), base_file(base_file), TabInfos(TabInfos::BASE), @@ -17,10 +18,17 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file) this->Bind(wxEVT_BUTTON, &BaseTab::OnSave, this, ID_SAVE_BUTTON); this->Bind(wxEVT_BUTTON, &BaseTab::OnExport, this, ID_EXPORT_BUTTON); this->Bind(wxEVT_LIST_ITEM_ACTIVATED, &BaseTab::OnOpenGame, this, wxID_ANY); + this->Bind(wxEVT_BUTTON, &BaseTab::OnImport, this, ID_IMPORT_BUTTON); + current_base->SetLabel(base_file); LoadFile(); } +void BaseTab::OnImport(wxCommandEvent &event) { + AppendGameDialog *dia=new AppendGameDialog(this,base); + dia->ShowModal(); +} + void BaseTab::OnDelete(wxCommandEvent &event) { long selected = game_list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); @@ -77,7 +85,7 @@ void BaseTab::OnExport(wxCommandEvent &event) { GameBase *base; if (ext == "pgn") { base = new PGNGameBase(path); - base->Save(this->base); + base->Export(this->base); delete base; } } @@ -109,4 +117,4 @@ void BaseTab::LoadFile() { wxCommandEvent event(REFRESH_TAB_TITLE, GetId()); event.SetEventObject(this); ProcessEvent(event); -} \ No newline at end of file +} diff --git a/src/base_tab/BaseTab.hpp b/src/base_tab/BaseTab.hpp index a283975..8d01827 100644 --- a/src/base_tab/BaseTab.hpp +++ b/src/base_tab/BaseTab.hpp @@ -22,6 +22,7 @@ public: void OnSave(wxCommandEvent &event); void OnExport(wxCommandEvent &event); void OnOpenGame(wxListEvent &event); + void OnImport(wxCommandEvent &event); void *GetGame() { return (NULL); } void *GetBase() { return (base); }; }; \ No newline at end of file diff --git a/src/base_tab/gamebase/GameBase.hpp b/src/base_tab/gamebase/GameBase.hpp index cf87a9c..d13c01d 100644 --- a/src/base_tab/gamebase/GameBase.hpp +++ b/src/base_tab/gamebase/GameBase.hpp @@ -14,5 +14,10 @@ public: virtual bool NextGame() = 0; virtual std::string GetTag(std::string tag) = 0; virtual void Reset() = 0; - virtual void Save(GameBase *base) = 0; + /** + * @brief Save the given base into current base format (export) + * + * @param base + */ + virtual void Export(GameBase *base) = 0; }; \ No newline at end of file diff --git a/src/base_tab/gamebase/PGNGameBase.cpp b/src/base_tab/gamebase/PGNGameBase.cpp index dc6341c..3be65d7 100644 --- a/src/base_tab/gamebase/PGNGameBase.cpp +++ b/src/base_tab/gamebase/PGNGameBase.cpp @@ -98,7 +98,7 @@ void PGNGameBase::Save(std::vector to_ignore, wxRemoveFile(tmp); } -void PGNGameBase::Save(GameBase *base) { +void PGNGameBase::Export(GameBase *base) { wxFile new_pgn(file, wxFile::write); base->Reset(); diff --git a/src/base_tab/gamebase/PGNGameBase.hpp b/src/base_tab/gamebase/PGNGameBase.hpp index e153701..982f57c 100644 --- a/src/base_tab/gamebase/PGNGameBase.hpp +++ b/src/base_tab/gamebase/PGNGameBase.hpp @@ -16,5 +16,5 @@ public: std::vector new_games_bases, std::vector new_games); void Reset(); - void Save(GameBase *base); + void Export(GameBase *base); }; \ No newline at end of file diff --git a/tools/wxframebuilder/AppendGameDialog.fbp b/tools/wxframebuilder/AppendGameDialog.fbp new file mode 100644 index 0000000..0b65ea8 --- /dev/null +++ b/tools/wxframebuilder/AppendGameDialog.fbp @@ -0,0 +1,358 @@ + + + + + ; + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + AppendGameDialogBF + 1000 + none + + + 0 + AppendGameDialogBF + + ../../src/base_tab + + 1 + 1 + 1 + 1 + UI + 0 + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + AppendGameDialogBF + + 388,263 + wxDEFAULT_DIALOG_STYLE + ; ; forward_declare + + + 0 + + + + + + main_sizer + wxVERTICAL + none + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Please select games to import: + 0 + + 0 + + + 0 + + 1 + main_label + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALL|wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + game_list + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 + wxEXPAND + 0 + + + bSizer5 + wxHORIZONTAL + none + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + ID_DIALOG_CANCEL_BUTTON + Cancel + + 0 + + 0 + + + 0 + + 1 + cancel_button + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + ID_DIALOG_IMPORT_BUTTON + Import + + 0 + + 0 + + + 0 + + 1 + import_button + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + diff --git a/tools/wxframebuilder/BasePanel.fbp b/tools/wxframebuilder/BasePanel.fbp index c7ab989..ae395ef 100644 --- a/tools/wxframebuilder/BasePanel.fbp +++ b/tools/wxframebuilder/BasePanel.fbp @@ -344,127 +344,12 @@ none 5 - wxALIGN_CENTER_VERTICAL|wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Import games from: - 0 - - 0 - - - 0 - - 1 - append_choice_label - 1 - - + wxEXPAND + 1 + + 0 protected - 1 - - Resizable - 1 - - - ; ; forward_declare - 0 - - - - - -1 - - - - 5 - wxALIGN_CENTER_VERTICAL|wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - append_choice - 1 - - - protected - 1 - - Resizable - 0 - 1 - - - ; ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - + 0 @@ -504,8 +389,8 @@ 0 0 - wxID_ANY - Append + ID_IMPORT_BUTTON + Import games 0 @@ -515,7 +400,7 @@ 0 1 - append_button + import_button 1 @@ -540,16 +425,6 @@ - - 5 - wxEXPAND - 1 - - 0 - protected - 0 - - 5 wxALL