Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Multiline Search & Replace
Jenna:
--- Quote from: mariocup on November 08, 2009, 10:49:17 am ---seems very very cool.
--- End quote ---
Absolutely correct.
Does it also work with mixed line-edings ?
rickg22:
--- Quote from: jens on November 08, 2009, 11:06:09 am ---
--- Quote from: mariocup on November 08, 2009, 10:49:17 am ---seems very very cool.
--- End quote ---
Absolutely correct.
Does it also work with mixed line-edings ?
--- End quote ---
It didn't work with mixed line-endings at first. I needed to convert the line endings of both the search/replace expressions AND of files. What I do is checking if the search/replace expressions contain a LF or CR. In that case, we convert the current file to the configured EOL mode so line endings aren't mixed anymore. We're going to search/replace, so it's not a problem if the file is modified. Of course, this is done INSIDE the undo action, so that if the match isn't found, the file is undo'ed. The undoing is already done with existing code inside EditorManager, i only had to move the begin-undo-action before the line conversion.
Here's the patch for EditorManager:
--- Code: ---int EditorManager::Replace(cbStyledTextCtrl* control, cbFindReplaceData* data)
{
if (!control || !data)
return -1;
if (control->GetReadOnly())
{
cbMessageBox(_("This file is read-only.\nReplacing in a read-only file is not possible."),
_("Warning"), wxICON_EXCLAMATION);
return -1;
}
bool AdvRegex=false;
int replacecount=0;
int foundcount=0;
int flags = 0;
control->BeginUndoAction(); // The undo is set at this point in case we need to convert the EOLs.
if((data->findText.Find(_T("\n")) != wxNOT_FOUND) || (data->findText.Find(_T("\r")) != wxNOT_FOUND))
{
// If it's a multi-line S&R, We need to convert the EOLs, or the find may be inaccurate.
// This will slow down processing as the whole file needs to be preprocessed, but it's a small price
// compared to searching and replacing multiple lines by hand.
static const int default_eol = platform::windows ? wxSCI_EOL_CRLF : wxSCI_EOL_LF;
int eolMode = Manager::Get()->GetConfigManager(_T("editor"))->ReadInt(_T("/eol/eolmode"), default_eol);
control->SetEOLMode(eolMode);
control->ConvertEOLs(eolMode);
}
CalculateFindReplaceStartEnd(control, data);
// ... the rest of the code is kept as it was.
--- End code ---
For find in files, it's a similar code.
This check is done only for the find string, since having a multiline replace string isn't a problem. It's the find string that gives us all the problems.
Algorithm aside, my real problem right now is getting the ctrl-tab key to work. I don't want the tabs to change between the single-line and multiple-line tabs, but between the Replace and Replace in files. How do I disable a wxNotebook control from accepting ctrl-tab keys?
Just in case, I'm going to change the wxNotebook for a wxChoicebook. I hope ctrl-tab isn't affected this way. (And I think it looks prettier and less bulky).
rickg22:
Ugh, this sucks!
wxNotebook interferes with my tabs and I find no way to make it ignore keys.
wxChoicebook completely deletes the tabs.
So I've decided to use a pair of radio buttons and emulate a wxNotebook by hiding and showing panels. This way the ctrl-tab isn't messed with, and the radio buttons are what I wanted in the first place.
It may take me a couple of hours to make it work.
Wish me luck!
rickg22:
:x ARGH! It took me four friggin' hours to get the dialog to work. It's incredible that the GUI was much more difficult to work on than the algorithm itself.
Okay, progress report:
The UI is done. Yay! :D
Replace in files hangs C::B. Not good. I guess I introduced a bug in there, or I didn't think well the replace in files part. It might take me another hour to get it to work.
Wish me luck!
rickg22:
Well well well. What do you know? The original XRC file had the "Project files" and "Open files" scope swapped. No wonder it was hanging. It was searching on ALL the files. I'll keep debugging.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version