diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index cb42534..5a0e220 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -146,7 +146,7 @@ void MainFrame::BindEvents() 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::OnSaveAs, this, wxID_SAVEAS); - Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnFileClose, this, wxID_CLOSE); + Bind(wxEVT_CLOSE_WINDOW, &TabContainer::OnClose, notebook, wxID_CLOSE); 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::OnEditCut, this, wxID_CUT); @@ -186,8 +186,11 @@ void MainFrame::OnFileClose(wxCommandEvent &WXUNUSED(event)) void MainFrame::OnSave(wxCommandEvent &WXUNUSED(event)) { - wxString file = notebook->GetCurrentEditor()->fileName; - notebook->GetCurrentEditor()->SaveFile(file); + EditPane *editor = notebook->GetCurrentEditor(); + wxString file = editor->fileName; + + editor->SetSavePoint(); + editor->SaveFile(file); } void MainFrame::OnSaveAs(wxCommandEvent &WXUNUSED(event)) diff --git a/src/widgets/TabContainer.cpp b/src/widgets/TabContainer.cpp index ab4d767..48687d9 100644 --- a/src/widgets/TabContainer.cpp +++ b/src/widgets/TabContainer.cpp @@ -64,3 +64,24 @@ EditPane *TabContainer::GetCurrentEditor() { return (EditPane *) this->GetCurrentPage(); } + +void TabContainer::OnClose(wxCloseEvent &event) +{ + //EditPane *currentTab = this->GetCurrentEditor(); + + if (event.CanVeto() && false)//currentTab->isModified()) + { + if ( + wxMessageBox("The file has not been saved... continue closing?", + "Please confirm", + wxICON_QUESTION | wxYES_NO + ) != wxYES + ) + { + event.Veto(); + return; + } + } + + Destroy(); +} diff --git a/src/widgets/TabContainer.h b/src/widgets/TabContainer.h index 88b31e6..38fc9a9 100644 --- a/src/widgets/TabContainer.h +++ b/src/widgets/TabContainer.h @@ -30,6 +30,7 @@ public: void AddTab(); void AddTab(wxString filePath); void OnEditSelectAll(wxCommandEvent &event); + void OnClose(wxCloseEvent &event); EditPane *GetCurrentEditor(); private: };