mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-06 01:56:28 +02:00
Improve tab management
This commit is contained in:
parent
d298c59206
commit
1293b59ed5
6 changed files with 31 additions and 30 deletions
|
@ -73,8 +73,19 @@ void MainWindow::OnCloseTabEvent(wxCommandEvent &event) {
|
|||
}
|
||||
|
||||
void MainWindow::OnCloseTabLinkedTo(wxCommandEvent &event){
|
||||
TabInfos *infos=(TabInfos*)event.GetClientData();
|
||||
CloseTabLinkedTo(infos->id);
|
||||
TabInfos *infosEvent=(TabInfos*)event.GetClientData();
|
||||
// Now close all tabs in the notebook related to the one in the event
|
||||
int i=0;
|
||||
while(i<notebook->GetPageCount()){
|
||||
wxWindow *page=notebook->GetPage(i);
|
||||
TabInfos* infos=(TabInfos*)page->GetClientData();
|
||||
if(infos->is_linked && infos->linked_id==infosEvent->id){
|
||||
notebook->DeletePage(i); // Remove page
|
||||
i=0; // Restart to page 0 since notebook updated (we just remove one page)
|
||||
}
|
||||
else
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::OnMenuItemClick(wxCommandEvent &event) {
|
||||
|
@ -104,7 +115,6 @@ void MainWindow::OnMenuItemClick(wxCommandEvent &event) {
|
|||
} else if (id == 5) {
|
||||
OpenFile();
|
||||
} else if (id == 6) {
|
||||
CloseTabLinkedTo(1);
|
||||
NewEngine();
|
||||
}
|
||||
}
|
||||
|
@ -179,20 +189,6 @@ void MainWindow::OnClose(wxCloseEvent &e) {
|
|||
e.Skip();
|
||||
}
|
||||
|
||||
void MainWindow::CloseTabLinkedTo(long id){
|
||||
int i=0;
|
||||
while(i<notebook->GetPageCount()){
|
||||
wxWindow *page=notebook->GetPage(i);
|
||||
TabInfos* infos=(TabInfos*)page->GetClientData();
|
||||
if(infos->is_linked && infos->linked_id==id){
|
||||
notebook->DeletePage(i);
|
||||
i=0; // Restart to page 0 since notebook updated
|
||||
}
|
||||
else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::OpenFile() {
|
||||
wxFileDialog openFileDialog(this, _("Open file"), "", "",
|
||||
|
|
|
@ -32,7 +32,6 @@ class MainWindow : public MainFrame {
|
|||
void OnMenuItemClick(wxCommandEvent &event);
|
||||
void OnCloseTabLinkedTo(wxCommandEvent &event);
|
||||
void AddPage(wxWindow* window, TabInfos* infos);
|
||||
void CloseTabLinkedTo(long id);
|
||||
public:
|
||||
MainWindow();
|
||||
void ApplyPreferences();
|
||||
|
|
|
@ -70,7 +70,7 @@ void BaseGameTab::OnSave(wxCommandEvent &event) {
|
|||
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
|
||||
// Close all opened games in this database
|
||||
wxCommandEvent closeLinkedTabEvent(CLOSE_LINKED_TAB, GetId());
|
||||
closeLinkedTabEvent.SetClientData(main_tab);
|
||||
ProcessEvent(closeLinkedTabEvent);
|
||||
|
@ -82,17 +82,23 @@ void BaseGameTab::OnSave(wxCommandEvent &event) {
|
|||
}
|
||||
|
||||
void BaseGameTab::OnOpenGame(wxListEvent &event) {
|
||||
wxLogDebug("Open!");
|
||||
long id = std::stoi(event.GetItem().GetText().ToStdString());
|
||||
std::shared_ptr<Game> *g = new std::shared_ptr<Game>(base->GetGame(id));
|
||||
if (g != NULL) {
|
||||
edited[id]=*g;
|
||||
deleted.push_back(id);
|
||||
game_list->SetItemBackgroundColour(event.GetIndex(), *wxGREEN);
|
||||
wxCommandEvent openGameEvent(OPEN_GAME_EVENT, GetId());
|
||||
openGameEvent.SetEventObject(this);
|
||||
openGameEvent.SetClientData(g);
|
||||
ProcessEvent(openGameEvent);
|
||||
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);
|
||||
game_list->SetItemBackgroundColour(event.GetIndex(), *wxGREEN);
|
||||
wxCommandEvent openGameEvent(OPEN_GAME_EVENT, GetId());
|
||||
openGameEvent.SetEventObject(this);
|
||||
openGameEvent.SetClientData(g);
|
||||
ProcessEvent(openGameEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
BaseImportTab::BaseImportTab(wxFrame *parent):
|
||||
TabBase_TabImport(parent)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -551,7 +551,7 @@ TabBase_TabGames::TabBase_TabGames( wxWindow* parent, wxWindowID id, const wxPoi
|
|||
import_button = new wxButton( this, ID_IMPORT_BUTTON, wxT("Import games"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bottom_sizer->Add( import_button, 0, wxALL, 5 );
|
||||
|
||||
delete_button = new wxButton( this, ID_DELETE_BUTTON, wxT("Delete selection"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
delete_button = new wxButton( this, ID_DELETE_BUTTON, wxT("Mark as deleted"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bottom_sizer->Add( delete_button, 0, wxALL, 5 );
|
||||
|
||||
|
||||
|
|
|
@ -5569,7 +5569,7 @@
|
|||
<property name="gripper">0</property>
|
||||
<property name="hidden">0</property>
|
||||
<property name="id">ID_DELETE_BUTTON</property>
|
||||
<property name="label">Delete selection</property>
|
||||
<property name="label">Mark as deleted</property>
|
||||
<property name="margins"></property>
|
||||
<property name="markup">0</property>
|
||||
<property name="max_size"></property>
|
||||
|
|
Loading…
Add table
Reference in a new issue