bool Ide::SearchInFile(const String& fn, const String& pattern, bool wholeword, bool ignorecase, int& n, RegExp *regexp) { FileIn in(fn); if(!in) return true; int ln = 1; bool wb = wholeword ? iscid(*pattern) : false; bool we = wholeword ? iscid(*pattern.Last()) : false; int infile = 0; while(!in.IsEof()) { String line = in.GetLine(); bool bw = true; int count; if(regexp) { if(regexp->Match(line)) AddFoundFile(fn, ln, line, regexp->GetOffset(), regexp->GetLength()); } else for(const char *s = line; *s; s++) { if(bw && Match(pattern, s, we, ignorecase, count)) { AddFoundFile(fn, ln, line, int(s - line), count); infile++; n++; break; } if(wb) bw = !iscid(*s); } ln++; } in.Close(); int ffs = ~ff.style; if(infile && ffs != STYLE_NO_REPLACE) { EditFile(fn); bool doit = true; if(ffs == STYLE_CONFIRM_REPLACE) { editor.SetCursor(0); editor.Find(false, true); switch(PromptYesNoCancel(NFormat("Replace %d lines in [* \1%s\1]?", infile, fn))) { case 1: break; case 0: doit = false; break; case -1: return false; } } if(doit) { editor.SelectAll(); editor.BlockReplace(); SaveFile(); ffound.Add(fn, Null, AsString(infile) + " replacements made"); ffound.Sync(); } } return true; }
void MapEditor::OnNewMap() { int r = PromptYesNoCancel(t_("Save current map before creating new map?")); if (r == IDYES) OnSaveMap(); if (r == IDCANCEL) return; _map.Clear(); UpdateLevelList(); UpdateEditorCtrls(); }