From 472c9f5693f78d99c7f89bf7f3563d8c282e6062 Mon Sep 17 00:00:00 2001 From: Tim Warren Date: Thu, 9 Apr 2015 13:54:28 -0400 Subject: [PATCH] Undo and Redo --- src/widgets/MainFrame.cpp | 25 +++++++++++++++++++++++-- src/widgets/MainFrame.h | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index 027c464..94a10e9 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -75,7 +75,7 @@ void MainFrame::SetupToolbar() toolBar->AddTool(wxID_NEW, "New", bitmaps[0], "New file"); toolBar->AddTool(wxID_OPEN, "Open", bitmaps[1], "Open 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->AddTool(wxID_ANY, "Settings", bitmaps[4], "Change Settings"); 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::OnEditPaste, this, wxID_PASTE); 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)) @@ -161,7 +163,10 @@ void MainFrame::OnEditCopy(wxCommandEvent &WXUNUSED(event)) void MainFrame::OnEditPaste(wxCommandEvent &WXUNUSED(event)) { - notebook->GetCurrentEditor()->Paste(); + if (notebook->GetCurrentEditor()->CanPaste()) + { + notebook->GetCurrentEditor()->Paste(); + } } void MainFrame::OnEditSelectAll(wxCommandEvent &WXUNUSED(event)) @@ -169,6 +174,22 @@ void MainFrame::OnEditSelectAll(wxCommandEvent &WXUNUSED(event)) 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)) { wxMessageBox(_T("Tyro, a text editor for all development\n Copyright 2015, Timothy J. Warren"), wxT("About Tyro"), wxOK| wxICON_INFORMATION, this); diff --git a/src/widgets/MainFrame.h b/src/widgets/MainFrame.h index 0edacde..47f58b1 100644 --- a/src/widgets/MainFrame.h +++ b/src/widgets/MainFrame.h @@ -31,6 +31,8 @@ class MainFrame: public wxFrame void OnEditCopy(wxCommandEvent &event); void OnEditPaste(wxCommandEvent &event); void OnEditSelectAll(wxCommandEvent &event); + void OnEditUndo(wxCommandEvent &event); + void OnEditRedo(wxCommandEvent &event); void OnClose(wxCloseEvent &event); void OnQuit(wxCommandEvent &event); void OnAbout(wxCommandEvent &event);