mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Improve database tab
This commit is contained in:
parent
32fdf9272e
commit
cb6fbd18f3
9 changed files with 76 additions and 15 deletions
|
@ -1,6 +1,14 @@
|
||||||
#include "BaseGameTab.hpp"
|
#include "BaseGameTab.hpp"
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
|
||||||
|
#define NOTIFY_MANAGE_TAB() \
|
||||||
|
{ \
|
||||||
|
wxCommandEvent e(REFRESH_MANAGE_TAB,GetId()); \
|
||||||
|
ProcessEvent(e); \
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDECLARE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent);
|
||||||
|
|
||||||
BaseGameTab::BaseGameTab(wxFrame *parent, std::shared_ptr<GameBase> base)
|
BaseGameTab::BaseGameTab(wxFrame *parent, std::shared_ptr<GameBase> base)
|
||||||
: TabBase_TabGames(parent),base(base) {
|
: TabBase_TabGames(parent),base(base) {
|
||||||
|
|
||||||
|
@ -31,6 +39,7 @@ void BaseGameTab::OnDelete(wxCommandEvent &event) {
|
||||||
deleted.push_back(glm->GetItemGameId(i));
|
deleted.push_back(glm->GetItemGameId(i));
|
||||||
glm->MarkItemAsDeleted(i);
|
glm->MarkItemAsDeleted(i);
|
||||||
}
|
}
|
||||||
|
NOTIFY_MANAGE_TAB();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Game> BaseGameTab::OpenGame(long gameid, long item) {
|
std::shared_ptr<Game> BaseGameTab::OpenGame(long gameid, long item) {
|
||||||
|
@ -44,6 +53,7 @@ std::shared_ptr<Game> BaseGameTab::OpenGame(long gameid, long item) {
|
||||||
edited[gameid]=g;
|
edited[gameid]=g;
|
||||||
deleted.push_back(gameid);
|
deleted.push_back(gameid);
|
||||||
glm->MarkItemAsOpen(item);
|
glm->MarkItemAsOpen(item);
|
||||||
|
NOTIFY_MANAGE_TAB();
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,6 +89,7 @@ void BaseGameTab::Reset(std::shared_ptr<GameBase> base){
|
||||||
base->GetTag("ECO"));
|
base->GetTag("ECO"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NOTIFY_MANAGE_TAB();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include "gamebase/GameBase.hpp"
|
#include "gamebase/GameBase.hpp"
|
||||||
#include "gamebase/PGNGameBase.hpp"
|
#include "gamebase/PGNGameBase.hpp"
|
||||||
#include "GameListManager.hpp"
|
#include "GameListManager.hpp"
|
||||||
|
|
||||||
class BaseGameTab : public TabBase_TabGames {
|
class BaseGameTab : public TabBase_TabGames {
|
||||||
std::shared_ptr<GameBase> base;
|
std::shared_ptr<GameBase> base;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::shared_ptr<GameListManager> glm;
|
||||||
/// @brief Old deleted games id
|
/// @brief Old deleted games id
|
||||||
std::vector<std::uint32_t> deleted;
|
std::vector<std::uint32_t> deleted;
|
||||||
/// @brief Old edited game id+object
|
/// @brief Old edited game id+object
|
||||||
std::unordered_map<long, std::shared_ptr<Game>> edited;
|
std::unordered_map<long, std::shared_ptr<Game>> edited;
|
||||||
|
|
||||||
public:
|
|
||||||
std::shared_ptr<GameListManager> glm;
|
|
||||||
|
|
||||||
BaseGameTab(wxFrame *parent, std::shared_ptr<GameBase> base);
|
BaseGameTab(wxFrame *parent, std::shared_ptr<GameBase> base);
|
||||||
|
|
||||||
void Reset(std::shared_ptr<GameBase> base);
|
void Reset(std::shared_ptr<GameBase> base);
|
||||||
|
|
|
@ -2,9 +2,22 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "gamebase/GameBase.hpp"
|
#include "gamebase/GameBase.hpp"
|
||||||
|
|
||||||
|
#define NOTIFY_MANAGE_TAB() \
|
||||||
|
{ \
|
||||||
|
wxCommandEvent e(REFRESH_MANAGE_TAB,GetId()); \
|
||||||
|
ProcessEvent(e); \
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDECLARE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent);
|
||||||
|
|
||||||
BaseImportTab::BaseImportTab(wxFrame *parent, std::shared_ptr<GameBase> db, TabInfos *main_tab):
|
BaseImportTab::BaseImportTab(wxFrame *parent, std::shared_ptr<GameBase> db, TabInfos *main_tab):
|
||||||
TabBase_TabImport(parent), main_tab(main_tab), base(db)
|
TabBase_TabImport(parent), main_tab(main_tab), base(db)
|
||||||
{
|
{
|
||||||
|
// Init counters
|
||||||
|
import_ndb=0;
|
||||||
|
import_ngames=0;
|
||||||
|
import_nselect=0;
|
||||||
|
|
||||||
glm=std::make_shared<GameListManager>(game_list);
|
glm=std::make_shared<GameListManager>(game_list);
|
||||||
RefreshImportLists();
|
RefreshImportLists();
|
||||||
RefreshPendingImports();
|
RefreshPendingImports();
|
||||||
|
@ -27,17 +40,19 @@ void BaseImportTab::OnImportDatabase(wxCommandEvent &event){
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseImportTab::RefreshPendingImports(){
|
void BaseImportTab::RefreshPendingImports(){
|
||||||
int ngames=games_to_import.size();
|
import_ndb=databases_to_import.size();
|
||||||
int ndb=databases_to_import.size();
|
import_ngames=games_to_import.size();
|
||||||
int nbselect=0;
|
import_nselect=0;
|
||||||
for (auto it = selected_games_to_import.begin(); it != selected_games_to_import.end(); it++){
|
for (auto it = selected_games_to_import.begin(); it != selected_games_to_import.end(); it++){
|
||||||
nbselect+=it->second.size();
|
import_nselect+=it->second.size();
|
||||||
}
|
}
|
||||||
pending_imports->Clear();
|
pending_imports->Clear();
|
||||||
if(ngames+ndb+nbselect>0){
|
if(import_ndb+import_ngames+import_nselect>0){
|
||||||
pending_imports->AppendText(" Pending imports: "+std::to_string(ngames+nbselect)+" games and "+std::to_string(ndb)+" databases");
|
pending_imports->AppendText(" Pending imports: "+std::to_string(import_ngames+import_nselect)+" games and "+std::to_string(import_ndb)+" databases");
|
||||||
}else
|
}else
|
||||||
pending_imports->SetHint("No pending imports");
|
pending_imports->SetHint("No pending imports");
|
||||||
|
|
||||||
|
NOTIFY_MANAGE_TAB();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseImportTab::RefreshImportLists(){
|
void BaseImportTab::RefreshImportLists(){
|
||||||
|
@ -116,6 +131,7 @@ void BaseImportTab::Reset(std::shared_ptr<GameBase> base){
|
||||||
this->selected_games_to_import.clear();
|
this->selected_games_to_import.clear();
|
||||||
glm->Clear();
|
glm->Clear();
|
||||||
RefreshPendingImports();
|
RefreshPendingImports();
|
||||||
|
NOTIFY_MANAGE_TAB();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Game>> BaseImportTab::GetGameToImport(){
|
std::vector<std::shared_ptr<Game>> BaseImportTab::GetGameToImport(){
|
||||||
|
|
|
@ -18,6 +18,7 @@ class BaseImportTab : public TabBase_TabImport {
|
||||||
|
|
||||||
void RefreshPendingImports();
|
void RefreshPendingImports();
|
||||||
public:
|
public:
|
||||||
|
int import_ndb, import_ngames,import_nselect;
|
||||||
BaseImportTab(wxFrame *parent, std::shared_ptr<GameBase> db, TabInfos *main_tab);
|
BaseImportTab(wxFrame *parent, std::shared_ptr<GameBase> db, TabInfos *main_tab);
|
||||||
void RefreshImportLists();
|
void RefreshImportLists();
|
||||||
void OnLoad(wxCommandEvent &event);
|
void OnLoad(wxCommandEvent &event);
|
||||||
|
|
|
@ -2,9 +2,8 @@
|
||||||
|
|
||||||
#define ADD_INFO(text) {informations->WriteText(text);informations->WriteText("\n");}
|
#define ADD_INFO(text) {informations->WriteText(text);informations->WriteText("\n");}
|
||||||
|
|
||||||
|
BaseManageTab::BaseManageTab(wxFrame *parent, std::shared_ptr<GameBase> db, std::shared_ptr<GameListManager> glm, BaseImportTab *import_tab,BaseGameTab *games_tab):
|
||||||
BaseManageTab::BaseManageTab(wxFrame *parent, std::shared_ptr<GameBase> db, std::shared_ptr<GameListManager> glm):
|
TabBase_TabManage(parent), glm(glm), base(db), import_tab(import_tab), games_tab(games_tab)
|
||||||
TabBase_TabManage(parent), glm(glm), base(db)
|
|
||||||
{
|
{
|
||||||
RefreshInformations();
|
RefreshInformations();
|
||||||
}
|
}
|
||||||
|
@ -17,6 +16,20 @@ void BaseManageTab::RefreshInformations(){
|
||||||
ADD_INFO("Last Modified: "+base_path.GetModificationTime().Format());
|
ADD_INFO("Last Modified: "+base_path.GetModificationTime().Format());
|
||||||
ADD_INFO("Database Format: "+base->GetFormat());
|
ADD_INFO("Database Format: "+base->GetFormat());
|
||||||
ADD_INFO("Total Number of Games: "+std::to_string(glm->rows.size()));
|
ADD_INFO("Total Number of Games: "+std::to_string(glm->rows.size()));
|
||||||
|
int ngames=import_tab->import_ngames;
|
||||||
|
int nselect=import_tab->import_nselect;
|
||||||
|
int ndb=import_tab->import_ndb;
|
||||||
|
int nedited=games_tab->edited.size();
|
||||||
|
int ndeleted=games_tab->deleted.size()-nedited;
|
||||||
|
if((ngames+nselect+ndb+nedited+ndeleted) >0){
|
||||||
|
ADD_INFO("\n---------- Pending operations ----------");
|
||||||
|
ADD_INFO("Imports:");
|
||||||
|
ADD_INFO(" -> "+std::to_string(ngames+nselect)+" game(s)");
|
||||||
|
ADD_INFO(" -> "+std::to_string(ndb)+ " database(s)");
|
||||||
|
ADD_INFO("Others:");
|
||||||
|
ADD_INFO(" -> "+std::to_string(nedited)+" edited game(s)");
|
||||||
|
ADD_INFO(" -> "+std::to_string(ndeleted)+" deleted game(s)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseManageTab::Reset(std::shared_ptr<GameBase> db) {
|
void BaseManageTab::Reset(std::shared_ptr<GameBase> db) {
|
||||||
|
|
|
@ -1,15 +1,22 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include "ochess.hpp"
|
#include "ochess.hpp"
|
||||||
#include "GameListManager.hpp"
|
#include "GameListManager.hpp"
|
||||||
#include "gamebase/GameBase.hpp"
|
#include "gamebase/GameBase.hpp"
|
||||||
|
#include "BaseImportTab.hpp"
|
||||||
|
#include "BaseGameTab.hpp"
|
||||||
|
|
||||||
class BaseManageTab : public TabBase_TabManage {
|
class BaseManageTab : public TabBase_TabManage {
|
||||||
|
|
||||||
/// @brief Never free the following pointer in that class
|
/// @brief Never free the following pointers in that class
|
||||||
std::shared_ptr<GameListManager> glm;
|
std::shared_ptr<GameListManager> glm;
|
||||||
std::shared_ptr<GameBase> base;
|
std::shared_ptr<GameBase> base;
|
||||||
|
BaseImportTab *import_tab;
|
||||||
|
BaseGameTab *games_tab;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BaseManageTab(wxFrame *parent, std::shared_ptr<GameBase> db, std::shared_ptr<GameListManager> glm);
|
BaseManageTab(wxFrame *parent, std::shared_ptr<GameBase> db,
|
||||||
|
std::shared_ptr<GameListManager> glm, BaseImportTab *import_tab, BaseGameTab *games_tab);
|
||||||
void RefreshInformations();
|
void RefreshInformations();
|
||||||
void Reset(std::shared_ptr<GameBase> db);
|
void Reset(std::shared_ptr<GameBase> db);
|
||||||
};
|
};
|
|
@ -1,6 +1,8 @@
|
||||||
#include "BaseTab.hpp"
|
#include "BaseTab.hpp"
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
|
||||||
|
wxDEFINE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent);
|
||||||
|
|
||||||
BaseTab::BaseTab(wxFrame *parent, std::string base_file)
|
BaseTab::BaseTab(wxFrame *parent, std::string base_file)
|
||||||
: TabBase(parent), TabInfos(TabInfos::BASE), base_file(base_file){
|
: TabBase(parent), TabInfos(TabInfos::BASE), base_file(base_file){
|
||||||
|
|
||||||
|
@ -14,7 +16,7 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file)
|
||||||
import_tab=new BaseImportTab((wxFrame *)notebook,base,this);
|
import_tab=new BaseImportTab((wxFrame *)notebook,base,this);
|
||||||
notebook->AddPage(import_tab, "Import games");
|
notebook->AddPage(import_tab, "Import games");
|
||||||
// Manage tab
|
// Manage tab
|
||||||
manage_tab=new BaseManageTab((wxFrame *)notebook, base, games_tab->glm);
|
manage_tab=new BaseManageTab((wxFrame *)notebook, base, games_tab->glm,import_tab,games_tab);
|
||||||
notebook->AddPage(manage_tab, "Manage database");
|
notebook->AddPage(manage_tab, "Manage database");
|
||||||
|
|
||||||
// Refresh dynamic elements of the database (tab title, available db for import etc.)
|
// Refresh dynamic elements of the database (tab title, available db for import etc.)
|
||||||
|
@ -23,6 +25,9 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file)
|
||||||
// Bindings
|
// Bindings
|
||||||
this->Bind(wxEVT_BUTTON, &BaseTab::OnSave, this, ID_SAVE_BUTTON);
|
this->Bind(wxEVT_BUTTON, &BaseTab::OnSave, this, ID_SAVE_BUTTON);
|
||||||
this->Bind(wxEVT_LIST_ITEM_ACTIVATED, &BaseTab::OnOpenGame, this, ID_TABGAMES_GAME_LIST);
|
this->Bind(wxEVT_LIST_ITEM_ACTIVATED, &BaseTab::OnOpenGame, this, ID_TABGAMES_GAME_LIST);
|
||||||
|
Bind(REFRESH_MANAGE_TAB,[tab=manage_tab](wxCommandEvent &e){
|
||||||
|
tab->RefreshInformations();
|
||||||
|
},wxID_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTab::OnOpenGame(wxListEvent &event){
|
void BaseTab::OnOpenGame(wxListEvent &event){
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
|
wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
|
||||||
wxDECLARE_EVENT(CLOSE_LINKED_TAB, wxCommandEvent);
|
wxDECLARE_EVENT(CLOSE_LINKED_TAB, wxCommandEvent);
|
||||||
|
|
||||||
|
// Local events
|
||||||
|
wxDECLARE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent);
|
||||||
|
|
||||||
class BaseTab : public TabBase, public TabInfos {
|
class BaseTab : public TabBase, public TabInfos {
|
||||||
/// @brief The opened database
|
/// @brief The opened database
|
||||||
std::shared_ptr<GameBase> base;
|
std::shared_ptr<GameBase> base;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include "GameBase.hpp"
|
#include "GameBase.hpp"
|
||||||
#include "pgnp.hpp"
|
#include "pgnp.hpp"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue