home *** CD-ROM | disk | FTP | other *** search
- !!script
- // Copyright ⌐ 1997-1998 - Modelworks Software
-
- /**
- @Tool: replaceInLines~replaces a findWhat expression with a replaceWith
- value for all lines listed Library/Output/replaceInLines.out file. To use
- first generate a list of lines with a format
- "File "<path>" Line n:"
- in the replaceInLines.out file. Then run this script.
- @EndTool:
- @Summary: replaceInLines~does a replace for specified lines in files
- */
-
- var gReplaceInAllSubdirectories = true;
- var gReplaceInFileTypes = "*.*";
-
- var gOutput = getOutput();
-
- function DoCommand()
- {
- var findParameters = getGlobal("FindParameters", null);
-
- var findData = chooseReplaceParameters("Replace in lines",
- findParameters.findWhat,
- findParameters.replaceWith,
- findParameters.caseSensitive,
- findParameters.wholeWord,
- findParameters.regularExpression);
-
- if (findData)
- {
- findParameters.findWhat = findData.key;
- findParameters.replaceWith = findData.getReplaceValue();
- findParameters.caseSensitive = findData.caseSensitive;
- findParameters.wholeWord = findData.wholeWord;
- findParameters.regularExpression = findData.regularExpression;
- findParameters.searchDown = findData.searchDown;
- findParameters.updateHistory();
-
- var findExpression = findParameters.findWhat;
- var caseSensitive = findParameters.caseSensitive;
- var replaceValue = findParameters.replaceWith;
-
- gOutput.clear();
- gOutput.writeLine("Searching for: '" +
- findData.key + "', Replacing with: '" + findData.getReplaceValue() + "'");
-
- var path = File.getLibraryPath() + "\\Output\\replaceInLines.out";
- var replaceInLinesFileList = openEditor(path, false);
-
- if (replaceInLinesFileList)
- {
- saveAll();
-
- var maxLineIndex = replaceInLinesFileList.getLineCount();
- for (var i = 0; i < maxLineIndex; i++)
- {
- var lineData = replaceInLinesFileList.copy(i);
- var foundPath = searchInString(lineData, '"[^"]*"');
- if (foundPath)
- {
- var path = foundPath.key;
- path = path.substring(1, path.length-1); // stript quotes
- var editor = openEditor(path, false);
- if (editor)
- {
- var foundLine = searchInString(lineData, 'Line[^:]*:');
- if (foundLine && foundLine.key.length > 5)
- {
- var lineIndex = new Number(foundLine.key.substring(4, foundLine.key.length-1)) - 1;
- var string = editor.copy(lineIndex);
- if (string)
- {
- var found = searchInString(string, findExpression, 0, caseSensitive);
- if (found)
- {
- gOutput.writeLine("Replaced found value in: " + path + " at line: " + lineIndex);
- var changedString = replaceInString(string, found.value,
- found.key.length, replaceValue);
-
- editor.replace(changedString, lineIndex);
- }
- }
- if (!editor.visible)
- {
- editor.close();
- }
- }
- }
- }
- }
- }
- gOutput.writeLine("Replace in lines completed");
- }
- }
-
- !!/script
-
-