aboutsummaryrefslogtreecommitdiff
path: root/src/base_tab
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-02-26 12:30:07 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-02-26 12:30:07 +0100
commite0a1894928abb8361f959a147066e94e2cda996b (patch)
tree1ce31d0dda368d6b1c5527aa28d11543e620ee1e /src/base_tab
parent3b6e7d39cf2d03f2e43c249ece6da32f1f8030a7 (diff)
Improve database game import
Diffstat (limited to 'src/base_tab')
-rw-r--r--src/base_tab/AppendGameDialog.cpp28
-rw-r--r--src/base_tab/AppendGameDialog.hpp12
-rw-r--r--src/base_tab/AppendGameDialogBF.cpp50
-rw-r--r--src/base_tab/AppendGameDialogBF.h51
-rw-r--r--src/base_tab/BasePanelBF.cpp15
-rw-r--r--src/base_tab/BasePanelBF.h8
-rw-r--r--src/base_tab/BaseTab.cpp12
-rw-r--r--src/base_tab/BaseTab.hpp1
-rw-r--r--src/base_tab/gamebase/GameBase.hpp7
-rw-r--r--src/base_tab/gamebase/PGNGameBase.cpp2
-rw-r--r--src/base_tab/gamebase/PGNGameBase.hpp2
11 files changed, 166 insertions, 22 deletions
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<wxWindow *>(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<std::uint32_t> to_ignore;
+ std::vector<GameBase *> new_games_bases;
+ std::vector<Game *> 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<TabInfos *> 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 <wx/artprov.h>
+#include <wx/xrc/xmlres.h>
+#include <wx/string.h>
+#include <wx/stattext.h>
+#include <wx/gdicmn.h>
+#include <wx/font.h>
+#include <wx/colour.h>
+#include <wx/settings.h>
+#include <wx/listbox.h>
+#include <wx/button.h>
+#include <wx/bitmap.h>
+#include <wx/image.h>
+#include <wx/icon.h>
+#include <wx/sizer.h>
+#include <wx/dialog.h>
+
+///////////////////////////////////////////////////////////////////////////
+
+#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 <wx/icon.h>
#include <wx/sizer.h>
#include <wx/statline.h>
-#include <wx/choice.h>
#include <wx/listctrl.h>
#include <wx/panel.h>
@@ -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 <wx/filename.h>
+#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<std::uint32_t> 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<GameBase *> new_games_bases,
std::vector<Game *> new_games);
void Reset();
- void Save(GameBase *base);
+ void Export(GameBase *base);
}; \ No newline at end of file