mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Enable database export
This commit is contained in:
parent
cbcc455e33
commit
98488e899a
9 changed files with 57 additions and 14 deletions
|
@ -24,7 +24,7 @@ BasePanelBF::BasePanelBF( wxWindow* parent, wxWindowID id, const wxPoint& pos, c
|
||||||
save_button = new wxButton( this, ID_SAVE_BUTTON, wxT("Save"), wxDefaultPosition, wxDefaultSize, 0 );
|
save_button = new wxButton( this, ID_SAVE_BUTTON, wxT("Save"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||||
top_sizer->Add( save_button, 0, wxALL, 5 );
|
top_sizer->Add( save_button, 0, wxALL, 5 );
|
||||||
|
|
||||||
export_button = new wxButton( this, wxID_ANY, wxT("Export"), wxDefaultPosition, wxDefaultSize, 0 );
|
export_button = new wxButton( this, ID_EXPORT_BUTTON, wxT("Export"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||||
top_sizer->Add( export_button, 0, wxALL, 5 );
|
top_sizer->Add( export_button, 0, wxALL, 5 );
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,8 @@
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#define ID_SAVE_BUTTON 1000
|
#define ID_SAVE_BUTTON 1000
|
||||||
#define ID_DELETE_BUTTON 1001
|
#define ID_EXPORT_BUTTON 1001
|
||||||
|
#define ID_DELETE_BUTTON 1002
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
/// Class BasePanelBF
|
/// Class BasePanelBF
|
||||||
|
|
|
@ -15,6 +15,7 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file)
|
||||||
|
|
||||||
this->Bind(wxEVT_BUTTON, &BaseTab::OnDelete, this, ID_DELETE_BUTTON);
|
this->Bind(wxEVT_BUTTON, &BaseTab::OnDelete, this, ID_DELETE_BUTTON);
|
||||||
this->Bind(wxEVT_BUTTON, &BaseTab::OnSave, this, ID_SAVE_BUTTON);
|
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_LIST_ITEM_ACTIVATED, &BaseTab::OnOpenGame, this, wxID_ANY);
|
||||||
current_base->SetLabel(base_file);
|
current_base->SetLabel(base_file);
|
||||||
LoadFile();
|
LoadFile();
|
||||||
|
@ -65,6 +66,23 @@ void BaseTab::OnOpenGame(wxListEvent &event) {
|
||||||
|
|
||||||
void BaseTab::ApplyPreferences() {}
|
void BaseTab::ApplyPreferences() {}
|
||||||
|
|
||||||
|
void BaseTab::OnExport(wxCommandEvent &event) {
|
||||||
|
wxFileDialog openFileDialog(this, _("Export database"), "", "",
|
||||||
|
"Database files (*.pgn)|*.pgn",
|
||||||
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
||||||
|
if (openFileDialog.ShowModal() != wxID_CANCEL) {
|
||||||
|
std::string path = openFileDialog.GetPath().ToStdString();
|
||||||
|
wxFileName file(base_file);
|
||||||
|
wxString ext = file.GetExt().Lower();
|
||||||
|
GameBase *base;
|
||||||
|
if (ext == "pgn") {
|
||||||
|
base = new PGNGameBase(path);
|
||||||
|
base->Save(this->base);
|
||||||
|
delete base;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BaseTab::LoadFile() {
|
void BaseTab::LoadFile() {
|
||||||
wxFileName file(base_file);
|
wxFileName file(base_file);
|
||||||
wxString ext = file.GetExt().Lower();
|
wxString ext = file.GetExt().Lower();
|
||||||
|
|
|
@ -20,5 +20,6 @@ public:
|
||||||
void LoadFile();
|
void LoadFile();
|
||||||
void OnDelete(wxCommandEvent &event);
|
void OnDelete(wxCommandEvent &event);
|
||||||
void OnSave(wxCommandEvent &event);
|
void OnSave(wxCommandEvent &event);
|
||||||
|
void OnExport(wxCommandEvent &event);
|
||||||
void OnOpenGame(wxListEvent &event);
|
void OnOpenGame(wxListEvent &event);
|
||||||
};
|
};
|
|
@ -14,4 +14,5 @@ public:
|
||||||
virtual bool NextGame() = 0;
|
virtual bool NextGame() = 0;
|
||||||
virtual std::string GetTag(std::string tag) = 0;
|
virtual std::string GetTag(std::string tag) = 0;
|
||||||
virtual void Reset() = 0;
|
virtual void Reset() = 0;
|
||||||
|
virtual void Save(GameBase *base) = 0;
|
||||||
};
|
};
|
|
@ -68,11 +68,16 @@ void PGNGameBase::Save(std::vector<std::uint32_t> to_ignore,
|
||||||
|
|
||||||
Reset();
|
Reset();
|
||||||
std::uint32_t id = 0;
|
std::uint32_t id = 0;
|
||||||
|
bool several = false;
|
||||||
while (NextGame()) {
|
while (NextGame()) {
|
||||||
if (std::find(to_ignore.begin(), to_ignore.end(), id) == to_ignore.end()) {
|
if (std::find(to_ignore.begin(), to_ignore.end(), id) == to_ignore.end()) {
|
||||||
|
if (several) {
|
||||||
|
new_pgn.Write("\n\n");
|
||||||
|
} else {
|
||||||
|
several = true;
|
||||||
|
}
|
||||||
Game *g = GetCurrentGame();
|
Game *g = GetCurrentGame();
|
||||||
new_pgn.Write(g->GetPGN());
|
new_pgn.Write(g->GetPGN());
|
||||||
new_pgn.Write("\n\n");
|
|
||||||
delete g;
|
delete g;
|
||||||
}
|
}
|
||||||
id++;
|
id++;
|
||||||
|
@ -80,18 +85,34 @@ void PGNGameBase::Save(std::vector<std::uint32_t> to_ignore,
|
||||||
|
|
||||||
// Now add new games
|
// Now add new games
|
||||||
for (Game *g : new_games) {
|
for (Game *g : new_games) {
|
||||||
|
if (several) {
|
||||||
|
new_pgn.Write("\n\n");
|
||||||
|
} else {
|
||||||
|
several = true;
|
||||||
|
}
|
||||||
new_pgn.Write(g->GetPGN());
|
new_pgn.Write(g->GetPGN());
|
||||||
new_pgn.Write("\n\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// new_games->Reset();
|
|
||||||
// while (new_games->NextGame()) {
|
|
||||||
// Game *g = new_games->GetCurrentGame();
|
|
||||||
// new_pgn.Write(g->GetPGN());
|
|
||||||
// delete g;
|
|
||||||
// }
|
|
||||||
|
|
||||||
new_pgn.Close();
|
new_pgn.Close();
|
||||||
wxCopyFile(tmp, file);
|
wxCopyFile(tmp, file);
|
||||||
wxRemoveFile(tmp);
|
wxRemoveFile(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PGNGameBase::Save(GameBase *base) {
|
||||||
|
wxFile new_pgn(file, wxFile::write);
|
||||||
|
|
||||||
|
base->Reset();
|
||||||
|
bool several = false;
|
||||||
|
while (base->NextGame()) {
|
||||||
|
if (several) {
|
||||||
|
new_pgn.Write("\n\n");
|
||||||
|
} else {
|
||||||
|
several = true;
|
||||||
|
}
|
||||||
|
Game *g = base->GetCurrentGame();
|
||||||
|
new_pgn.Write(g->GetPGN());
|
||||||
|
delete g;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_pgn.Close();
|
||||||
|
}
|
||||||
|
|
|
@ -16,4 +16,5 @@ public:
|
||||||
std::vector<GameBase *> new_games_bases,
|
std::vector<GameBase *> new_games_bases,
|
||||||
std::vector<Game *> new_games);
|
std::vector<Game *> new_games);
|
||||||
void Reset();
|
void Reset();
|
||||||
|
void Save(GameBase *base);
|
||||||
};
|
};
|
|
@ -50,7 +50,7 @@ void Abort(std::string msg);
|
||||||
*/
|
*/
|
||||||
class TabInfos {
|
class TabInfos {
|
||||||
public:
|
public:
|
||||||
typedef enum Type { GAME, BASE,NONE } Type;
|
typedef enum Type { GAME, BASE, NONE } Type;
|
||||||
Type type;
|
Type type;
|
||||||
TabInfos(Type type_) : type(type_) {}
|
TabInfos(Type type_) : type(type_) {}
|
||||||
virtual void ApplyPreferences() = 0;
|
virtual void ApplyPreferences() = 0;
|
||||||
|
|
|
@ -164,7 +164,7 @@
|
||||||
<property name="font"></property>
|
<property name="font"></property>
|
||||||
<property name="gripper">0</property>
|
<property name="gripper">0</property>
|
||||||
<property name="hidden">0</property>
|
<property name="hidden">0</property>
|
||||||
<property name="id">ID_SAVE_BTN</property>
|
<property name="id">ID_SAVE_BUTTON</property>
|
||||||
<property name="label">Save</property>
|
<property name="label">Save</property>
|
||||||
<property name="margins"></property>
|
<property name="margins"></property>
|
||||||
<property name="markup">0</property>
|
<property name="markup">0</property>
|
||||||
|
@ -237,7 +237,7 @@
|
||||||
<property name="font"></property>
|
<property name="font"></property>
|
||||||
<property name="gripper">0</property>
|
<property name="gripper">0</property>
|
||||||
<property name="hidden">0</property>
|
<property name="hidden">0</property>
|
||||||
<property name="id">wxID_ANY</property>
|
<property name="id">ID_EXPORT_BUTTON</property>
|
||||||
<property name="label">Export</property>
|
<property name="label">Export</property>
|
||||||
<property name="margins"></property>
|
<property name="margins"></property>
|
||||||
<property name="markup">0</property>
|
<property name="markup">0</property>
|
||||||
|
|
Loading…
Add table
Reference in a new issue