void FindWindow::ReplaceAll(void) { // This function is called from the FinderThread function, so locking is // required when accessing any member variables. Lock(); BString errorLog; BString findText(fFindBox->Text()); BString replaceText(fReplaceBox->Text()); if (!fIsRegEx) { findText.CharacterEscape("^$()%.[]*+-?", '\\'); } BString replaceTerms; replaceTerms << "'" << findText << "' '" << replaceText << "'"; ShellHelper shell; shell << "pwd; find "; shell.AddEscapedArg(fWorkingDir); BString sStr("'s/"); sStr << findText.String() << "/"; sStr << replaceText.String() << "/"; sStr << "'"; shell << " -type f | xargs sed -i " << sStr.String(); STRACE(2,("Shell command: %s\n",shell.AsString().String())); Unlock(); BString out; shell.RunInPipe(out,false); STRACE(2,("Command output: %s\n",out.String())); if (errorLog.CountChars() > 0) { BString errorString = B_TRANSLATE("The following files had problems replacing the search terms:\n"); errorString << errorLog; ShowAlert(errorString.String()); } PostMessage(M_FIND); }
void FindWindow::Replace(void) // Was REPLACEALL { // This function is called from the FinderThread function, so locking is // required when accessing any member variables. // Just make sure you escape single quotes and underscores before constructing // the sed command ShowAlert(B_TRANSLATE("luare based replace all has been removed until it can be migrated from Lua"), "OK", NULL, NULL, B_STOP_ALERT); return; Lock(); BString errorLog; for (int32 i = 0; i < fResultList->CountItems(); i++) { BString findText(fFindBox->Text()), replaceText(fReplaceBox->Text()); if (!fIsRegEx) { findText.CharacterEscape("^$()%.[]*+-?", '%'); replaceText.CharacterEscape("%", '%'); } findText.CharacterEscape("'", '\\'); replaceText.CharacterEscape("'", '\\'); BString replaceTerms; replaceTerms << "'" << findText << "' '" << replaceText << "'"; GrepListItem *gitem = (GrepListItem*)fResultList->ItemAt(i); DPath file(gitem->GetRef()); ShellHelper shell; shell << "luare" << replaceTerms; shell.AddEscapedArg(file.GetFullPath()); shell.AddEscapedArg(file.GetFullPath()); printf("replace command: %s\n", shell.AsString().String()); int32 outvalue = shell.Run(); if (outvalue) { // append file name to list of files with error conditions and notify // user of problems at the end so as not to annoy them. errorLog << "\t" << file.GetFileName() << "\n"; } // Allow window updates from time to time if (i % 5 == 0) { Unlock(); Lock(); } } Unlock(); if (errorLog.CountChars() > 0) { BString errorString = B_TRANSLATE("The following files had problems replacing the search terms:\n"); errorString << errorLog; BAlert *alert = new BAlert(B_TRANSLATE_SYSTEM_NAME("Paladin"), errorString.String(), B_TRANSLATE("OK")); alert->Go(); } PostMessage(M_FIND); }