Properly disable controls when using the tab button to close the last tab

This commit is contained in:
Tim Warren 2015-04-20 17:02:34 -04:00
parent 62556ecf6d
commit 4d05a0943e
2 changed files with 45 additions and 0 deletions

View File

@ -143,6 +143,8 @@ void MainFrame::BindEvents()
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnOpen, this, wxID_OPEN); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnOpen, this, wxID_OPEN);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnSave, this, wxID_SAVE); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnSave, this, wxID_SAVE);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnSaveAs, this, wxID_SAVEAS); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnSaveAs, this, wxID_SAVEAS);
Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSE, &MainFrame::OnClose, this, wxID_ANY);
Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSED, &MainFrame::OnClosed, this, wxID_ANY);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnCloseTab, this, wxID_CLOSE); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnCloseTab, this, wxID_CLOSE);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnAbout, this, wxID_ABOUT); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnAbout, this, wxID_ABOUT);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnQuit, this, wxID_EXIT); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnQuit, this, wxID_EXIT);
@ -176,6 +178,47 @@ void MainFrame::OnOpen(wxCommandEvent &WXUNUSED(event))
notebook->AddTab(filename); notebook->AddTab(filename);
} }
void MainFrame::OnClose(wxAuiNotebookEvent &event)
{
int current_tab = notebook->GetSelection();
EditPane *editor = notebook->GetCurrentEditor();
// Sanity check
if (current_tab == -1) return;
if (editor->IsModified())
{
int Msgbox_Choice = wxMessageBox(
_T("File has not been saved, save file before closing?"),
_T("Modified File"),
wxYES_NO | wxCANCEL | wxICON_QUESTION,
this
);
if (Msgbox_Choice == wxCANCEL)
{
event.Veto();
}
else if (Msgbox_Choice == wxYES)
{
editor->SaveFile();
if (editor->IsModified())
{
wxMessageBox(_("File could not be saved"), _("Error"), wxOK | wxICON_EXCLAMATION);
event.Veto();
}
}
}
}
void MainFrame::OnClosed(wxAuiNotebookEvent &WXUNUSED(event))
{
if (notebook->GetPageCount() == 0)
{
this->DisableEditControls();
}
}
void MainFrame::OnCloseTab(wxCommandEvent &WXUNUSED(event)) void MainFrame::OnCloseTab(wxCommandEvent &WXUNUSED(event))
{ {
int current_tab = notebook->GetSelection(); int current_tab = notebook->GetSelection();

View File

@ -42,6 +42,8 @@ class MainFrame: public wxFrame
void DisableEditControls(); void DisableEditControls();
void OnNew(wxCommandEvent &event); void OnNew(wxCommandEvent &event);
void OnOpen(wxCommandEvent &event); void OnOpen(wxCommandEvent &event);
void OnClose(wxAuiNotebookEvent &event);
void OnClosed(wxAuiNotebookEvent &event);
void OnFileClose(wxCommandEvent &event); void OnFileClose(wxCommandEvent &event);
void OnSave(wxCommandEvent &event); void OnSave(wxCommandEvent &event);
void OnSaveAs(wxCommandEvent &event); void OnSaveAs(wxCommandEvent &event);