Hi Nicolai!
We have
earlier discussed the possibility of including "common code" in a script but concluded an enhancement request to IDM must be the answer. No news of this since.
But lacking this, your proof of concept is really great !! - I tested it with the "FileNameFunctions.js" as well and it worked perfectly!
But it is not "flicker free" since a new document is opened temporarily. I wanted a "flicker free" and fast way of including my common.js script which I always manually add to new scripts.
This is what I did:
a) I installed the small program
clip.exe into \WINDOWS\SYSTEM32. Clip.exe can be used a the DOS command line to capture DOS output to the windows clipboard.
b) Next I configured a user tool in UE with these settings:
Name=IncludeCommon
Command Line=
TYPE \data\UltraEditScripts\common.js | clipOptions: DOS Program
Output: Append to existing, uncheck "show DOS box", uncheck "capture output", no replace
c) Then I created a includeCommon() function inspired by your trick with eval (my common.js contains the functions from the FileNameFunctions.js script by Mofi and some other basic functions). PS: You need UE version 14.20 since I rely on UltraEdit.clipboardContent.
- Code: Select all
eval(includeCommon());
UltraEdit.outputWindow.write("Result of the functions for input string \"C:\\Temp\\Test.txt\":");
UltraEdit.outputWindow.write("");
UltraEdit.outputWindow.write("GetFilePath: \""+GetFilePath("C:\\Temp\\Test.txt")+"\"");
UltraEdit.outputWindow.write("GetNameOfFile: \""+GetNameOfFile("C:\\Temp\\Test.txt")+"\"");
UltraEdit.outputWindow.write("GetFileName: \""+GetFileName("C:\\Temp\\Test.txt")+"\"");
UltraEdit.outputWindow.write("GetFileExt: \""+GetFileExt("C:\\Temp\\Test.txt")+"\"");
function includeCommon() {
/* which UE clipboard is active ? */
var clipIdx = UltraEdit.clipboardIdx;
/* If Windows clipboard is active - then save content on this */
var clipboardContent;
if(clipIdx==0) clipboardContent = UltraEdit.clipboardContent;
/* ensure windows clipboard and clear it */
UltraEdit.selectClipboard(0);
UltraEdit.clearClipboard();
/* run tool that gets contents of common script functions file */
UltraEdit.runTool("IncludeCommon");
/* retrieve contents from windows clipboard and clear clipboard */
var commonCode = UltraEdit.clipboardContent;
UltraEdit.clearClipboard();
/* restore original active clipboard */
UltraEdit.selectClipboard(clipIdx);
/* if active clipboard was windows clipboard, restore contents */
if(clipIdx==0) UltraEdit.clipboardContent = clipboardContent;
/* return common code */
return commonCode;
}
And it seems to be quite fast and it is "flicker free" and doesn't remove focus from the active document.
Here is the condensed version when you do not worry about overwriting the contents of the windows clipboard:
- Code: Select all
eval(includeCommon());
function includeCommon() {
UltraEdit.selectClipboard(0);
UltraEdit.runTool("IncludeCommon");
var commonCode = UltraEdit.clipboardContent;
UltraEdit.clearClipboard();
return commonCode;
}