diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index dfc100c..62b17e1 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -59,8 +59,11 @@ MainWindow::MainWindow() NewGame(std::shared_ptr(new Game())); // Temporary TO REMOVE JUST FOR TESTS: - //BaseTab *bt = new BaseTab((wxFrame *)notebook, "/home/loic/pgn/twic1467.pgn"); - //this->AddPage(bt,bt); + /*BaseTab *bt = new BaseTab((wxFrame *)notebook, "/home/loic/pgn/Milov.pgn"); + this->AddPage(bt,bt); + + bt = new BaseTab((wxFrame *)notebook, "/home/loic/pgn/Milov.pgn"); + this->AddPage(bt,bt);*/ } void MainWindow::AddPage(wxWindow* window, TabInfos* infos){ diff --git a/src/base_tab/BaseImportTab.cpp b/src/base_tab/BaseImportTab.cpp index 9b2f541..6395fdf 100644 --- a/src/base_tab/BaseImportTab.cpp +++ b/src/base_tab/BaseImportTab.cpp @@ -1,14 +1,38 @@ #include "BaseImportTab.hpp" +#include +#include "gamebase/GameBase.hpp" -BaseImportTab::BaseImportTab(wxFrame *parent, TabInfos *main_tab): -TabBase_TabImport(parent), main_tab(main_tab) +BaseImportTab::BaseImportTab(wxFrame *parent, std::shared_ptr db, TabInfos *main_tab): +TabBase_TabImport(parent), main_tab(main_tab), base(db) { - glm=new GameListManager(game_list); + glm=std::make_shared(game_list); RefreshImportLists(); + RefreshPendingImports(); this->Bind(wxEVT_BUTTON, &BaseImportTab::OnLoad, this, ID_LOAD_BUTTON); + this->Bind(wxEVT_BUTTON, &BaseImportTab::OnImportGame, this, ID_IMPORT_GAME_BUTTON); + this->Bind(wxEVT_BUTTON, &BaseImportTab::OnImportSelection, this, ID_IMPORT_SELECTION); + this->Bind(wxEVT_BUTTON, &BaseImportTab::OnImportDatabase, this, ID_IMPORT_DB); + opened_db_list->SetHint("No other database open"); } +void BaseImportTab::OnImportDatabase(wxCommandEvent &event){ + if(std::find(databases_to_import.begin(), databases_to_import.end(), selected_base) == databases_to_import.end()){ + databases_to_import.push_back(selected_base); + RefreshPendingImports(); + } + else SHOW_DIALOG_INFO("Database already prepared for import"); +} + +void BaseImportTab::RefreshPendingImports(){ + int ngames=games_to_import.size(); + int ndb=databases_to_import.size(); + if(ngames+ndb>0){ + pending_imports->SetLabel(" Pending imports: "+std::to_string(ngames)+" games and "+std::to_string(ndb)+" databases"); + }else + pending_imports->SetLabel(""); +} + void BaseImportTab::RefreshImportLists(){ opened_game_list->Clear(); opened_db_list->Clear(); @@ -26,6 +50,48 @@ void BaseImportTab::RefreshImportLists(){ } } -void BaseImportTab::OnLoad(wxCommandEvent &event){ -wxLogDebug("Load!"); +void BaseImportTab::OnImportSelection(wxCommandEvent &event){ + long selected = -1; + while ((selected = game_list->GetNextItem(selected, wxLIST_NEXT_ALL, + wxLIST_STATE_SELECTED)) != + wxNOT_FOUND) { + games_to_import.push_back(selected_base->GetGame(glm->GetItemGameId(selected))); + } + RefreshPendingImports(); +} + +void BaseImportTab::OnImportGame(wxCommandEvent &event){ + TabInfos *game_tab=(TabInfos*)opened_game_list->GetClientData(opened_game_list->GetSelection()); + std::shared_ptr g=game_tab->GetGame(); + if(std::find(games_to_import.begin(), games_to_import.end(), g) == games_to_import.end()){ wxLogDebug("Import!"); + games_to_import.push_back(g); + RefreshPendingImports(); + } + else SHOW_DIALOG_INFO("Game already prepared for import"); +} + +void BaseImportTab::OnLoad(wxCommandEvent &event){ + TabInfos *game_tab=(TabInfos*)opened_db_list->GetClientData(opened_db_list->GetSelection()); + selected_base.reset(); + selected_base=game_tab->GetBase(); + glm->Clear(); + + // Load all games (for now :) + selected_base->Reset(); + while (selected_base->NextGame()) { + glm->AddGame( + selected_base->GetTag("White"), + selected_base->GetTag("Black"), + selected_base->GetTag("Event"), + selected_base->GetTag("Round"), + selected_base->GetTag("Result"), + selected_base->GetTag("ECO")); + } +} + +void BaseImportTab::Reset(std::shared_ptr base){ + this->base=base; + this->games_to_import.clear(); + this->databases_to_import.clear(); + glm->Clear(); } diff --git a/src/base_tab/BaseImportTab.hpp b/src/base_tab/BaseImportTab.hpp index a301f9b..a3a19de 100644 --- a/src/base_tab/BaseImportTab.hpp +++ b/src/base_tab/BaseImportTab.hpp @@ -1,12 +1,24 @@ +#pragma once + #include "ochess.hpp" #include "GameListManager.hpp" +#include "game_tab/Game.hpp" class BaseImportTab : public TabBase_TabImport { TabInfos *main_tab; - GameListManager *glm; + std::shared_ptr glm; + std::vector> games_to_import; + std::vector> databases_to_import; + std::shared_ptr base; + std::shared_ptr selected_base; + void RefreshPendingImports(); public: - BaseImportTab(wxFrame *parent, TabInfos *main_tab); + BaseImportTab(wxFrame *parent, std::shared_ptr db, TabInfos *main_tab); void RefreshImportLists(); void OnLoad(wxCommandEvent &event); + void OnImportGame(wxCommandEvent &event); + void OnImportSelection(wxCommandEvent &event); + void OnImportDatabase(wxCommandEvent &event); + void Reset(std::shared_ptr base); }; \ No newline at end of file diff --git a/src/base_tab/BaseTab.cpp b/src/base_tab/BaseTab.cpp index 05ff907..c13caae 100644 --- a/src/base_tab/BaseTab.cpp +++ b/src/base_tab/BaseTab.cpp @@ -10,9 +10,10 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file) // Games tab games_tab=new BaseGameTab((wxFrame *)notebook,base,this); + glm=games_tab->glm; notebook->AddPage(games_tab, "Games list",true); // true for selecting the tab // Import tab - import_tab=new BaseImportTab((wxFrame *)notebook,this); + import_tab=new BaseImportTab((wxFrame *)notebook,base,this); notebook->AddPage(import_tab, "Import games"); // Manage tab manage_tab=new BaseManageTab((wxFrame *)notebook, base, games_tab->glm); @@ -67,4 +68,5 @@ void BaseTab::OnSave(wxCommandEvent &event) { OpenDatabase(base_file); games_tab->Reset(base); manage_tab->Reset(base); + import_tab->Reset(base); } \ No newline at end of file diff --git a/src/base_tab/BaseTab.hpp b/src/base_tab/BaseTab.hpp index c8efd11..5b21353 100644 --- a/src/base_tab/BaseTab.hpp +++ b/src/base_tab/BaseTab.hpp @@ -1,3 +1,4 @@ +#pragma once #include "gamebase/GameBase.hpp" #include "ochess.hpp" @@ -19,6 +20,7 @@ class BaseTab : public TabBase, public TabInfos { BaseManageTab *manage_tab; std::string base_file; + std::shared_ptr glm; void OnOpenGame(wxCommandEvent &event); void OnSave(wxCommandEvent &event); diff --git a/src/gui.cpp b/src/gui.cpp index 507eca0..b33583f 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -565,31 +565,38 @@ TabBase_TabImport::TabBase_TabImport( wxWindow* parent, wxWindowID id, const wxP wxBoxSizer* main_sizer; main_sizer = new wxBoxSizer( wxVERTICAL ); - from_game_label = new wxStaticText( this, wxID_ANY, wxT("From opened games"), wxDefaultPosition, wxDefaultSize, 0 ); - from_game_label->Wrap( -1 ); - main_sizer->Add( from_game_label, 0, wxALL, 5 ); + pending_imports = new wxStaticText( this, wxID_ANY, wxT("No pending imports"), wxDefaultPosition, wxDefaultSize, 0 ); + pending_imports->Wrap( -1 ); + pending_imports->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); - wxBoxSizer* top_sizer; - top_sizer = new wxBoxSizer( wxHORIZONTAL ); + main_sizer->Add( pending_imports, 0, wxALL|wxEXPAND, 5 ); + + m_staticline41 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); + main_sizer->Add( m_staticline41, 0, wxEXPAND | wxALL, 5 ); + + wxBoxSizer* games_sizer; + games_sizer = new wxBoxSizer( wxHORIZONTAL ); + + from_game_label = new wxStaticText( this, wxID_ANY, wxT("Games:"), wxDefaultPosition, wxDefaultSize, 0 ); + from_game_label->Wrap( -1 ); + from_game_label->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); + + games_sizer->Add( from_game_label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); opened_game_list = new wxComboBox( this, wxID_ANY, wxT("No game opened"), wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); - top_sizer->Add( opened_game_list, 100, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + games_sizer->Add( opened_game_list, 100, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - import_from_game_button = new wxButton( this, wxID_ANY, wxT("Import Game"), wxDefaultPosition, wxDefaultSize, 0 ); - top_sizer->Add( import_from_game_button, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + import_from_game_button = new wxButton( this, ID_IMPORT_GAME_BUTTON, wxT("Import Game"), wxDefaultPosition, wxDefaultSize, 0 ); + games_sizer->Add( import_from_game_button, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - main_sizer->Add( top_sizer, 1, wxALIGN_TOP|wxEXPAND, 5 ); + main_sizer->Add( games_sizer, 0, wxALIGN_TOP|wxEXPAND, 5 ); m_staticline4 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); main_sizer->Add( m_staticline4, 0, wxEXPAND | wxALL, 5 ); - from_db_label = new wxStaticText( this, wxID_ANY, wxT("From opened databases"), wxDefaultPosition, wxDefaultSize, 0 ); - from_db_label->Wrap( -1 ); - main_sizer->Add( from_db_label, 0, wxALL, 5 ); - - wxBoxSizer* bottom_sizer; - bottom_sizer = new wxBoxSizer( wxVERTICAL ); + wxBoxSizer* databases_sizer; + databases_sizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer* bSizer33; bSizer33 = new wxBoxSizer( wxHORIZONTAL ); @@ -605,18 +612,21 @@ TabBase_TabImport::TabBase_TabImport( wxWindow* parent, wxWindowID id, const wxP bSizer33->Add( load_button, 0, wxALL, 5 ); - bottom_sizer->Add( bSizer33, 1, wxEXPAND, 5 ); + databases_sizer->Add( bSizer33, 0, wxEXPAND, 5 ); - game_list = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_ICON|wxLC_REPORT ); + game_list = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT ); game_list->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_INACTIVECAPTIONTEXT ) ); - bottom_sizer->Add( game_list, 20, wxALL|wxEXPAND, 5 ); + databases_sizer->Add( game_list, 100, wxALL|wxEXPAND, 5 ); - import_from_db_button = new wxButton( this, wxID_ANY, wxT("Import Selection"), wxDefaultPosition, wxDefaultSize, 0 ); - bottom_sizer->Add( import_from_db_button, 0, wxALL|wxEXPAND, 5 ); + import_from_db_button = new wxButton( this, ID_IMPORT_SELECTION, wxT("Import Selection"), wxDefaultPosition, wxDefaultSize, 0 ); + databases_sizer->Add( import_from_db_button, 0, wxALL|wxEXPAND, 5 ); + + m_button16 = new wxButton( this, ID_IMPORT_DB, wxT("Import all games"), wxDefaultPosition, wxDefaultSize, 0 ); + databases_sizer->Add( m_button16, 0, wxALL|wxEXPAND, 5 ); - main_sizer->Add( bottom_sizer, 100, wxEXPAND, 5 ); + main_sizer->Add( databases_sizer, 80, wxEXPAND, 5 ); this->SetSizer( main_sizer ); diff --git a/src/gui.h b/src/gui.h index 91de89e..df64a5e 100644 --- a/src/gui.h +++ b/src/gui.h @@ -58,8 +58,11 @@ #define ID_SEARCH_TERMS 1013 #define ID_APPLY_FILTER_BUTTON 1014 #define ID_DELETE_BUTTON 1015 -#define ID_LOAD_BUTTON 1016 -#define ID_SAVE_BUTTON 1017 +#define ID_IMPORT_GAME_BUTTON 1016 +#define ID_LOAD_BUTTON 1017 +#define ID_IMPORT_SELECTION 1018 +#define ID_IMPORT_DB 1019 +#define ID_SAVE_BUTTON 1020 /////////////////////////////////////////////////////////////////////////////// /// Class MainFrame @@ -331,20 +334,22 @@ class TabBase_TabImport : public wxPanel private: protected: + wxStaticText* pending_imports; + wxStaticLine* m_staticline41; wxStaticText* from_game_label; wxComboBox* opened_game_list; wxButton* import_from_game_button; wxStaticLine* m_staticline4; - wxStaticText* from_db_label; wxStaticText* m_staticText29; wxComboBox* opened_db_list; wxButton* load_button; wxListCtrl* game_list; wxButton* import_from_db_button; + wxButton* m_button16; public: - TabBase_TabImport( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,200 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); + TabBase_TabImport( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,661 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); ~TabBase_TabImport(); diff --git a/src/ochess.cpp b/src/ochess.cpp index 74ffc88..3cfa8be 100644 --- a/src/ochess.cpp +++ b/src/ochess.cpp @@ -1,5 +1,6 @@ #include "ochess.hpp" #include "MainWindow.hpp" +#include "base_tab/BaseTab.hpp" bool MyApp::OnInit() { wxImage::AddHandler(new wxPNGHandler); @@ -18,6 +19,7 @@ std::vector MyApp::ListTabInfos() { return (tinfos); } + wxIMPLEMENT_APP(MyApp); void Abort(std::string msg) { diff --git a/src/ochess.hpp b/src/ochess.hpp index 7f94fe1..2692521 100644 --- a/src/ochess.hpp +++ b/src/ochess.hpp @@ -21,7 +21,7 @@ NULL, wxT(message), wxT("Error"), wxOK | wxICON_ERROR); \ dial->ShowModal(); \ } - +#define SHOW_DIALOG_INFO(message) {wxMessageBox( wxT(message) );} #define REQUIRE_FILE(file) \ { \ if (!wxFileExists(file)) { \ diff --git a/tools/wxFrameBuilder.fbp b/tools/wxFrameBuilder.fbp index c442080..006a2d1 100644 --- a/tools/wxFrameBuilder.fbp +++ b/tools/wxFrameBuilder.fbp @@ -5135,7 +5135,7 @@ - + 0 wxAUI_MGR_DEFAULT @@ -5158,7 +5158,7 @@ wxTAB_TRAVERSAL - + main_sizer wxVERTICAL @@ -5520,7 +5520,7 @@ - + 0 wxAUI_MGR_DEFAULT @@ -5536,23 +5536,84 @@ TabBase_TabImport - 500,200 + 500,661 ; ; forward_declare 0 wxTAB_TRAVERSAL - + main_sizer wxVERTICAL none - + 5 - wxALL + wxALL|wxEXPAND 0 - + + 1 + 1 + 1 + 1 + + + + + + wxSYS_COLOUR_WINDOW + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + No pending imports + 0 + + 0 + + + 0 + + 1 + pending_imports + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxEXPAND | wxALL + 0 + 1 1 1 @@ -5580,8 +5641,6 @@ 0 0 wxID_ANY - From opened games - 0 0 @@ -5589,7 +5648,7 @@ 0 1 - from_game_label + m_staticline41 1 @@ -5599,25 +5658,85 @@ Resizable 1 - + wxLI_HORIZONTAL ; ; forward_declare 0 - -1 - + 5 wxALIGN_TOP|wxEXPAND - 1 - + 0 + - top_sizer + games_sizer wxHORIZONTAL none + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + wxSYS_COLOUR_WINDOW + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Games: + 0 + + 0 + + + 0 + + 1 + from_game_label + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + 5 wxALIGN_CENTER_VERTICAL|wxALL @@ -5720,7 +5839,7 @@ 0 0 - wxID_ANY + ID_IMPORT_GAME_BUTTON Import Game 0 @@ -5816,80 +5935,19 @@ - - 5 - wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - From opened databases - 0 - - 0 - - - 0 - - 1 - from_db_label - 1 - - - protected - 1 - - Resizable - 1 - - - ; ; forward_declare - 0 - - - - - -1 - - - + 5 wxEXPAND - 100 - + 80 + - bottom_sizer + databases_sizer wxVERTICAL none - + 5 wxEXPAND - 1 + 0 bSizer33 @@ -6099,7 +6157,7 @@ 5 wxALL|wxEXPAND - 20 + 100 1 1 @@ -6145,7 +6203,7 @@ Resizable 1 - wxLC_ICON|wxLC_REPORT + wxLC_REPORT ; ; forward_declare 0 @@ -6195,7 +6253,7 @@ 0 0 - wxID_ANY + ID_IMPORT_SELECTION Import Selection 0 @@ -6231,6 +6289,79 @@ + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + ID_IMPORT_DB + Import all games + + 0 + + 0 + + + 0 + + 1 + m_button16 + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + +