diff --git a/Makefile b/Makefile index 37b5b0d..2583d3c 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,8 @@ WX_RES = $(shell wx-config --rescomp) WX_CXXFLAGS = $(shell wx-config --cxxflags) INC_FLAGS = -Iinclude -I. -I/usr/local/include -DEV_CXXFLAGS = -g -Wall -Wextra -DDEBUG $(INC_FLAGS) -CXXFLAGS = -Os -DNDEBUG $(INC_FLAGS) +DEV_CXXFLAGS = -O0 -g -Wall -Wextra -pipe -DDEBUG $(INC_FLAGS) +CXXFLAGS = -Os -pipe -DNDEBUG $(INC_FLAGS) TEST_SRC = $(wildcard tests/*.cpp) TESTS = $(patsubst %.cpp,%,$(TEST_SRC)) diff --git a/src/TyroApp.cpp b/src/TyroApp.cpp index e9e531d..f916181 100644 --- a/src/TyroApp.cpp +++ b/src/TyroApp.cpp @@ -142,4 +142,5 @@ private: } }; +// Set up the main method and event loop IMPLEMENT_APP(TyroApp); diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index cb4037e..4748451 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -41,6 +41,12 @@ MainFrame::~MainFrame() wxLogDebug("Main Frame Destructor Called."); delete notebook; delete toolBar; + + wxDELETE(this->findDlg); + wxDELETE(this->findData); + wxDELETE(this->replaceDlg); + wxDELETE(this->findReplaceData); + manager->UnInit(); } @@ -425,17 +431,13 @@ void MainFrame::OnToggleWhitespace(wxCommandEvent& event) */ void MainFrame::OnEditFind(wxCommandEvent &WXUNUSED(event)) { - if (this->findDlg != nullptr) - { - wxDELETE(this->findDlg); - wxDELETE(this->findData); - } - else + if (this->findDlg == nullptr) { this->findData = new wxFindReplaceData(wxFR_DOWN); this->findDlg = new wxFindReplaceDialog(this, this->findData, "Find"); - this->findDlg->Show(true); } + + this->findDlg->Show(true); } /** @@ -445,19 +447,14 @@ void MainFrame::OnEditFind(wxCommandEvent &WXUNUSED(event)) */ void MainFrame::OnEditReplace(wxCommandEvent &WXUNUSED(event)) { - if (this->replaceDlg != nullptr) - { - wxDELETE(this->replaceDlg); - wxDELETE(this->findReplaceData); - } - else + if (this->replaceDlg == nullptr) { this->findReplaceData = new wxFindReplaceData(wxFR_DOWN); this->replaceDlg = new wxFindReplaceDialog(this, this->findReplaceData, "Find and Replace", wxFR_REPLACEDIALOG); - - this->replaceDlg->Show(true); } + + this->replaceDlg->Show(true); } /** @@ -538,6 +535,25 @@ void MainFrame::OnFindDialog(wxFindDialogEvent &event) else if (type == wxEVT_FIND_REPLACE_ALL) { wxLogDebug("wxEVT_FIND_REPLACE_ALL"); + + // Freeze editor drawing until replacement is finished + editor->Freeze(); + + editor->GotoPos(0); // Go to the start of the document + editor->SearchAnchor(); + + editor->BeginUndoAction(); + + while (editor->SearchNext(stc_flags, event.GetFindString()) != -1) + { + editor->ReplaceSelection(event.GetReplaceString()); + } + + editor->EndUndoAction(); + + editor->ScrollToEnd(); + + editor->Thaw(); } } diff --git a/src/widgets/TyroMenu.cpp b/src/widgets/TyroMenu.cpp index 6e99656..30c323d 100644 --- a/src/widgets/TyroMenu.cpp +++ b/src/widgets/TyroMenu.cpp @@ -63,7 +63,7 @@ void TyroMenu::SetupMainMenus() //editMenu->Append(wxID_DELETE, "&Delete\tDel"); editMenu->AppendSeparator(); editMenu->Append(wxID_FIND, "&Find\tCtrl+F"); - //editMenu->Append(wxID_REPLACE, "&Replace\tCtrl+R"); + editMenu->Append(wxID_REPLACE, "&Replace\tCtrl+R"); editMenu->AppendSeparator(); editMenu->Append(wxID_SELECTALL, "Select All\tCtrl+A", "Select all the text in the current document"); @@ -112,7 +112,7 @@ void TyroMenu::EnableEditControls(bool enable) this->editMenu->Enable(wxID_PASTE, enable); this->editMenu->Enable(wxID_SELECTALL, enable); this->editMenu->Enable(wxID_FIND, enable); - //this->editMenu->Enable(wxID_REPLACE, enable); + this->editMenu->Enable(wxID_REPLACE, enable); // Enable/disable top level menus this->EnableEntireMenu(myVIEW_MENU, this->viewMenu, enable);