Find/Replace functionality, resolves #3

This commit is contained in:
Tim Warren 2015-06-03 14:32:19 -04:00
parent 4f649b73a7
commit b39e63060b
4 changed files with 36 additions and 19 deletions

View File

@ -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))

View File

@ -142,4 +142,5 @@ private:
}
};
// Set up the main method and event loop
IMPLEMENT_APP(TyroApp);

View File

@ -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);
}
}
/**
@ -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();
}
}

View File

@ -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);