This will allow you to take a decimal number and convert it to hexadecimal and an hexadecimal and convert it to decimal all from a keyboard shortcut or right click context menu. (15 to 0xF or 0xF to 15 as an example)
Place functions below in SciteStartup.lua (Accessed via Options > Open Lua Startup Script)
Code: Select all
-- SciteConvertDecHex
-- Convert the selected text to decimal or hex
-- 2013.04.06 by lee.sheen at gmail dot com
function IsHexString (s)
local header = string.sub(s, 1, 2)
if "0x" == header or "0X" == header then
return true
else
return false
end
end
function ConvertDecHex ()
local current_selected_text, current_selected_length = editor:GetSelText()
local converted_number = tonumber(current_selected_text)
if not (converted_number == nil) then
local converted_text = nil
if IsHexString(current_selected_text) then
converted_text = tostring(converted_number)
else
converted_text = string.format("0x%X", converted_number)
end
editor:ReplaceSel(converted_text)
end
end
##########
# SCITEGlobal.properties
##########
Find: ext.lua.startup
Below it you will see:
ext.lua.auto.reload=1
#ext.lua.reset=0
where ext.lua.auto may or may not be commented out, I can not remember if it is by default,
I may have uncommented it in my experiments. But below these place the following bit:
Code: Select all
command.name.1.*=Convert Dec Hex
command.subsystem.1.*=3
command.1.*=ConvertDecHex
command.mode.1.*=savebefore:no
command.shortcut.1.*=Alt+Shift+C
The following are additional keyboard shortcuts, many of which I copy and pasted from a blog (http://the-automator.com/scite-hotkeys/) I found and pruned out a few but not all the ones I don't use so, feel free to remove whichever ones you do not want.
Place in SCITEUser.properties (accessed via Options > Open User Options File)
Code: Select all
#******************User defined hot key commands*****************
user.shortcuts=\
Ctrl+Shift+V|IDM_PASTEANDDOWN|\
Ctrl+PageUp|IDM_PREVFILE|\
Ctrl+PageDown|IDM_NEXTFILE|\
Ctrl+Shift+Right|IDM_SWITCHPANE|\
Ctrl+Shift+Left|IDM_SWITCHPANE|\
Ctrl+Alt+c|IDM_COPYASRTF|\
Ctrl+F1|IDM_HELP_SCITE|\
Ctrl+PageUp|IDM_PREVFILE|\
Ctrl+PageDown|IDM_NEXTFILE|\
Ctrl+t|IDM_TOGGLEOUTPUT|\
Ctrl+Shift+t|IDM_SHOWCALLTIP|\
Ctrl+Shift+u|IDM_OPENUSERPROPERTIES|\
Ctrl+Escape|IDM_STOPEXECUTE|\
Alt+Shift+C|ConvertDecHex()|\
##################All comments need to be at end
#*****************User hotkeys end**************************************
These are additional context menu short cuts I find useful, feel free to pull out whichever you do not want. These are also placed in the SCITEUser.properties file.
Code: Select all
#******************CONTEXT MENU*************************************.
# Add items to SciTE's context menu (right click menu) #get others here: http://www.scintilla.org/CommandValues.html
user.context.menu=\
||\
Duplicate |IDM_DUPLICATE|\
||\
Save File |IDM_SAVE|\
Save File As |IDM_SAVEAS|\
Save a Copy |IDM_SAVEACOPY|\
||\
View White Space|IDM_VIEWSPACE|\
View End of Line|IDM_VIEWEOL|\
||\
Open File of Path Selected (no quotes) |IDM_OPENSELECTED|\
Copy as RTF |IDM_COPYASRTF|\
Copy Path of THIS File|IDM_COPYPATH|\
||\
Clear Output Pane |IDM_CLEAROUTPUT|\
Toggle Output Pane |IDM_TOGGLEOUTPUT|\
||\
Convert Decimal to Hexadecimal |1101|\
||\
Make Uppercase |IDM_UPRCASE|\
Make Lowercase |IDM_LWRCASE|\
||\
Compile Script |IDM_COMPILE|\
Note 2: You may need to restart scite one all these things have been added, I did not but you never know.
Note 3: The shortcut for converting a number from hexadecimal to decimal and vise versa is set to Alt Shift C and accessible though the context menu (right click menu), the number must be highlighted in either case.
As always back up your stuff before dropping any of this stuff in.
Hope it helps.