UltraEdit selects automatically the active file as first file to compare and the previously active file as second file to compare on opening the
Compare Files/Folders dialog for example with predefined hotkey
Alt+F11. The user has the option to select for first and second file to compare a different opened file using the drop down list or click on the buttons
... to browse to files (or directories on using UltraCompare as comparison tool) not opened at all. But the user usually just hits next
RETURN or
ENTER to run the configured file comparison tool with the currently active and previously active file. The previously active file can be any opened file, not only the one right (or left) the active file. So it might be useful for you to add this line in INI file for usage of
Compare Files/Folders in addition to your script if you want to run Beyond Compare with currently active file and previously active file or a completely different file instead of active file and the file right (or left) to active file in file tabs bar.
I have also a suggestion for the script:
Code: Select all
// ----------------------------------------------------------------------------
// Starting Beyond Compare via helper application with using active file
// as first and the next or previous file as second file to compare.
// ----------------------------------------------------------------------------
if (UltraEdit.document.length >= 2) // Are at least two files opened?
{
// Get document index of active file used as first file to compare.
var nDocIndex1 = UltraEdit.activeDocumentIdx;
// Set document index of next file for second file to compare.
var nDocIndex2 = nDocIndex1 + 1;
// If there is no more file next to active file, use the
// document index of previous file for second file to compare.
if (nDocIndex2 == UltraEdit.document.length) nDocIndex2 -= 2;
// Has the first file no real file name and also no real file extension?
var bFileNamed1 = !UltraEdit.document[nDocIndex1].isName("");
if (!bFileNamed1) bFileNamed1 = !UltraEdit.document[nDocIndex1].isExt("");
// Has the second file no real file name and also no real file extension?
var bFileNamed2 = !UltraEdit.document[nDocIndex2].isName("");
if (!bFileNamed2) bFileNamed2 = !UltraEdit.document[nDocIndex2].isExt("");
// Are both files named files and not new, unnamed files?
if (bFileNamed1 && bFileNamed2)
{
// Create a new file, write both full qualified file names enclosed
// in double quotes into this file, select the two argument strings,
// run the user tool and close the new file without saving it.
UltraEdit.newFile();
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
UltraEdit.activeDocument.write('"'+UltraEdit.document[nDocIndex1].path+'" "'+UltraEdit.document[nDocIndex2].path+'"');
UltraEdit.activeDocument.selectToTop();
UltraEdit.runTool("BeyondCompare");
UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
}
else
{
if (!bFileNamed1) UltraEdit.outputWindow.write("Error: File "+UltraEdit.document[nDocIndex1].path+" is a new, unnamed file.");
if (!bFileNamed2) UltraEdit.outputWindow.write("Error: File "+UltraEdit.document[nDocIndex2].path+" is a new, unnamed file.");
UltraEdit.outputWindow.showWindow(true);
}
}
else
{
UltraEdit.outputWindow.write("Error: There must be opened at least two named files.");
UltraEdit.outputWindow.showWindow(true);
}
The script selects the file left to active file if the active file is the last one in documents array, i.e. is the last one on file tabs bar. The script also checks if both files are not new, unnamed files as in this case the files can't be compared with Beyond Compare without first saving the files in a directory.
I have one more suggestion: The user tool runs the C# application written by you. So it would be also possible to pass the two full qualified file names from script via Windows clipboard to the C# application started as user tool. This would have the advantage that file names with one or more Unicode characters could be also passed to your self-coded application and there is not always a new file created temporarily.