Undo and Redo

This commit is contained in:
Tim Warren 2015-04-09 13:54:28 -04:00
parent 57fb790397
commit 472c9f5693
2 changed files with 25 additions and 2 deletions

View File

@ -75,7 +75,7 @@ void MainFrame::SetupToolbar()
toolBar->AddTool(wxID_NEW, "New", bitmaps[0], "New file"); toolBar->AddTool(wxID_NEW, "New", bitmaps[0], "New file");
toolBar->AddTool(wxID_OPEN, "Open", bitmaps[1], "Open file"); toolBar->AddTool(wxID_OPEN, "Open", bitmaps[1], "Open file");
toolBar->AddTool(wxID_SAVE, "Save", bitmaps[2], "Save file"); toolBar->AddTool(wxID_SAVE, "Save", bitmaps[2], "Save file");
toolBar->AddTool(wxID_CLOSE, "Close", bitmaps[3], "Close file"); //toolBar->AddTool(wxID_CLOSE, "Close", bitmaps[3], "Close file");
//toolBar->AddSeparator(); //toolBar->AddSeparator();
//toolBar->AddTool(wxID_ANY, "Settings", bitmaps[4], "Change Settings"); //toolBar->AddTool(wxID_ANY, "Settings", bitmaps[4], "Change Settings");
toolBar->Realize(); toolBar->Realize();
@ -132,6 +132,8 @@ void MainFrame::BindEvents()
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditCopy, this, wxID_COPY); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditCopy, this, wxID_COPY);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditPaste, this, wxID_PASTE); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditPaste, this, wxID_PASTE);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditSelectAll, this, wxID_SELECTALL); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditSelectAll, this, wxID_SELECTALL);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditUndo, this, wxID_UNDO);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditRedo, this, wxID_REDO);
} }
void MainFrame::OnClose(wxCloseEvent &WXUNUSED(event)) void MainFrame::OnClose(wxCloseEvent &WXUNUSED(event))
@ -160,15 +162,34 @@ void MainFrame::OnEditCopy(wxCommandEvent &WXUNUSED(event))
} }
void MainFrame::OnEditPaste(wxCommandEvent &WXUNUSED(event)) void MainFrame::OnEditPaste(wxCommandEvent &WXUNUSED(event))
{
if (notebook->GetCurrentEditor()->CanPaste())
{ {
notebook->GetCurrentEditor()->Paste(); notebook->GetCurrentEditor()->Paste();
} }
}
void MainFrame::OnEditSelectAll(wxCommandEvent &WXUNUSED(event)) void MainFrame::OnEditSelectAll(wxCommandEvent &WXUNUSED(event))
{ {
notebook->GetCurrentEditor()->SelectAll(); notebook->GetCurrentEditor()->SelectAll();
} }
void MainFrame::OnEditUndo(wxCommandEvent &WXUNUSED(event))
{
if (notebook->GetCurrentEditor()->CanUndo())
{
notebook->GetCurrentEditor()->Undo();
}
}
void MainFrame::OnEditRedo(wxCommandEvent &WXUNUSED(event))
{
if (notebook->GetCurrentEditor()->CanRedo())
{
notebook->GetCurrentEditor()->Redo();
}
}
void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event)) void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event))
{ {
wxMessageBox(_T("Tyro, a text editor for all development\n Copyright 2015, Timothy J. Warren"), wxT("About Tyro"), wxOK| wxICON_INFORMATION, this); wxMessageBox(_T("Tyro, a text editor for all development\n Copyright 2015, Timothy J. Warren"), wxT("About Tyro"), wxOK| wxICON_INFORMATION, this);

View File

@ -31,6 +31,8 @@ class MainFrame: public wxFrame
void OnEditCopy(wxCommandEvent &event); void OnEditCopy(wxCommandEvent &event);
void OnEditPaste(wxCommandEvent &event); void OnEditPaste(wxCommandEvent &event);
void OnEditSelectAll(wxCommandEvent &event); void OnEditSelectAll(wxCommandEvent &event);
void OnEditUndo(wxCommandEvent &event);
void OnEditRedo(wxCommandEvent &event);
void OnClose(wxCloseEvent &event); void OnClose(wxCloseEvent &event);
void OnQuit(wxCommandEvent &event); void OnQuit(wxCommandEvent &event);
void OnAbout(wxCommandEvent &event); void OnAbout(wxCommandEvent &event);