home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------
- // Object Scripting
- // Copyright (c) 1996, 1997 by Borland International, All Rights Reserved
- //
- // SRCHALL.SPP: Search All. Searches and replaces across files in the
- // current project.
- //
- // USE: Run script. Invoke SearchAll(topNode) to search and
- // ReplaceAll(topNode) to search and replace. Parameter topNode optionally
- // specifies a node from which to begin the search. Searches include C,
- // CPP, SPP and TXT files. Search/replaces allow the specification of a
- // file mask.
- //
- // FILES: SEARCH.DLL, MISC.SPP, FOREACH.SPP
- //
- // NOTES: Search.dll must be available for loading. It is shipped in the
- // BCW bin directory.
- //--------------------------------------------------------------------------
- print typeid(module());
-
- //
- // IDE imports.
- //
- import IDE;
- import editor;
- import scriptEngine;
-
- //
- // Load support modules.
- //
- if (!scriptEngine.IsLoaded("foreach")) scriptEngine.Load("foreach");
-
- //
- // class TSearchRep
- // ~~~~~ ~~~~~~~~~~
- // Used to pass parameters to replace.
- //
- class TSearchRep(search, replace) {
- declare searchFor = new String(search);
- declare replaceWith = new String(replace);
- }
-
- //
- // Get a handle to the current module. Used in passing "global" functions.
- //
- Mod = module();
-
- TopMessage = NULL; // Message database ID of parent message.
-
- //
- // Import a custom dialog function from srchrep.dll.
- //
- import "search.dll" {
- int searchReplaceDialog (int, char *, char *, char *);
- }
-
- //
- // Import needed Windows APIs.
- //
- import "user32.dll" {
- int GetActiveWindow();
- }
-
- Search(fileName, parentName, searchFor)
- {
- if (TopMessage == NULL) {
- TopMessage = IDE.MessageCreate("SearchA&ll", "transfer", INFORMATION, 0,
- "Searching nodes for '" +
- searchFor + "'", 0, 0, NULL, 0, 0);
- }
-
- declare del = 0;
-
- if (searchFor != "") {
- declare newEdView;
- declare pos;
-
- if (editor.TopView.Buffer.FileName == fileName) {
- newEdView = editor.TopView;
- pos = newEdView.Position;
- pos.Save();
- pos.Move(1, 1);
- }
- else {
- newEdView = new EditBuffer(fileName, TRUE);
- del = 1;
- pos = newEdView.Position;
- pos.Move(1, 1);
- }
-
- if (pos.Search(searchFor, FALSE, FALSE) == TRUE) {
- do {
- IDE.MessageCreate("SearchA&ll", "", INFORMATION, TopMessage,
- fileName, pos.Row, pos.Column, "Found", 0, 0);
- } while (pos.SearchAgain());
- }
- if (del) {
- newEdView.Destroy();
- }
- else {
- pos.Restore();
- }
- }
-
- return OK;
- }
-
- Replace(fileName, parentName, searchReplace)
- {
- declare searchFor;
- declare replaceWith;
- declare del = 0;
-
- if (initialized(searchReplace)) {
- searchFor = searchReplace.searchFor;
- replaceWith = searchReplace.replaceWith;
-
- if (TopMessage == NULL) {
- TopMessage = IDE.MessageCreate("R&eplaceAll", "transfer", INFORMATION,
- 0, "Searching nodes for '" +
- searchFor.Text +
- "', replacing with '" +
- replaceWith.Text + "'",
- 0, 0, NULL, 0, 0);
- }
-
- if (searchFor.Length != 0 && replaceWith.Length != 0) {
- declare newEdBuffer;
- declare pos;
-
- if (editor.TopView.Buffer.FileName == fileName) {
- pos = editor.TopView.Position;
- pos.Save();
- pos.Move(1, 1);
- }
- else {
- newEdBuffer = new EditBuffer(fileName, TRUE);
- del = 1;
- pos = newEdBuffer.Position;
- pos.Move(1, 1);
- }
-
- if (pos.Replace(searchFor.Text, replaceWith.Text, FALSE, FALSE) != 0) {
- do {
- IDE.MessageCreate("R&eplaceAll", "", INFORMATION, TopMessage,
- fileName, pos.Row, pos.Column, "Replaced", 0, 0);
- } while (pos.ReplaceAgain());
- }
- if (del) {
- if (newEdBuffer.IsModified) {
- newEdBuffer.Save();
- }
- newEdBuffer.Destroy();
- }
- else {
- pos.Restore();
- }
- }
- }
- else {
- return 0;
- }
-
- return OK;
- }
-
- SearchAll(node)
- {
- declare searchFor;
- searchFor = IDE.SimpleDialog("Search For:", "");
-
- if (searchFor != "") {
- if (initialized(node)) {
- declare prjNode = new ProjectNode(node);
- TraverseProject(node, Mod:>Search, "*.cpp;*.spp;*.txt",
- searchFor);
- }
- else {
- TraverseProject(NULL, Mod:>Search, "*.cpp;*.spp;*.txt",
- searchFor);
- }
- }
-
- TopMessage = NULL;
-
- // Show the results.
- //
- IDE.ViewMessage("SearchAll");
- }
-
- ReplaceAll(node)
- {
- declare searchFor;
- declare replaceWith;
- declare mask = "*.cpp;*.spp;*.txt";
- declare retVal = searchReplaceDialog(GetActiveWindow(), searchFor,
- replaceWith, mask);
-
- if (retVal) {
- declare str = new TSearchRep(searchFor, replaceWith);
- if (initialized(node)) {
- declare prjNode = new ProjectNode(node);
- TraverseProject(node, Mod:>Replace, mask, str);
- }
- else {
- TraverseProject(NULL, Mod:>Replace, mask, str);
- }
- }
-
- TopMessage = NULL;
-
- // Show the results.
- //
- IDE.ViewMessage("ReplaceAll");
- }
-
-