mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Prompt the user before closing dirty tabs
This commit is contained in:
parent
f1a54fd165
commit
e686937ce9
9 changed files with 28 additions and 9 deletions
4
TODO.md
4
TODO.md
|
@ -3,8 +3,8 @@
|
||||||
## Before releasing v0.1.0
|
## Before releasing v0.1.0
|
||||||
- [x] In BoardCanvas search for a workaround of the dynamic allocation of adata.buffer (on canvas resize)
|
- [x] In BoardCanvas search for a workaround of the dynamic allocation of adata.buffer (on canvas resize)
|
||||||
- [ ] Bind the chess game editor settings to EditorPrefs.hpp
|
- [ ] Bind the chess game editor settings to EditorPrefs.hpp
|
||||||
- [ ] Ask before closing MainWindow/Tabs if anything is not saved
|
- [x] Ask before closing MainWindow/Tabs if anything is not saved
|
||||||
- [ ] Disable the save button in GameTab after saving (and re-enable it on new changes)
|
- [x] Disable the save button in GameTab after saving (and re-enable it on new changes)
|
||||||
- [ ] Make PGNGameBase use GotoNextGame() instead of ParseNextGame() in the NextGame() method to improve performance
|
- [ ] Make PGNGameBase use GotoNextGame() instead of ParseNextGame() in the NextGame() method to improve performance
|
||||||
|
|
||||||
## Additional Features
|
## Additional Features
|
||||||
|
|
|
@ -64,12 +64,16 @@ MainWindow::MainWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::OnAuiNotebookPageCheck(wxAuiNotebookEvent& event){
|
void MainWindow::OnAuiNotebookPageCheck(wxAuiNotebookEvent& event){
|
||||||
// TODO: Ask the user before closing
|
|
||||||
//event.Veto();
|
|
||||||
int selection=event.GetSelection();
|
int selection=event.GetSelection();
|
||||||
TabInfos *t=dynamic_cast<TabInfos *>(notebook->GetPage(selection));
|
TabInfos *t=dynamic_cast<TabInfos *>(notebook->GetPage(selection));
|
||||||
if(t->is_dirty){
|
if(t->is_dirty){
|
||||||
wxLogDebug("Tab was dirty");
|
wxMessageDialog *dial = new wxMessageDialog(NULL,
|
||||||
|
wxT("This tab contains data that are not saved. Are you sure you want to close it?"), wxT("Information"),
|
||||||
|
wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
|
||||||
|
if(dial->ShowModal() == wxID_YES)
|
||||||
|
event.Allow();
|
||||||
|
else
|
||||||
|
event.Veto();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ BaseManageTab::BaseManageTab(wxFrame *parent, std::shared_ptr<GameBase> db, std:
|
||||||
TabBase_TabManage(parent), glm(glm), base(db), import_tab(import_tab), games_tab(games_tab)
|
TabBase_TabManage(parent), glm(glm), base(db), import_tab(import_tab), games_tab(games_tab)
|
||||||
{
|
{
|
||||||
RefreshInformations();
|
RefreshInformations();
|
||||||
|
has_pending_events=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseManageTab::RefreshInformations(){
|
void BaseManageTab::RefreshInformations(){
|
||||||
|
@ -22,6 +23,7 @@ void BaseManageTab::RefreshInformations(){
|
||||||
int nedited=games_tab->edited.size();
|
int nedited=games_tab->edited.size();
|
||||||
int ndeleted=games_tab->deleted.size()-nedited;
|
int ndeleted=games_tab->deleted.size()-nedited;
|
||||||
if((ngames+nselect+ndb+nedited+ndeleted) >0){
|
if((ngames+nselect+ndb+nedited+ndeleted) >0){
|
||||||
|
has_pending_events=true;
|
||||||
ADD_INFO("\n---------- Pending operations ----------");
|
ADD_INFO("\n---------- Pending operations ----------");
|
||||||
ADD_INFO("Imports:");
|
ADD_INFO("Imports:");
|
||||||
ADD_INFO(" -> "+std::to_string(ngames+nselect)+" game(s)");
|
ADD_INFO(" -> "+std::to_string(ngames+nselect)+" game(s)");
|
||||||
|
@ -29,6 +31,8 @@ void BaseManageTab::RefreshInformations(){
|
||||||
ADD_INFO("Others:");
|
ADD_INFO("Others:");
|
||||||
ADD_INFO(" -> "+std::to_string(nedited)+" edited game(s)");
|
ADD_INFO(" -> "+std::to_string(nedited)+" edited game(s)");
|
||||||
ADD_INFO(" -> "+std::to_string(ndeleted)+" deleted game(s)");
|
ADD_INFO(" -> "+std::to_string(ndeleted)+" deleted game(s)");
|
||||||
|
} else {
|
||||||
|
has_pending_events=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,12 @@ class BaseManageTab : public TabBase_TabManage {
|
||||||
BaseImportTab *import_tab;
|
BaseImportTab *import_tab;
|
||||||
BaseGameTab *games_tab;
|
BaseGameTab *games_tab;
|
||||||
|
|
||||||
|
bool has_pending_events;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BaseManageTab(wxFrame *parent, std::shared_ptr<GameBase> db,
|
BaseManageTab(wxFrame *parent, std::shared_ptr<GameBase> db,
|
||||||
std::shared_ptr<GameListManager> glm, BaseImportTab *import_tab, BaseGameTab *games_tab);
|
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);
|
||||||
|
bool HasPendingEvents(){return(has_pending_events);};
|
||||||
};
|
};
|
|
@ -25,8 +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){
|
Bind(REFRESH_MANAGE_TAB,[p=this](wxCommandEvent &e){
|
||||||
tab->RefreshInformations();
|
p->manage_tab->RefreshInformations();
|
||||||
|
p->is_dirty=p->manage_tab->HasPendingEvents(); // Refresh tab dirty flag
|
||||||
},wxID_ANY);
|
},wxID_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ EngineTab::EngineTab(wxWindow *parent, std::string name)
|
||||||
|
|
||||||
Bind(wxEVT_BUTTON, &EngineTab::OnSave, this, ENGINE_SAVE_CONF_BUTTON);
|
Bind(wxEVT_BUTTON, &EngineTab::OnSave, this, ENGINE_SAVE_CONF_BUTTON);
|
||||||
Bind(wxEVT_BUTTON, &EngineTab::OnDelete, this, ENGINE_DELETE_CONF_BUTTON);
|
Bind(wxEVT_BUTTON, &EngineTab::OnDelete, this, ENGINE_DELETE_CONF_BUTTON);
|
||||||
|
Bind(wxEVT_PG_CHANGED, [p=this](wxPropertyGridEvent& event){p->is_dirty=true;});
|
||||||
}
|
}
|
||||||
|
|
||||||
EngineTab::~EngineTab() {
|
EngineTab::~EngineTab() {
|
||||||
|
|
|
@ -11,6 +11,7 @@ GameTab::GameTab(wxFrame *parent, std::shared_ptr<Game> game)
|
||||||
// Panels
|
// Panels
|
||||||
game->BuildAndVerify();
|
game->BuildAndVerify();
|
||||||
board_panel = new GameTabLeftPanel((wxFrame *)splitter, game);
|
board_panel = new GameTabLeftPanel((wxFrame *)splitter, game);
|
||||||
|
board_panel->SetSaveToolEnable(false);
|
||||||
editor_panel = new GameTabRightPanel((wxFrame *)splitter, game);
|
editor_panel = new GameTabRightPanel((wxFrame *)splitter, game);
|
||||||
splitter->SplitVertically(board_panel, editor_panel);
|
splitter->SplitVertically(board_panel, editor_panel);
|
||||||
|
|
||||||
|
@ -59,6 +60,11 @@ void GameTab::OnGameChange(wxCommandEvent &event) {
|
||||||
board_panel->Notify();
|
board_panel->Notify();
|
||||||
RefreshTabTitle();
|
RefreshTabTitle();
|
||||||
}
|
}
|
||||||
|
// Update dirty flag
|
||||||
|
if(!is_linked){
|
||||||
|
is_dirty=true;
|
||||||
|
board_panel->SetSaveToolEnable(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameTab::RefreshTabTitle() {
|
void GameTab::RefreshTabTitle() {
|
||||||
|
|
|
@ -29,5 +29,5 @@ public:
|
||||||
std::shared_ptr<Game> GetGame() { return (std::shared_ptr<Game>(game)); }
|
std::shared_ptr<Game> GetGame() { return (std::shared_ptr<Game>(game)); }
|
||||||
std::shared_ptr<GameBase> GetBase() { return nullptr; };
|
std::shared_ptr<GameBase> GetBase() { return nullptr; };
|
||||||
void OnToolClick(wxCommandEvent &event);
|
void OnToolClick(wxCommandEvent &event);
|
||||||
void OnLink(){board_panel->DisableSaveTool();};
|
void OnLink(){board_panel->SetSaveToolEnable(false);};
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,5 +21,5 @@ public:
|
||||||
void OnGotoMove(wxCommandEvent &event);
|
void OnGotoMove(wxCommandEvent &event);
|
||||||
void OnRefreshBoard(wxCommandEvent &event);
|
void OnRefreshBoard(wxCommandEvent &event);
|
||||||
void ApplyPreferences();
|
void ApplyPreferences();
|
||||||
void DisableSaveTool(){game_toolbar->EnableTool(0,false);};
|
void SetSaveToolEnable(bool state){game_toolbar->EnableTool(0,state);};
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue