home *** CD-ROM | disk | FTP | other *** search
- !!script
- // Copyright ⌐ 1997-1998 - Modelworks Software
-
- /**
- @Tool: replaceInOpenDocuments~replaces a findWhat expression with a replaceWith
- value in all open documents.
- @EndTool:
- @Summary: replaceInOpenDocuments~replaces in open documents
- */
-
- var output = getOutput();
-
- function DoCommand()
- {
- var findParameters = getGlobal("FindParameters", null);
-
- var findData = chooseReplaceParameters("Replace in open windows",
- 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();
-
- output.clear();
- output.writeLine("Searching for: " +
- findData.key + ": Replacing with: " + findData.getReplaceValue());
-
- var index = 0;
- var lineIndex = -1;
- var editor = getEditor(index++);
- while (editor)
- {
- var fileName = editor.path;
-
- findData.startCharIndex = 0;
- findData.startLineIndex = 0;
-
- editor.findNext(findData);
- while (findData && findData.found)
- {
- editor.replace(findData.getReplaceValue(), findData);
-
- var range = findData.range;
-
- // Only print out one message per line
- if (lineIndex != range.startLineIndex)
- {
- lineIndex = range.startLineIndex;
- output.writeMessage(fileName, lineIndex, editor.copy(lineIndex));
- }
-
- editor.findNext(findData);
- }
- lineIndex = -1;
- editor.update();
- editor = getEditor(index++);
- }
- output.writeLine("Replace in open files completed");
- }
- }
-
- !!/script
-
-