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) {
if (prefsEditor != NULL) {
prefsEditor->Dismiss();

View file

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

View file

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

View file

@ -1,8 +1,13 @@
#include "BaseImportTab.hpp"
BaseImportTab::BaseImportTab(wxFrame *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"
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 );
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 );
top_sizer->Add( m_comboBox1, 100, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
opened_game_list = new wxComboBox( this, wxID_ANY, wxT("No game opened"), wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
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 );
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_engine;
wxStatusBar* status_bar;
wxAuiNotebook* notebook;
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 );
@ -333,7 +333,7 @@ class TabBase_TabImport : public wxPanel
protected:
wxStaticText* from_game_label;
wxComboBox* m_comboBox1;
wxComboBox* opened_game_list;
wxButton* import_from_game_button;
wxStaticLine* m_staticline4;
wxStaticText* from_db_label;

View file

@ -8,6 +8,16 @@ bool MyApp::OnInit() {
frame->Show(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);
void Abort(std::string msg) {

View file

@ -32,19 +32,6 @@
#define CONFIG_OPEN(name) wxConfig *name = new wxConfig("ochess")
#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 GameBase;
@ -69,3 +56,19 @@ public:
virtual std::shared_ptr<Game> GetGame() = 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);