ip74 wrote:What do you all think about the feature "Hex Insert/Delete" in "Hex Functions" menu?
Not much.
Hex Insert/Delete works as designed and described in help of UltraEdit.
But I try once again to encourage you using an UltraEdit script now after knowing better what you want.
I suggest a solution which replaces command
Paste by an enhanced version customized for your needs.
- Open a new file in UltraEdit with Ctrl+N and make sure that the file is an ASCII/ANSI file with DOS line terminators.
See indications on status bar at bottom of UltraEdit main window and use the appropriate commands in File - Conversions in case of having a different encoding or different line termination type configured for new files.
- Copy & paste following script code into the new file.
Code: Select all
// Is any file opened in UltraEdit / UEStudio?
if (UltraEdit.document.length > 0)
{
// Is active file opened in hex edit mode?
if (UltraEdit.activeDocument.isHexModeOn())
{
// Does the active clipboard contain only hexadecimal values in
// ASCII with always exactly two hexadecimal characters per byte
// and without or with whitespaces around them?
if (UltraEdit.clipboardContent.search(/^\s*(?:[0-9A-Fa-f]{2}\s*)+$/) == 0)
{
// Get the hexadecimal values in ASCII without the whitespaces.
var sHexAscii = UltraEdit.clipboardContent.replace(/\s+/g,"");
// Clear the clipboard.
UltraEdit.clearClipboard();
// Write to clipboard the bytes according to hexadecimal values.
for (var nCharIndex = 0; nCharIndex < sHexAscii.length; nCharIndex += 2)
{
var nByteValue = parseInt(sHexAscii.substr(nCharIndex,2),16);
UltraEdit.clipboardContent += String.fromCharCode(nByteValue);
}
}
}
// Execute paste command independent on editing mode and
// clipboard content was modified by the script at all.
UltraEdit.activeDocument.paste();
}
You can remove all comment lines starting with // after 0 or more spaces to make execution a little bit faster.
- Using command File - Save As and store the file for example with name SmartHexPaste.js into a directory of your choice, for example %APPDATA%\IDMComp\UltraEdit\scripts whereby subdirectory scripts must be most likely created first within Save As dialog.
- Close the script file and click on menu item Scripts in menu Scripting.
- Click on button Add, browse to just saved script file, select it, enter in field Description for example
Pastes hexadecimal values in ASCII as binary in hex edit mode
(optional, not required) and click on button Open.
- Double click with primary mouse button into cell of column Hotkey in row of just added script, press Ctrl+V and then click into any other cell with primary mouse button to assign this hotkey to the script. Click on button OK to save modified list and close the Scripts dialog.
- Although it is not really necessary, it is best to open now Advanced - Configuration - Key Mapping, navigate in list of Commands to the command EditPaste, and click on button Remove to remove Ctrl+V as hotkey for this command.
- Click next on configuration tree on Scripting and uncheck setting Show status information in output window which disables overwriting current contents of active output window by status and error information output usually to output window on running a script. Uncheck also setting Show cancel dialog in same configuration dialog.
- Close the configuration dialog with a click on button OK to take over changed key mapping and scripting configuration settings which are saved on next exit of UltraEdit also into uedit*.uek and uedit*.ini file (or Windows registry).
Whenever you press now Ctrl+V, the script is executed resulting in doing the paste from clipboard in most cases. There is no difference to built-in paste for a paste in text edit mode in standard or column editing mode with insert or overstrike mode and with or without having a selection as the script executes in those modes simply the command
Paste. Also Ctrl+V in hex edit mode is in most cases just a simple
Paste.
But if
- hex edit mode is enabled for active file
AND
- the active clipboard contains an ASCII text with hexadecimal values without or with whitespaces (space, tab, carriage return, line-feed, ...) between and/or around the ASCII representation of the hexadecimal values
the script modifies content of active clipboard before executing the paste. The ASCII text with the hexadecimal values are converted to bytes in clipboard before doing the paste.
The clipboard content is not modified if both conditions are not true for example if clipboard contains
B CD 12 34 or
AB CD 12 3 or other characters than whitespaces, digits and the letters A-F in any case.
It is of course also possible to assign a chord (multi-key assignment) or a different hotkey than Ctrl+V to the script if you don't want to replace standard command
Paste by the smart hex paste via the script.
Here is a variant of above script without comments which restores original clipboard content after binary paste in hex edit mode.
Code: Select all
if (UltraEdit.document.length > 0)
{
var sClipboardContent = "";
if (UltraEdit.activeDocument.isHexModeOn())
{
if (UltraEdit.clipboardContent.search(/^\s*(?:[0-9A-Fa-f]{2}\s*)+$/) == 0)
{
sClipboardContent = UltraEdit.clipboardContent;
var sHexAscii = UltraEdit.clipboardContent.replace(/\s+/g,"");
UltraEdit.clearClipboard();
for (var nCharIndex = 0; nCharIndex < sHexAscii.length; nCharIndex += 2)
{
var nByteValue = parseInt(sHexAscii.substr(nCharIndex,2),16);
UltraEdit.clipboardContent += String.fromCharCode(nByteValue);
}
}
}
UltraEdit.activeDocument.paste();
if (sClipboardContent.length) UltraEdit.clipboardContent = sClipboardContent;
}
Both scripts require UltraEdit for Windows >= 14.20 or UEStudio >= v9.00.