Hello script writers!
Since UE v14.20 this function is an obsolete method to get the clipboard content into a variable - see the posts below!
Here is a function which you can use to get the text in the current clipboard into a string variable for manipulation before writing the string into a file. For further details see the comments in the script.
Since UE v14.20 this function is an obsolete method to get the clipboard content into a variable - see the posts below!
Here is a function which you can use to get the text in the current clipboard into a string variable for manipulation before writing the string into a file. For further details see the comments in the script.
Code: Select all
//== GetClipboardText ======================================================
/* The function GetClipboardText returns the text in the active
clipboard as string for a variable of type string. It does this
by opening a new file, convert it to ASCII in case of the setting
>Always create new files as UNICODE< is checked in the configuration,
pastes the text, re-selects it and returns the selection as string.
This routine can be also used to get a selection in a Unicode file
into a string variable if you first copy the selection to one of
the 10 clipboards and the selected Unicode string can be converted
to ANSI without a change in the characters like for UTF-8 XML files
which do not really contain Unicode characters.
The function requires UltraEdit >= v13.20 or UEStudio >= v6.40.
The function has following optional input parameters:
1) nDocIndex - is the document index number of the ASCII/ANSI file
which should be used for the clipboard to string conversion. The
default value is -1 which means that the function should create a
new ASCII file by itself. Use -1 on first call of this function. But
if you need this function more than once, use the second parameter to
avoid closing the temp file and call this function with the correct
document index number of the temp file to avoid permanent opening
and closing temp files during script execution which would make the
script very slow.
2) bAutoClose - boolean variable to specify if the temp file should be
automatically closed after the function has loaded the clipboard text
into a string variable. The default is TRUE which means that the temp
file is automatically closed.
This function is copyrighted by Mofi for free usage by UE/UES users.
The author cannot be responsible for any damage caused by this function.
You use it at your own risk. */
function GetClipboardText (nDocIndex, bAutoClose)
{
// First check the optional input parameters.
if (typeof(nDocIndex) != "number") nDocIndex = -1;
if (nDocIndex >= 0) // Check for invalid document index.
{
if (nDocIndex >= UltraEdit.document.length) nDocIndex = -1;
}
if (typeof(bAutoClose) != "boolean") bAutoClose = true;
/* Remember document index of active file in case it must be made
active again after the function has loaded the string from the
temp file. This small routine was copied from
http://forums.ultraedit.com/viewtopic.php?f=52&t=4571 */
var nActiveFileIndex = -1
for (var i = 0; i < UltraEdit.document.length; i++)
{
if (UltraEdit.activeDocument.path == UltraEdit.document[i].path)
{
nActiveFileIndex = i;
break;
}
}
var nActLineNo = -1;
var nTempFileIndex = nDocIndex;
if (nDocIndex < 0) // Must a new temp file be created?
{
UltraEdit.newFile();
nTempFileIndex = UltraEdit.document.length - 1;
UltraEdit.document[nTempFileIndex].unicodeToASCII();
}
else
{
/* Just in case the user wants to use the active file as temp
file remember the current position in the temp file to
restore the position later. */
nActLineNo = UltraEdit.document[nTempFileIndex].currentLineNum;
var nActColNo = UltraEdit.document[nTempFileIndex].currentColumnNum;
if (typeof(UltraEdit.activeDocumentIdx) == "undefined") nActColNo++;
}
/* Go to top of the temp file, paste the active clipboard content
and re-select it. */
UltraEdit.document[nTempFileIndex].top();
UltraEdit.document[nTempFileIndex].paste();
UltraEdit.document[nTempFileIndex].selectToTop();
// Get the selection into a string variable if there is one.
var sClipboardText = "";
if (UltraEdit.document[nTempFileIndex].isSel())
{
sClipboardText = UltraEdit.document[nTempFileIndex].selection;
UltraEdit.document[nTempFileIndex].deleteText();
}
// Restore previous file position in the temp file if necessary.
if (nActLineNo >= 0) UltraEdit.document[nTempFileIndex].gotoLine(nActLineNo,nActColNo);
// Close the temp file if it should be done.
if (bAutoClose) UltraEdit.closeFile(UltraEdit.document[nTempFileIndex].path,2);
// Set focus back to previous active file if this is necessary.
if (nActiveFileIndex >= 0 && nActiveFileIndex < UltraEdit.document.length)
{
if (UltraEdit.activeDocument.path != UltraEdit.document[nActiveFileIndex].path)
{
UltraEdit.document[nActiveFileIndex].setActive();
}
}
return sClipboardText;
}