Update the db import game feature

This commit is contained in:
Loic Guegan 2022-12-25 11:13:05 +01:00
parent 1293b59ed5
commit 4ffba108e3
10 changed files with 47 additions and 41 deletions

View file

@ -174,14 +174,6 @@ void MainWindow::ApplyPreferences() {
} }
} }
std::vector<TabInfos *> MainWindow::ListTabInfos() {
std::vector<TabInfos *> tinfos;
for (int i = 0; i < notebook->GetPageCount(); i++) {
tinfos.push_back(dynamic_cast<TabInfos *>(notebook->GetPage(i)));
}
return (tinfos);
}
void MainWindow::OnClose(wxCloseEvent &e) { void MainWindow::OnClose(wxCloseEvent &e) {
if (prefsEditor != NULL) { if (prefsEditor != NULL) {
prefsEditor->Dismiss(); prefsEditor->Dismiss();

View file

@ -2,7 +2,6 @@
#include "base_tab/BaseTab.hpp" #include "base_tab/BaseTab.hpp"
#include "game_tab/GameTab.hpp" #include "game_tab/GameTab.hpp"
#include "ochess.hpp"
#include <wx/aui/auibook.h> #include <wx/aui/auibook.h>
#include <wx/filedlg.h> #include <wx/filedlg.h>
#include <wx/preferences.h> #include <wx/preferences.h>
@ -35,5 +34,4 @@ class MainWindow : public MainFrame {
public: public:
MainWindow(); MainWindow();
void ApplyPreferences(); void ApplyPreferences();
std::vector<TabInfos *> ListTabInfos();
}; };

View file

@ -5,7 +5,7 @@
AppendGameDialog::AppendGameDialog(wxWindow *parent, std::shared_ptr<GameBase> base) AppendGameDialog::AppendGameDialog(wxWindow *parent, std::shared_ptr<GameBase> base)
: DialogAppendGame(parent), base(base) { : DialogAppendGame(parent), base(base) {
for (TabInfos *i : MAINWIN->ListTabInfos()) { for (TabInfos *i : wxGetApp().ListTabInfos()) {
if (i->type == TabInfos::GAME || i->type == TabInfos::BASE) { if (i->type == TabInfos::GAME || i->type == TabInfos::BASE) {
wxWindow *win = dynamic_cast<wxWindow *>(i); wxWindow *win = dynamic_cast<wxWindow *>(i);
game_list->Append(win->GetLabel()); game_list->Append(win->GetLabel());

View file

@ -1,8 +1,13 @@
#include "BaseImportTab.hpp" #include "BaseImportTab.hpp"
BaseImportTab::BaseImportTab(wxFrame *parent): BaseImportTab::BaseImportTab(wxFrame *parent):
TabBase_TabImport(parent) TabBase_TabImport(parent)
{ {
for (TabInfos *i : wxGetApp().ListTabInfos()) {
if (i->type == TabInfos::GAME || i->type == TabInfos::BASE) {
wxWindow *win = dynamic_cast<wxWindow *>(i);
opened_game_list->Append(win->GetLabel(),i);
opened_game_list->SetSelection(0);
}
}
} }

View file

@ -1,7 +1,5 @@
#include "ochess.hpp" #include "ochess.hpp"
class BaseImportTab : public TabBase_TabImport { class BaseImportTab : public TabBase_TabImport {

View file

@ -581,8 +581,8 @@ TabBase_TabImport::TabBase_TabImport( wxWindow* parent, wxWindowID id, const wxP
from_game_label->Wrap( -1 ); from_game_label->Wrap( -1 );
top_sizer->Add( from_game_label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); top_sizer->Add( from_game_label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_comboBox1 = new wxComboBox( this, wxID_ANY, wxT("Combo!"), wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); opened_game_list = new wxComboBox( this, wxID_ANY, wxT("No game opened"), wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
top_sizer->Add( m_comboBox1, 100, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); top_sizer->Add( opened_game_list, 100, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
import_from_game_button = new wxButton( this, wxID_ANY, wxT("Import"), wxDefaultPosition, wxDefaultSize, 0 ); import_from_game_button = new wxButton( this, wxID_ANY, wxT("Import"), wxDefaultPosition, wxDefaultSize, 0 );
top_sizer->Add( import_from_game_button, 0, wxALL, 5 ); top_sizer->Add( import_from_game_button, 0, wxALL, 5 );

View file

@ -74,9 +74,9 @@ class MainFrame : public wxFrame
wxMenu* menu_db; wxMenu* menu_db;
wxMenu* menu_engine; wxMenu* menu_engine;
wxStatusBar* status_bar; wxStatusBar* status_bar;
wxAuiNotebook* notebook;
public: public:
wxAuiNotebook* notebook;
MainFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("OChess"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL ); MainFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("OChess"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
@ -333,7 +333,7 @@ class TabBase_TabImport : public wxPanel
protected: protected:
wxStaticText* from_game_label; wxStaticText* from_game_label;
wxComboBox* m_comboBox1; wxComboBox* opened_game_list;
wxButton* import_from_game_button; wxButton* import_from_game_button;
wxStaticLine* m_staticline4; wxStaticLine* m_staticline4;
wxStaticText* from_db_label; wxStaticText* from_db_label;

View file

@ -8,6 +8,16 @@ bool MyApp::OnInit() {
frame->Show(true); frame->Show(true);
return true; return true;
} }
std::vector<TabInfos *> MyApp::ListTabInfos() {
std::vector<TabInfos *> tinfos;
wxAuiNotebook *notebook=((MainWindow *)this->GetTopWindow())->notebook;
for (int i = 0; i < notebook->GetPageCount(); i++) {
tinfos.push_back(dynamic_cast<TabInfos *>(notebook->GetPage(i)));
}
return (tinfos);
}
wxIMPLEMENT_APP(MyApp); wxIMPLEMENT_APP(MyApp);
void Abort(std::string msg) { void Abort(std::string msg) {

View file

@ -32,19 +32,6 @@
#define CONFIG_OPEN(name) wxConfig *name = new wxConfig("ochess") #define CONFIG_OPEN(name) wxConfig *name = new wxConfig("ochess")
#define CONFIG_CLOSE(name) delete name #define CONFIG_CLOSE(name) delete name
/**
* @brief Main application
*
*/
class MyApp : public wxApp {
public:
virtual bool OnInit();
};
wxDECLARE_APP(MyApp);
///@brief Abort ochess with a message
void Abort(std::string msg);
class Game; class Game;
class GameBase; class GameBase;
@ -69,3 +56,19 @@ public:
virtual std::shared_ptr<Game> GetGame() = 0; virtual std::shared_ptr<Game> GetGame() = 0;
virtual std::shared_ptr<GameBase> GetBase() = 0; virtual std::shared_ptr<GameBase> GetBase() = 0;
}; };
/**
* @brief Main application
*
*/
class MyApp : public wxApp {
public:
virtual bool OnInit();
std::vector<TabInfos *> ListTabInfos();
};
wxDECLARE_APP(MyApp);
///@brief Abort ochess with a message
void Abort(std::string msg);

View file

@ -29,7 +29,7 @@
<property name="use_array_enum">0</property> <property name="use_array_enum">0</property>
<property name="use_enum">0</property> <property name="use_enum">0</property>
<property name="use_microsoft_bom">0</property> <property name="use_microsoft_bom">0</property>
<object class="Frame" expanded="0"> <object class="Frame" expanded="1">
<property name="aui_managed">0</property> <property name="aui_managed">0</property>
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property> <property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
<property name="bg"></property> <property name="bg"></property>
@ -122,7 +122,7 @@
<property name="window_name"></property> <property name="window_name"></property>
<property name="window_style"></property> <property name="window_style"></property>
</object> </object>
<object class="wxBoxSizer" expanded="0"> <object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="name">main_sizer</property> <property name="name">main_sizer</property>
<property name="orient">wxVERTICAL</property> <property name="orient">wxVERTICAL</property>
@ -170,7 +170,7 @@
<property name="pane_border">1</property> <property name="pane_border">1</property>
<property name="pane_position"></property> <property name="pane_position"></property>
<property name="pane_size"></property> <property name="pane_size"></property>
<property name="permission">protected</property> <property name="permission">public</property>
<property name="pin_button">1</property> <property name="pin_button">1</property>
<property name="pos"></property> <property name="pos"></property>
<property name="resize">Resizable</property> <property name="resize">Resizable</property>
@ -5670,7 +5670,7 @@
</object> </object>
</object> </object>
</object> </object>
<object class="Panel" expanded="0"> <object class="Panel" expanded="1">
<property name="aui_managed">0</property> <property name="aui_managed">0</property>
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property> <property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
<property name="bg"></property> <property name="bg"></property>
@ -5693,16 +5693,16 @@
<property name="window_extra_style"></property> <property name="window_extra_style"></property>
<property name="window_name"></property> <property name="window_name"></property>
<property name="window_style">wxTAB_TRAVERSAL</property> <property name="window_style">wxTAB_TRAVERSAL</property>
<object class="wxBoxSizer" expanded="0"> <object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="name">main_sizer</property> <property name="name">main_sizer</property>
<property name="orient">wxVERTICAL</property> <property name="orient">wxVERTICAL</property>
<property name="permission">none</property> <property name="permission">none</property>
<object class="sizeritem" expanded="0"> <object class="sizeritem" expanded="1">
<property name="border">5</property> <property name="border">5</property>
<property name="flag">wxEXPAND</property> <property name="flag">wxEXPAND</property>
<property name="proportion">1</property> <property name="proportion">1</property>
<object class="wxBoxSizer" expanded="0"> <object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="name">top_sizer</property> <property name="name">top_sizer</property>
<property name="orient">wxHORIZONTAL</property> <property name="orient">wxHORIZONTAL</property>
@ -5808,7 +5808,7 @@
<property name="minimize_button">0</property> <property name="minimize_button">0</property>
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="moveable">1</property> <property name="moveable">1</property>
<property name="name">m_comboBox1</property> <property name="name">opened_game_list</property>
<property name="pane_border">1</property> <property name="pane_border">1</property>
<property name="pane_position"></property> <property name="pane_position"></property>
<property name="pane_size"></property> <property name="pane_size"></property>
@ -5827,7 +5827,7 @@
<property name="validator_style">wxFILTER_NONE</property> <property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property> <property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property> <property name="validator_variable"></property>
<property name="value">Combo!</property> <property name="value">No game opened</property>
<property name="window_extra_style"></property> <property name="window_extra_style"></property>
<property name="window_name"></property> <property name="window_name"></property>
<property name="window_style"></property> <property name="window_style"></property>