Thanks for the answer mofi.
Here is a script i'm trying to make up. It's supposed to look for function definition in a working directory full of source files.
Like you are writing your code and use a function defined in an other file but exported and you need to see the code of this function.( to refresh your memory
)
You just click on the function named where it's called in your code and this script open the file that has your function code in it.
(i've used your script GetListOfFiles),
This script almost works, but i'm having 2 problems :
- sometimes the function gotoline doesn't work properly. Like i found a function definition in file, but when i tried to find the definition of a 2nd function the scripts just doesn't got to the line where it's supposed to go, though it has the right line saved in the var lineFunction.
- 2nd point is that i doesn't really like the fact that i have a small tab open to store my list of results from the find in files but i guess i can't make it be " unseen" just using UE scripting.
If anybody would like to give me some tips or improvement i'll be thankfull.
Code: Select all
Principal();
function Principal()
{
//This script requires UltraEdit v13.10 or UEStudio v6.30 or any later.
//var init
var findStr;
//Clear the output window, make it visible and disable status information.
UltraEdit.outputWindow.showStatus=false;
UltraEdit.outputWindow.clear();
if (UltraEdit.outputWindow.visible == false) {
UltraEdit.outputWindow.showWindow(true);
}
//Get the line where the cursor is.
UltraEdit.activeDocument.startSelect();
UltraEdit.activeDocument.key("END");
var findStr = UltraEdit.activeDocument.selection;
UltraEdit.activeDocument.endSelect();
// Remember current regular expression engine.
var RegexEngine = UltraEdit.regexMode;
/* A regular expression engine must be defined or the find
for the last line in the Unicode results could fail. */
UltraEdit.ueReOn();
findStr = findStr.replace(/\(.*\)/,"");
findStr = findStr.replace(/ .*/,"");
findStr = findStr.replace(/;/,"");
findStr = findStr.replace(/\,/,"");
findStr = "function " + findStr + "(";
switch (RegexEngine) { // Restore original regular expression engine.
case 1: UltraEdit.unixReOn(); break;
case 2: UltraEdit.perlReOn(); break;
default: UltraEdit.ueReOn(); break;
}
var TxtDir = "";
GetListOfFiles(0, TxtDir, "*.psl","",findStr);
// selection into var for last active tab
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.key("DOWN ARROW");
UltraEdit.activeDocument.key("DOWN ARROW");
UltraEdit.activeDocument.startSelect();
UltraEdit.activeDocument.key("END");
UltraEdit.activeDocument.copy();
var wrkTimestampText = UltraEdit.activeDocument.selection;
UltraEdit.activeDocument.endSelect();
var pslFilePath = wrkTimestampText.replace(/\(.*\)/,"");
var lineFunction = wrkTimestampText.replace(/\).*/,"");
lineFunction = lineFunction.replace(/.*\(/,"");
ResultsDocTitle = "** Find Results ** " ;
for (var i = 0; i < UltraEdit.document.length; i++)
{
if (UltraEdit.document[i].path == ResultsDocTitle) {
UltraEdit.closeFile(UltraEdit.document[i].path,2);
break;
}
}
//lineFunction = parseInt( lineFunction );
lineFunction = parseInt( lineFunction );
//UltraEdit.outputWindow.write(lineFunction);
UltraEdit.open(pslFilePath);
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.gotoLine(lineFunction, 0);
}
/*** GetListOfFiles *******************************************************/
This function is copyright by Mofi for free usage by UE/UES users. The
author cannot be responsible for any damage caused by this script. You
use it at your own risk.
function GetListOfFiles (FileList, Directory, FileType, SubDirs , StrLookFor) {
var SummaryInfo = "Search complete, found";
var ResultsDocTitle = "** Find Results ** "; // Note the space at end!
var OutputType = (typeof(DebugMessage) == "number") ? DebugMessage : 2;
if (typeof(FileList) != "value" || FileList < 0 || FileList > 4) FileList = 0;
if (FileList == 0) { // Search in a specified directory?
// If no directory specified, use current working directory.
if (typeof(Directory) != "string" || Directory == "" ) Directory = ".\\";
// Append a backslash if it is missing at end of the directory string.
else if (Directory.match(/\\$/) == null) Directory += "\\";
// Search for all files if no file type is specified.
if (typeof(FileType) != "string" || FileType == "") FileType = "*";
if (typeof(SubDirs) != "boolean") SubDirs = false;
} else {
Directory = ""; // For the list of open, favorite, project
FileType = ""; // or solution files the other 3 parameters
SubDirs = false; // have always the same default values.
}
// Remember current regular expression engine.
var RegexEngine = UltraEdit.regexMode;
/* A regular expression engine must be defined or the find
for the last line in the Unicode results could fail. */
UltraEdit.ueReOn();
/* Run a Find In Files with an empty search string to get the
list of files stored in the specified directory in an edit
window and delete the last line with the summary info. */
UltraEdit.frInFiles.directoryStart=Directory;
UltraEdit.frInFiles.filesToSearch=FileList;
UltraEdit.frInFiles.matchCase=false;
UltraEdit.frInFiles.matchWord=false;
UltraEdit.frInFiles.regExp=true;
UltraEdit.frInFiles.searchInFilesTypes=FileType;
UltraEdit.frInFiles.searchSubs=SubDirs;
UltraEdit.frInFiles.unicodeSearch=false;
UltraEdit.frInFiles.useOutputWindow=false;
UltraEdit.frInFiles.find(StrLookFor);
//UltraEdit.frInFiles.find("*");
// var ListCreated = false;
if (UltraEdit.activeDocument.path == ResultsDocTitle) ListCreated = true;
else {
for (var i = 0; i < UltraEdit.document.length; i++)
{
if (UltraEdit.document[i].path == ResultsDocTitle) {
UltraEdit.document[i].setActive();
ListCreated = true;
break;
}
}
}
if (ListCreated == true) {
// Search for the summary info at bottom of the results.
UltraEdit.activeDocument.findReplace.searchDown=false;
UltraEdit.activeDocument.findReplace.matchCase=true;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=false;
UltraEdit.activeDocument.findReplace.find(SummaryInfo);
ListCreated = UltraEdit.activeDocument.isFound();
}
UltraEdit.activeDocument.findReplace.searchDown=true;
switch (RegexEngine) { // Restore original regular expression engine.
case 1: UltraEdit.unixReOn(); break;
case 2: UltraEdit.perlReOn(); break;
default: UltraEdit.ueReOn(); break;
}
/* Check now if the Find above has had success finding the last line in
the active document which should contain the Find In Files results. */
if (ListCreated == false) {
if (OutputType == 2) {
UltraEdit.messageBox("There is a problem with frInFiles command or one of the strings in the variables\n\"SummaryInfo\" or \"ResultsDocTitle\" is not adapted to your version of UE/UES!","GetListOfFiles Error");
} else if (OutputType == 1) {
if (UltraEdit.outputWindow.visible == false) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetListOfFiles: There is a problem with frInFiles command or one of the strings in the variables");
UltraEdit.outputWindow.write(" \"SummaryInfo\" or \"ResultsDocTitle\" is not adapted to your version of UE/UES!");
}
return false;
}
UltraEdit.activeDocument.deleteLine();
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.key("RIGHT ARROW");
if (UltraEdit.activeDocument.currentPos > 1) UltraEdit.activeDocument.unicodeToASCII();
else UltraEdit.activeDocument.top();
// If top of file is also end of file, no files were found.
if (UltraEdit.activeDocument.isEof()) {
if (OutputType == 2) {
UltraEdit.messageBox("No file "+FileType+" was found in directory\n\n"+Directory,"GetListOfFiles Error");
} else if (OutputType == 1) {
if (UltraEdit.outputWindow.visible == false) UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.write("GetListOfFiles: No file "+FileType+" was found in directory "+Directory);
}
UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
return false;
}
return true;
}