aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/base_tab/BaseGameTab.cpp95
-rw-r--r--src/base_tab/BaseGameTab.hpp15
-rw-r--r--src/base_tab/BaseTab.cpp28
-rw-r--r--src/base_tab/BaseTab.hpp8
-rw-r--r--src/base_tab/GameListManager.cpp15
-rw-r--r--src/base_tab/GameListManager.hpp16
-rw-r--r--src/base_tab/gamebase/GameBase.cpp2
-rw-r--r--src/gui.cpp4
-rw-r--r--src/gui.h13
-rw-r--r--src/ochess.hpp2
-rw-r--r--tools/wxFrameBuilder.fbp8
11 files changed, 87 insertions, 119 deletions
diff --git a/src/base_tab/BaseGameTab.cpp b/src/base_tab/BaseGameTab.cpp
index ecf4935..cc2cf3d 100644
--- a/src/base_tab/BaseGameTab.cpp
+++ b/src/base_tab/BaseGameTab.cpp
@@ -1,18 +1,13 @@
#include "BaseGameTab.hpp"
#include <wx/filename.h>
-wxDEFINE_EVENT(OPEN_GAME_EVENT, wxCommandEvent);
-
-
-BaseGameTab::BaseGameTab(wxFrame *parent, std::shared_ptr<GameBase> base, TabInfos *main_tab)
- : TabBase_TabGames(parent), main_tab(main_tab),base(base) {
+BaseGameTab::BaseGameTab(wxFrame *parent, std::shared_ptr<GameBase> base)
+ : TabBase_TabGames(parent),base(base) {
glm=std::make_shared<GameListManager>(game_list);
Reset(base);
-
this->Bind(wxEVT_BUTTON, &BaseGameTab::OnDelete, this, ID_DELETE_BUTTON);
- this->Bind(wxEVT_LIST_ITEM_ACTIVATED, &BaseGameTab::OnOpenGame, this, wxID_ANY);
this->Bind(wxEVT_BUTTON, &BaseGameTab::OnApplyFilter, this, ID_APPLY_FILTER_BUTTON);
this->Bind(wxEVT_TEXT_ENTER, &BaseGameTab::OnApplyFilter, this, ID_SEARCH_TERMS);
@@ -28,15 +23,6 @@ void BaseGameTab::OnApplyFilter(wxCommandEvent &event){
}
}
-void BaseGameTab::OnImport(wxCommandEvent &event) {
- // AppendGameDialog *dia = new AppendGameDialog(this, base);
- // dia->ShowModal();
- // glm->Clear();
- // deleted.clear();
- // edited.clear();
- // LoadFile();
-}
-
void BaseGameTab::OnDelete(wxCommandEvent &event) {
for(auto i: glm->GetSelectedItems()){
deleted.push_back(glm->GetItemGameId(i));
@@ -44,56 +30,25 @@ void BaseGameTab::OnDelete(wxCommandEvent &event) {
}
}
-void BaseGameTab::OnSave(wxCommandEvent &event) {
- // std::vector<std::shared_ptr<GameBase>> new_games_bases;
-
- // // Build edited games vector
- // std::vector<std::shared_ptr<Game>> edited_games;
- // for (auto itr = edited.begin(); itr != edited.end(); itr++) {
- // edited_games.push_back(itr->second);
- // }
-
- // // Combine new_games and edited games
- // std::vector<std::shared_ptr<Game>> new_games;
- // new_games.insert(
- // new_games.end(), edited_games.begin(),
- // edited_games.end()); // Add edited game (since they are also deleted)
- // base->Save(deleted, new_games_bases, new_games);
-
- // // Close all opened games in this database
- // wxCommandEvent closeLinkedTabEvent(CLOSE_LINKED_TAB, GetId());
- // closeLinkedTabEvent.SetClientData(main_tab);
- // ProcessEvent(closeLinkedTabEvent);
-
- // glm->Clear();
- // edited.clear();
- // deleted.clear();
- // LoadFile();
-}
-
-void BaseGameTab::OnOpenGame(wxListEvent &event) {
- long id = std::stoi(event.GetItem().GetText().ToStdString());
- std::shared_ptr<Game> *g = new std::shared_ptr<Game>(base->GetGame(id));
- wxLogDebug("kjkj");
-
- if (g != NULL) {
- if(edited.find(id) != edited.end()){
- // TODO: Focus on the game tab and if close reopen it
- wxLogDebug("Already opened!");
- }
- else {
- wxLogDebug("Open game");
- edited[id]=*g;
- deleted.push_back(id);
- glm->MarkItemAsOpen(event.GetIndex());
- wxCommandEvent openGameEvent(OPEN_GAME_EVENT, GetId());
- openGameEvent.SetEventObject(this);
- openGameEvent.SetClientData(g);
- ProcessEvent(openGameEvent);
+std::shared_ptr<Game> BaseGameTab::OpenGame(long gameid, long item) {
+ if(edited.find(gameid) != edited.end()){
+ // TODO: Focus on the game tab and if close reopen it
+ wxLogDebug("Already opened!");
+ }
+ else {
+ std::shared_ptr<Game> g = base->GetGame(gameid);
+ if(g){
+ edited[gameid]=g;
+ deleted.push_back(gameid);
+ glm->MarkItemAsOpen(item);
+ return g;
}
}
+
+ return nullptr;
}
+
std::vector<std::shared_ptr<Game>> BaseGameTab::GetEditedGames(){
std::vector<std::shared_ptr<Game>> games;
for(auto it = edited.begin(); it != edited.end(); it++){
@@ -123,21 +78,5 @@ void BaseGameTab::Reset(std::shared_ptr<GameBase> base){
}
}
-void BaseGameTab::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->Export(this->base);
- // delete base;
- // }
- // }
-}
diff --git a/src/base_tab/BaseGameTab.hpp b/src/base_tab/BaseGameTab.hpp
index b634148..4fcf3fd 100644
--- a/src/base_tab/BaseGameTab.hpp
+++ b/src/base_tab/BaseGameTab.hpp
@@ -3,30 +3,25 @@
#include "gamebase/PGNGameBase.hpp"
#include "GameListManager.hpp"
-// Foreign events
-wxDECLARE_EVENT(OPEN_GAME_EVENT, wxCommandEvent);
-wxDECLARE_EVENT(CLOSE_LINKED_TAB, wxCommandEvent);
-
class BaseGameTab : public TabBase_TabGames {
std::shared_ptr<GameBase> base;
+ /// @brief Old deleted games id
std::vector<std::uint32_t> deleted;
+ /// @brief Old edited game id+object
std::unordered_map<long, std::shared_ptr<Game>> edited;
- TabInfos *main_tab;
public:
std::shared_ptr<GameListManager> glm;
- BaseGameTab(wxFrame *parent, std::shared_ptr<GameBase> base, TabInfos *main_tab);
+ BaseGameTab(wxFrame *parent, std::shared_ptr<GameBase> base);
void Reset(std::shared_ptr<GameBase> base);
void OnDelete(wxCommandEvent &event);
- void OnSave(wxCommandEvent &event);
- void OnExport(wxCommandEvent &event);
- void OnOpenGame(wxListEvent &event);
- void OnImport(wxCommandEvent &event);
void OnApplyFilter(wxCommandEvent &event);
std::vector<std::shared_ptr<Game>> GetEditedGames();
std::vector<std::uint32_t> GetDeletedGameIds() {return(deleted);};
+ std::shared_ptr<Game> OpenGame(long gameid, long item);
+
std::shared_ptr<Game> GetGame() { return (std::shared_ptr<Game>(NULL)); }
std::shared_ptr<GameBase> GetBase() { return (std::shared_ptr<GameBase>(base)); };
}; \ No newline at end of file
diff --git a/src/base_tab/BaseTab.cpp b/src/base_tab/BaseTab.cpp
index 6866da1..fada2b2 100644
--- a/src/base_tab/BaseTab.cpp
+++ b/src/base_tab/BaseTab.cpp
@@ -8,8 +8,7 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file)
base=OpenDatabase(base_file);
// Games tab
- games_tab=new BaseGameTab((wxFrame *)notebook,base,this);
- glm=games_tab->glm;
+ games_tab=new BaseGameTab((wxFrame *)notebook,base);
notebook->AddPage(games_tab, "Games list",true); // true for selecting the tab
// Import tab
import_tab=new BaseImportTab((wxFrame *)notebook,base,this);
@@ -22,21 +21,22 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file)
Refresh();
// Bindings
- this->Bind(OPEN_GAME_EVENT, &BaseTab::OnOpenGame, this, wxID_ANY);
this->Bind(wxEVT_BUTTON, &BaseTab::OnSave, this, ID_SAVE_BUTTON);
+ this->Bind(wxEVT_LIST_ITEM_ACTIVATED, &BaseTab::OnOpenGame, this, ID_TABGAMES_GAME_LIST);
}
-
-void BaseTab::OnOpenGame(wxCommandEvent &event){
- std::shared_ptr<Game> *g = (std::shared_ptr<Game>*)event.GetClientData();
- this->game=*g;
-
- // Ask MainFrame to open a new game
- // TODO: Simplify that is, use wxWidget main app to do it
- wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId());
- newGameEvent.SetEventObject(this);
- newGameEvent.SetClientData((TabInfos*)this);
- ProcessEvent(newGameEvent);
+void BaseTab::OnOpenGame(wxListEvent &event){
+ long gameid=std::stol(event.GetItem().GetText().ToStdString());
+ std::shared_ptr<Game> g = games_tab->OpenGame(gameid,event.GetIndex());
+ if(g){
+ game=g;
+ // Ask MainFrame to open a new game
+ // TODO: Simplify that is, use wxWidget main app to do it
+ wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId());
+ newGameEvent.SetEventObject(this);
+ newGameEvent.SetClientData((TabInfos*)this);
+ ProcessEvent(newGameEvent);
+ }
}
void BaseTab::Refresh(){
diff --git a/src/base_tab/BaseTab.hpp b/src/base_tab/BaseTab.hpp
index 51b8fa4..71e7cec 100644
--- a/src/base_tab/BaseTab.hpp
+++ b/src/base_tab/BaseTab.hpp
@@ -6,7 +6,9 @@
#include "BaseImportTab.hpp"
#include "BaseManageTab.hpp"
+// Foreign events
wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
+wxDECLARE_EVENT(CLOSE_LINKED_TAB, wxCommandEvent);
class BaseTab : public TabBase, public TabInfos {
/// @brief The opened database
@@ -19,10 +21,12 @@ class BaseTab : public TabBase, public TabInfos {
BaseImportTab *import_tab;
BaseManageTab *manage_tab;
+ /// @brief Database file path
std::string base_file;
- std::shared_ptr<GameListManager> glm;
- void OnOpenGame(wxCommandEvent &event);
+ /// @brief Listen events from BaseImportTab
+ void OnOpenGame(wxListEvent &event);
+ /// @brief Listen events from BaseManageTab
void OnSave(wxCommandEvent &event);
public:
diff --git a/src/base_tab/GameListManager.cpp b/src/base_tab/GameListManager.cpp
index 3da6dc2..971e486 100644
--- a/src/base_tab/GameListManager.cpp
+++ b/src/base_tab/GameListManager.cpp
@@ -74,6 +74,21 @@ void GameListManager::SortBy(short col){
case 1:
std::sort(rows.begin(),rows.end(), [&](RType a, RType b){return(a.White < b.White);});
break;
+ case 2:
+ std::sort(rows.begin(),rows.end(), [&](RType a, RType b){return(a.Black < b.Black);});
+ break;
+ case 3:
+ std::sort(rows.begin(),rows.end(), [&](RType a, RType b){return(a.Event < b.Event);});
+ break;
+ case 4:
+ std::sort(rows.begin(),rows.end(), [&](RType a, RType b){return(a.Round < b.Round);});
+ break;
+ case 5:
+ std::sort(rows.begin(),rows.end(), [&](RType a, RType b){return(a.Result < b.Result);});
+ break;
+ case 6:
+ std::sort(rows.begin(),rows.end(), [&](RType a, RType b){return(a.Eco < b.Eco);});
+ break;
default:
std::sort(rows.begin(),rows.end(), [&](RType a, RType b){return(a.id < b.id);});
}
diff --git a/src/base_tab/GameListManager.hpp b/src/base_tab/GameListManager.hpp
index cebd5d3..3499aac 100644
--- a/src/base_tab/GameListManager.hpp
+++ b/src/base_tab/GameListManager.hpp
@@ -10,8 +10,10 @@
#define BG_IMPORT(INDEX) game_list->SetItemBackgroundColour(INDEX, *wxBLUE)
#define DISPLAY_ALL_ROWS() {for(int i=0;i<rows.size();i++){DisplayRow(i);}}
+///@brief Column content type
typedef std::string CType;
+///@brief Row item content
typedef struct Item {
long id;
CType White;
@@ -22,6 +24,10 @@ typedef struct Item {
CType Eco;
} RType;
+/**
+ * @brief A manager for wxListCtrl that display games
+ *
+ */
class GameListManager {
long game_counter;
wxListCtrl *game_list;
@@ -30,17 +36,25 @@ class GameListManager {
void DisplayRow(long id);
void ClearDisplayedRow();
public:
+ /// @brief Accessible outside (DO NOT MODIFY FROM OUTSIDE)
std::vector<RType> rows;
GameListManager(wxListCtrl *game_list);
+ /// @brief Add a game to the list
long AddGame(CType White,CType Black,CType Event,CType Round, CType Result, CType Eco);
- void Clear();
void MarkItemAsOpen(long item);
void MarkItemAsDeleted(long item);
void MarkItemAsImported(long item);
+ /// @brief Clear the state of the GameListManager
+ void Clear();
+ /// @brief Return the id of the selected items
std::vector<long> GetSelectedItems();
+ /// @brief Get the game id from the item id
long GetItemGameId(long item);
+ /// @brief Filter the rows given terms
void Filter(std::string terms);
+ /// @brief Remove all filters
void ClearFilter();
+ /// @brief Sort items by the given column
void SortBy(short col);
}; \ No newline at end of file
diff --git a/src/base_tab/gamebase/GameBase.cpp b/src/base_tab/gamebase/GameBase.cpp
index 4c7c1a3..a4c51ce 100644
--- a/src/base_tab/gamebase/GameBase.cpp
+++ b/src/base_tab/gamebase/GameBase.cpp
@@ -4,7 +4,7 @@
std::shared_ptr<GameBase> OpenDatabase(const std::string &dbpath, bool createIfNotExist){
wxFileName file(dbpath);
wxString ext = file.GetExt().Lower();
- bool create=createIfNotExist && !file.Exists();
+ bool create=(createIfNotExist && !file.Exists());
if (ext == "pgn") {
if(create)
PGNGameBase::CreateDatabaseFile(dbpath);
diff --git a/src/gui.cpp b/src/gui.cpp
index 1077a2e..ed6941e 100644
--- a/src/gui.cpp
+++ b/src/gui.cpp
@@ -539,7 +539,7 @@ TabBase_TabGames::TabBase_TabGames( wxWindow* parent, wxWindowID id, const wxPoi
main_sizer->Add( top_sizer, 0, wxEXPAND, 5 );
- game_list = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxSize( -1,-1 ), wxLC_REPORT );
+ game_list = new wxListCtrl( this, ID_TABGAMES_GAME_LIST, wxDefaultPosition, wxSize( -1,-1 ), wxLC_REPORT );
main_sizer->Add( game_list, 1, wxALL|wxEXPAND, 5 );
wxBoxSizer* bottom_sizer;
@@ -616,7 +616,7 @@ TabBase_TabImport::TabBase_TabImport( wxWindow* parent, wxWindowID id, const wxP
import_from_db_button = new wxButton( this, ID_IMPORT_SELECTION, wxT("Import Selection"), wxDefaultPosition, wxDefaultSize, 0 );
databases_sizer->Add( import_from_db_button, 0, wxALL|wxEXPAND, 5 );
- m_button16 = new wxButton( this, ID_IMPORT_DB, wxT("Import all games"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_button16 = new wxButton( this, ID_IMPORT_DB, wxT("Import entire database"), wxDefaultPosition, wxDefaultSize, 0 );
databases_sizer->Add( m_button16, 0, wxALL|wxEXPAND, 5 );
diff --git a/src/gui.h b/src/gui.h
index 99405fc..8ea4f21 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -57,12 +57,13 @@
#define LIVE_ANALYSIS_GAME_BUTTON 1012
#define ID_SEARCH_TERMS 1013
#define ID_APPLY_FILTER_BUTTON 1014
-#define ID_DELETE_BUTTON 1015
-#define ID_IMPORT_GAME_BUTTON 1016
-#define ID_LOAD_BUTTON 1017
-#define ID_IMPORT_SELECTION 1018
-#define ID_IMPORT_DB 1019
-#define ID_SAVE_BUTTON 1020
+#define ID_TABGAMES_GAME_LIST 1015
+#define ID_DELETE_BUTTON 1016
+#define ID_IMPORT_GAME_BUTTON 1017
+#define ID_LOAD_BUTTON 1018
+#define ID_IMPORT_SELECTION 1019
+#define ID_IMPORT_DB 1020
+#define ID_SAVE_BUTTON 1021
///////////////////////////////////////////////////////////////////////////////
/// Class MainFrame
diff --git a/src/ochess.hpp b/src/ochess.hpp
index d920fa4..e7c2508 100644
--- a/src/ochess.hpp
+++ b/src/ochess.hpp
@@ -53,7 +53,7 @@ public:
long linked_id;
/// @brief Set to true if this tab is attach to another one (c.f linked_id)
bool is_linked;
- TabInfos(Type type_) : type(type_), id(tab_count), is_linked(false) { tab_count++; wxLogDebug("Tabid=%d",(int)id); }
+ TabInfos(Type type_) : type(type_), id(tab_count), is_linked(false) { tab_count++; }
void Link(TabInfos *tab);
virtual void Refresh(){};
virtual void ApplyPreferences() {};
diff --git a/tools/wxFrameBuilder.fbp b/tools/wxFrameBuilder.fbp
index 62c5f90..5b1ae05 100644
--- a/tools/wxFrameBuilder.fbp
+++ b/tools/wxFrameBuilder.fbp
@@ -3622,7 +3622,7 @@
</object>
</object>
</object>
- <object class="Panel" expanded="0">
+ <object class="Panel" expanded="1">
<property name="aui_managed">0</property>
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
<property name="bg"></property>
@@ -3645,7 +3645,7 @@
<property name="window_extra_style"></property>
<property name="window_name"></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="name">main_sizer</property>
<property name="orient">wxVERTICAL</property>
@@ -5403,7 +5403,7 @@
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
- <property name="id">wxID_ANY</property>
+ <property name="id">ID_TABGAMES_GAME_LIST</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
@@ -6272,7 +6272,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">ID_IMPORT_DB</property>
- <property name="label">Import all games</property>
+ <property name="label">Import entire database</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>