mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Improve database management
This commit is contained in:
parent
5c8334af1d
commit
5691b7b30f
5 changed files with 26 additions and 1 deletions
|
@ -35,7 +35,8 @@ MainWindow::MainWindow()
|
||||||
menu_game->Append(3, "New from FEN", "Create new game using FEN");
|
menu_game->Append(3, "New from FEN", "Create new game using FEN");
|
||||||
|
|
||||||
// Game base menu
|
// Game base menu
|
||||||
menu_db->Append(5, "Open", "Open a database");
|
menu_db->Append(7, "New", "Create database");
|
||||||
|
menu_db->Append(5, "Open", "Open database");
|
||||||
|
|
||||||
// Engine menu
|
// Engine menu
|
||||||
menu_engine->Append(6, "New", "Create a new engine configuration");
|
menu_engine->Append(6, "New", "Create a new engine configuration");
|
||||||
|
@ -129,6 +130,16 @@ void MainWindow::OnMenuItemClick(wxCommandEvent &event) {
|
||||||
OpenFile();
|
OpenFile();
|
||||||
} else if (id == 6) {
|
} else if (id == 6) {
|
||||||
NewEngine();
|
NewEngine();
|
||||||
|
} else if (id == 7) {
|
||||||
|
wxFileDialog
|
||||||
|
newFileDialog(this, _("Create database file"), "", "",
|
||||||
|
"PGN files (*.pgn)|*.pgn", wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
|
||||||
|
if (newFileDialog.ShowModal() == wxID_CANCEL)
|
||||||
|
return;
|
||||||
|
// Create and open new db
|
||||||
|
std::string path = newFileDialog.GetPath().ToStdString();
|
||||||
|
BaseTab *bt = new BaseTab((wxFrame *)notebook, path);
|
||||||
|
AddPage(bt,bt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,10 @@ void BaseTab::Refresh(){
|
||||||
void BaseTab::OpenDatabase(std::string dbpath) {
|
void BaseTab::OpenDatabase(std::string dbpath) {
|
||||||
wxFileName file(dbpath);
|
wxFileName file(dbpath);
|
||||||
wxString ext = file.GetExt().Lower();
|
wxString ext = file.GetExt().Lower();
|
||||||
|
wxLogDebug("Here");
|
||||||
if (ext == "pgn") {
|
if (ext == "pgn") {
|
||||||
|
if(!file.Exists())
|
||||||
|
PGNGameBase::CreateDatabaseFile(dbpath);
|
||||||
base.reset();
|
base.reset();
|
||||||
base = std::shared_ptr<GameBase>(new PGNGameBase(dbpath));
|
base = std::shared_ptr<GameBase>(new PGNGameBase(dbpath));
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,4 +22,9 @@ public:
|
||||||
* @param base
|
* @param base
|
||||||
*/
|
*/
|
||||||
virtual void Export(std::shared_ptr<GameBase> base) = 0;
|
virtual void Export(std::shared_ptr<GameBase> base) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief An additionnal static method is expected with the following signature:
|
||||||
|
* static void CreateDatabaseFile(std::string path);
|
||||||
|
*/
|
||||||
};
|
};
|
|
@ -28,6 +28,11 @@ std::string PGNGameBase::GetTag(std::string tag) {
|
||||||
return ("");
|
return ("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PGNGameBase::CreateDatabaseFile(std::string path){
|
||||||
|
wxFile empty_pgn(path, wxFile::write);
|
||||||
|
empty_pgn.Close();
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<Game> PGNGameBase::GetCurrentGame() {
|
std::shared_ptr<Game> PGNGameBase::GetCurrentGame() {
|
||||||
pgnp::HalfMove *pgnp_moves = new pgnp::HalfMove();
|
pgnp::HalfMove *pgnp_moves = new pgnp::HalfMove();
|
||||||
pgn->GetMoves(pgnp_moves);
|
pgn->GetMoves(pgnp_moves);
|
||||||
|
|
|
@ -22,4 +22,5 @@ public:
|
||||||
std::string GetFilePath() {return(file);};
|
std::string GetFilePath() {return(file);};
|
||||||
static std::string GetMovesPGN(HalfMove *m, bool needDots);
|
static std::string GetMovesPGN(HalfMove *m, bool needDots);
|
||||||
static std::string GetPGN(std::shared_ptr<Game> g);
|
static std::string GetPGN(std::shared_ptr<Game> g);
|
||||||
|
static void CreateDatabaseFile(std::string path);
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue