Dialog tutorial:
Part
4
This page adds the Search and Replace
dialog to the Text editor made in a previous
tutorial
- Reopen your text editor project and
use
the menuzone to add Replace to the Edit menu. Double click the
replica and you will be taken to the frames's eventhandler code.
Click in this, and choose the menu saying Insert Dialog | Own
Dialog. In the Choose file window, browse to the include file (
*.inc) and click OK. The contents of the include file are inserted
into the body of the function, the headers and makefile are updated
and the dialog's .cpp and .h files copied into the text
editor's project directory.
- In the Body of the OnEditReplace
method, add the code textctrl -> Replace
(sSearchBox,sReplaceBox); to call
the textctrl to do the actual
replacement, so that the code looks like this:
{
wxString sReplaceBox=
dialog.replTextCtrl_GetValue()
;
bool b =
dialog.m_RadioButtonUp_GetValue() ;
bool b2 =
dialog.CaseSensitiveCheckBox_IsChecked() ;
wxString sSearchBox =
dialog.SearchBox_GetValue() ;
textctrl -> Replace
(sSearchBox, sReplaceBox );
}
- Now we have to add the replace
method to the textctrl - go to the menuzone and right click the
white area of the window, select Go/Add Non GUI method. In the
dialog type int Replace (const wxString & sSearch,
const
wxString & sReplace)
- The body of the Replace method
should call Find (which we created earlier) to determine the
stating index of the required text, and then we can reuse the the
Replace method of wxTextCtrl
int iStart = Find ( sSearch ) ;
wxTextCtrl::Replace ( iStart, iStart +
sSearch.Length(), sReplace )
;
return iStart ;
- Now Run it and see how it
works. This is only the most basic search/replace code, so you can
modify it to do a case-insensitive search, and
to do repeated Find/Replace
Next - create a HTML navigator dialog
Back
wxHatch
Home 