home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
KEYS.PEL
< prev
next >
Wrap
Text File
|
1995-02-10
|
67KB
|
2,301 lines
# $Header: P:\source\wmacros\keys.pev 1.77 10 Feb 1995 12:32:14 PFHJXM0 $
##############################################################################
#
# Compuware Corporation
# 31440 Northwestern Highway
# Farmington Hills, Michigan 48334-2564
#
# This source code listing contains information that is
# proprietary to Compuware Corporation and may not be copied
# duplicated, translated, transmitted, stored, retrieved
# or in any manner or by any method conveyed or disclosed
# to a third party or parties without express written
# permission from Compuware Corporation.
#
#
##############################################################################
#### $Workfile: keys.pel $: Key binding code
#
#
## keyboard status keys:
global KB_SHIFTR = 0x01
global KB_SHIFTL = 0x02
global KB_CTRL = 0x04
global KB_ALT = 0x08
global KB_SCROLL_LOCK = 0x10
global KB_NUM_LOCK = 0x20
global KB_CAPS_LOCK = 0x40
global KB_INSERT = 0x80
## the following codes ambiguously define the equivalent
## keys on the two auxiliary "cursor" keypads:
global KEYCODE_HOME
global KEYCODE_UP
global KEYCODE_PAGEUP
global KEYCODE_LEFT
global KEYCODE_CENTER
global KEYCODE_RIGHT
global KEYCODE_END
global KEYCODE_DOWN
global KEYCODE_PAGEDOWN
global KEYCODE_CTRL_HOME
global KEYCODE_CTRL_UP
global KEYCODE_CTRL_PAGEUP
global KEYCODE_CTRL_LEFT
global KEYCODE_CTRL_CENTER
global KEYCODE_CTRL_RIGHT
global KEYCODE_CTRL_END
global KEYCODE_CTRL_DOWN
global KEYCODE_CTRL_PAGEDOWN
global KEYCODE_NUM_HOME
global KEYCODE_NUM_UP
global KEYCODE_NUM_PAGEUP
global KEYCODE_NUM_LEFT
global KEYCODE_NUM_RIGHT
global KEYCODE_NUM_END
global KEYCODE_NUM_DOWN
global KEYCODE_NUM_PAGEDOWN
global KEYCODE_CTRL_NUM_HOME
global KEYCODE_CTRL_NUM_UP
global KEYCODE_CTRL_NUM_PAGEUP
global KEYCODE_CTRL_NUM_LEFT
global KEYCODE_CTRL_NUM_RIGHT
global KEYCODE_CTRL_NUM_END
global KEYCODE_CTRL_NUM_DOWN
global KEYCODE_CTRL_NUM_PAGEDOWN
global KEYCODE_ESC
## other useful keycodes:
global KEYCODE_TAB
global KEYCODE_ENTER
global KEYCODE_SHIFT
global KEYCODE_CTRL
global KEYCODE_ALT
global KEYCODE_ESC
global KEYCODE_END
global KEYCODE_KEYPAD_ENTER
global KEYCODE_F1
global KEYCODE_F2
global KEYCODE_F3
global KEYCODE_F4
global KEYCODE_F5
global KEYCODE_F6
global KEYCODE_F7
global KEYCODE_F8
global KEYCODE_F9
global KEYCODE_F10
global KEYCODE_F11
global KEYCODE_F12
global KEYCODE_CTRL_AT # Ctrl-@ (== ctrl-2), ascii byte is 0
global KEYCODE_CTRL_R
global KEYCODE_ALT_1
global KEYCODE_ALT_2
global KEYCODE_ALT_3
global KEYCODE_ALT_4
global KEYCODE_ALT_5
global KEYCODE_ALT_6
global KEYCODE_ALT_7
global KEYCODE_ALT_8
global KEYCODE_ALT_9
global KEYCODE_ALT_0
## useful ascii codes:
global ASCII_BACKSPACE = 8
global ASCII_TAB = 9
global ASCII_ENTER = 10
global ASCII_CR = 13
global ASCII_ESC = 27
local EOF = -1 # value returned upon EOF
local keystroke
local symbol_list[]
local addToBindings[]
global function setup_global_keycodes()
{
# keys on the two auxiliary "cursor" keypads:
KEYCODE_HOME = key_to_int("<Home>")
KEYCODE_UP = key_to_int("<Up>")
KEYCODE_PAGEUP = key_to_int("<PageUp>")
KEYCODE_LEFT = key_to_int("<Left>")
KEYCODE_CENTER = key_to_int("<Num-5>")
KEYCODE_RIGHT = key_to_int("<Right>")
KEYCODE_END = key_to_int("<End>")
KEYCODE_DOWN = key_to_int("<Down>")
KEYCODE_PAGEDOWN = key_to_int("<PageDown>")
KEYCODE_CTRL_HOME = key_to_int("<Ctrl-Home>")
KEYCODE_CTRL_UP = key_to_int("<Ctrl-Up>")
KEYCODE_CTRL_PAGEUP = key_to_int("<Ctrl-PageUp>")
KEYCODE_CTRL_LEFT = key_to_int("<Ctrl-Left>")
KEYCODE_CTRL_CENTER = key_to_int("<Ctrl-Num-5>")
KEYCODE_CTRL_RIGHT = key_to_int("<Ctrl-Right>")
KEYCODE_CTRL_END = key_to_int("<Ctrl-End>")
KEYCODE_CTRL_DOWN = key_to_int("<Ctrl-Down>")
KEYCODE_CTRL_PAGEDOWN = key_to_int("<Ctrl-PageDown>")
KEYCODE_NUM_HOME = key_to_int("<Num-Home>")
KEYCODE_NUM_UP = key_to_int("<Num-Up>")
KEYCODE_NUM_PAGEUP = key_to_int("<Num-PageUp>")
KEYCODE_NUM_LEFT = key_to_int("<Num-Left>")
KEYCODE_NUM_RIGHT = key_to_int("<Num-Right>")
KEYCODE_NUM_END = key_to_int("<Num-End>")
KEYCODE_NUM_DOWN = key_to_int("<Num-Down>")
KEYCODE_NUM_PAGEDOWN = key_to_int("<Num-PageDown>")
KEYCODE_ALT_1 = key_to_int("<ALT-1>")
KEYCODE_ALT_2 = key_to_int("<ALT-2>")
KEYCODE_ALT_3 = key_to_int("<ALT-3>")
KEYCODE_ALT_4 = key_to_int("<ALT-4>")
KEYCODE_ALT_5 = key_to_int("<ALT-5>")
KEYCODE_ALT_6 = key_to_int("<ALT-6>")
KEYCODE_ALT_7 = key_to_int("<ALT-7>")
KEYCODE_ALT_8 = key_to_int("<ALT-8>")
KEYCODE_ALT_9 = key_to_int("<ALT-9>")
KEYCODE_ALT_0 = key_to_int("<ALT-0>")
KEYCODE_CTRL_NUM_HOME = key_to_int("<Ctrl-Num-Home>")
KEYCODE_CTRL_NUM_UP = key_to_int("<Ctrl-Num-Up>")
KEYCODE_CTRL_NUM_PAGEUP = key_to_int("<Ctrl-Num-PageUp>")
KEYCODE_CTRL_NUM_LEFT = key_to_int("<Ctrl-Num-Left>")
KEYCODE_CTRL_NUM_RIGHT = key_to_int("<Ctrl-Num-Right>")
KEYCODE_CTRL_NUM_END = key_to_int("<Ctrl-Num-End>")
KEYCODE_CTRL_NUM_DOWN = key_to_int("<Ctrl-Num-Down>")
KEYCODE_CTRL_NUM_PAGEDOWN = key_to_int("<Ctrl-Num-PageDown>")
KEYCODE_ESC = key_to_int("<Esc>")
## other useful keycodes:
KEYCODE_TAB = key_to_int("<Tab>")
KEYCODE_ENTER = key_to_int("<Enter>")
KEYCODE_SHIFT = key_to_int("<Shift>")
KEYCODE_CTRL = key_to_int("<Ctrl>")
KEYCODE_ALT = key_to_int("<Alt>")
KEYCODE_ESC = key_to_int("<Esc>")
KEYCODE_END = key_to_int("<End>")
KEYCODE_KEYPAD_ENTER = key_to_int("<Num-Enter>")
KEYCODE_F1 = key_to_int("<F1>")
KEYCODE_F2 = key_to_int("<F2>")
KEYCODE_F3 = key_to_int("<F3>")
KEYCODE_F4 = key_to_int("<F4>")
KEYCODE_F5 = key_to_int("<F5>")
KEYCODE_F6 = key_to_int("<F6>")
KEYCODE_F7 = key_to_int("<F7>")
KEYCODE_F8 = key_to_int("<F8>")
KEYCODE_F9 = key_to_int("<F9>")
KEYCODE_F10 = key_to_int("<F10>")
KEYCODE_F11 = key_to_int("<F11>")
KEYCODE_F12 = key_to_int("<F12>")
KEYCODE_CTRL_AT = key_to_int("<Ctrl-2>")
KEYCODE_CTRL_R = key_to_int("<Ctrl-R>")
}
### program a key to playback a recorded sequence
#
local learning # semaphore for recursive calls to learn_key
local learned_key # array of key->playback string associations
global function learn_key() #PUBLIC #VOID
{
local learn_name # name of key being learned
local key
local binding
# a recursive call to this function ends the recording process
if ( learning )
{
process_end()
return
}
# prompt for the key to learn and get the name
optional_function( "enable_status_bar_messages" )
notify( "Press key to be recorded" )
key = getKey()
optional_function( "restore_status_bar" )
if ( key == EOF )
{
message( "Cancelled." )
return
}
# get the name of the key to learn
learn_name = key_name( key )
# make sure it is alright to overwrite the previous binding
binding = keymap_binding( learn_name )
if ( binding )
{
binding = sprintf( "%s is bound to %s; redefine?", learn_name, binding )
if ( tolower( confirm( binding, "YyNn" )) != "y" )
{
message( "Canceled." )
return
}
}
assign_key( learn_name, "learn_key" ) # terminator
optional_function( "enable_status_bar_messages" )
notify( "Recording key sequence for %s...press %s again to terminate", \
learn_name, learn_name )
while ( !keyboard_input_pending )
idle()
optional_function( "restore_status_bar ")
# enable recording
record( 1 )
learning = 1 # recursion flag
process_begin()
# we continue here after the process_end, which will happen during
# the next recursive call to learn_key().
learning = 0
# create a key binding for the learned sequence
learned_key[ key ] = record( 0 )
assign_key( learn_name, "playback_learn_key" )
notify( "Reprogrammed %s Key", learn_name )
}
global function playback_learn_key()
{
playback( learned_key[ current_key ])
}
### print statistics about keys as they are entered
#
global function print_keys()
{
local key
optional_function( "enable_status_bar_messages" )
notify( "Press keys to be printed..." )
while(( key = getKey()) != EOF )
{
notify( "Keycodes: 0x%04x #%05u (%03u) \"%s\"", \
key, \
key, \
int_to_ascii(key), \
key_name( key ))
}
message( "" )
optional_function( "restore_status_bar ")
}
global function print_chars()
{
local key
optional_function( "enable_status_bar_messages" )
notify( "Press keys to be printed..." )
while(( key = getchar()) != ASCII_ESC )
{
notify( "Keycodes: 0x%04x #%05u (%03u) \"%s\"", \
key, \
key, \
int_to_ascii(key), \
key_name( key ))
}
message( "" )
optional_function( "restore_status_bar ")
}
### read a key and print its binding
#
local reentrant_print_bindings = 0
global function print_bindings()
{
local seq, key
# don't allow reentering the print_bindings if we
# are already in here
if ( reentrant_print_bindings )
{
# just in case message has disappeared
notify( "Press keys to be looked-up..." )
return;
}
reentrant_print_bindings = 1
optional_function( "enable_status_bar_messages" )
notify( "Press keys to be looked-up..." )
while(( key = getKey()) != EOF )
{
seq = key_encoding( key, 1 )
notify( "0x%04x #%05u (%03u) \"%s\" is bound to %s",\
key, \
key, \
int_to_ascii(key), \
key_name( key ), \
keymap_binding( seq ))
}
message( "" )
optional_function( "restore_status_bar" )
reentrant_print_bindings = 0
}
## display names of keys bound to a specified function
#
global function function_binding_key( functionName, noBrackets, plus, noShow )
{
local fid
local list, arry, keynum, i
local element, delimiter, msg
# prompt for function name if not specified
if (!functionName)
functionName = prompt_history( "XMACRO", "Enter function name: ", "", 1, 1, "function_binding_dialog" )
# invoke function_binding to get list of keys in #number form
if (( fid = function_id( functionName )))
{
list = function_binding( fid )
# look up key name corresponding to each #number
split( list, arry, "#" )
for ( i in arry )
{
element = arry[i]
delimiter = (element ~ / $/) ? " | " : ""
if (( keynum = 0+arry[i] ))
{
element = int_to_key( keynum, plus )
# remove the angle brackets
#
if ( noBrackets )
{
gsub("\\<", "", element)
gsub("\\>", "", element)
}
# append new key and delimiter to list of keys
#
msg = msg element delimiter
}
}
# display the list of keys on status bar
#
if (!noShow)
notify( "\"%s\" keys: %s", functionName, msg )
}
return msg
}
##
#
global function list_keymap( format, noBrackets, plus )
{
local i
local j
local len
local str
local fid
local keys
local list
local arry
local count
local keynum
local txtfile
local symbol_list
local LIST_LENGTH = 30
local cb = current_buffer
# coerce format to a number.
format = tolower(format)
if (format == 2 || prefix(format, 1) == "p" || format ~ "pel")
format = 2
else if (format == 1 || prefix(format, 1) == "c" || format ~ "cfg")
format = 1
else
format = 0
# coerce other params to numbers.
noBrackets = noBrackets+0
plus = plus+0
# search cpe path for the help menu file
if ( !(txtfile = locate_cpe_file(CPE_FILE_KEYMAP)))
txtfile = editor_path(CPE_FILE_KEYMAP)
if (format == 2)
txtfile = bld_fnam(txtfile, txtfile, "pel")
else if (format)
txtfile = bld_fnam(txtfile, txtfile, "cfg")
current_buffer = create_buffer( txtfile, txtfile, BUFFER_SCRATCH )
if (buffer_size)
{
goto_buffer_top()
begin_selection( LINE_SELECTION )
goto_buffer_bottom()
delete_chars()
}
# in case symbol_match takes a long time
if ( status_bar_flags )
message( "Working..." )
# read a list of all primitives & global functions.
symbol_list = symbol_match("", PRIMITIVE_FUN + GLOBAL_FUN)
if (symbol_list)
{
for (i in symbol_list)
{
str = symbol_list[i]
if (str != "insert_key")
{
if (format)
{
if (( fid = function_id( str )))
{
list = function_binding( fid )
# look up key name corresponding to each #number
split( list, arry, "#" )
for ( j in arry )
{
if (( keynum = 0+arry[j] ))
{
if (format == 2) # PEL File Format
{
insert_string("\tassign_key(\"" \
int_to_key( keynum, plus ) \
"\", \"" str "\")" )
insert_newline()
}
else # Config file format
{
insert_string("assign_key \"" \
int_to_key( keynum, plus ) \
"\" \"" str "\"" )
insert_newline()
}
}
}
}
}
else # Text Report Format
{
keys = function_binding_key(str, noBrackets, plus, TRUE)
if (keys && length(keys))
{
len = length(str)
if (len < LIST_LENGTH)
str = str strrepeat(" ", LIST_LENGTH - len)
insert_string(str " : " keys)
insert_newline()
if (count++ > 10)
{
update_current_view()
count = 0
}
}
}
}
}
if ( status_bar_flags )
message( "Working........." )
filter("sort")
goto_buffer_top()
buffer_flags = and(buffer_flags, not(BUFFER_MODIFIED))
}
else
{
notify( "Cannot find keymap information")
delete_buffer( current_buffer )
current_buffer = cb
}
if ( status_bar_flags )
message( "" )
}
### read a key and insert the corresponding "#"-sequence
#
global function insert_keys()
{
local key
local str
local priorWindow = current_window
optional_function( "enable_status_bar_messages" )
notify( "Press keys to be converted and inserted..." )
while(( key = getKey()) != EOF )
{
if(( str = key_encoding( key, 1 )))
{
if (priorWindow)
current_window = priorWindow
insert_string( str )
## raise_window( dialog_window )
update_current_view()
}
else
break
}
# remove temp dialog window if we created one above
message( "" )
optional_function( "restore_status_bar ")
}
### Read keys from the keyboard and insert them into the buffer if
# they represent valid ASCII characters.
#
# See also: insert_quoted_key() # singluar
local reentrant_insert_quoted_keys = 0
global function insert_quoted_keys()
{
local key
local ascii
local priorWindow = current_window
# don't allow reentering the insert_quoted_keys if we
# are already in here
if ( reentrant_insert_quoted_keys )
{
# just in case message has disappeared
notify( "Press ASCII keys to be inserted..." )
return;
}
reentrant_insert_quoted_keys = 1
optional_function( "enable_status_bar_messages" )
notify( "Press ASCII keys to be inserted..." )
while(( key = getKey()) != EOF )
{
notify( "Press ASCII keys to be inserted..." )
ascii = int_to_ascii(key)
if ( (ascii == 0 && key != KEYCODE_CTRL_AT) ||
(ascii == 0xe0 && key != ascii) )
{
warning( "non-ASCII key ignored" )
}
else
{
if (priorWindow)
current_window = priorWindow
if (ascii == ASCII_TAB)
insert_string( "\t" )
else
insert_key( ascii )
## raise_window( dialog_window )
update_current_view()
}
}
# remove temp dialog window if we created one above
message( "" )
optional_function( "restore_status_bar" )
reentrant_insert_quoted_keys = 0
}
### Read the next key from the keyboard and insert it into the buffer if
# it represents a valid ASCII character.
#
# See also: insert_quoted_keys() # plural
local reentrant_insert_quoted_key = 0
global function insert_quoted_key()
{
local key, ascii
local priorWindow = current_window
# don't allow reentering the insert_quoted_key if we
# are already in here
if ( reentrant_insert_quoted_key )
{
# just in case message has disappeared
notify( "Press ASCII key to be inserted..." )
return;
}
reentrant_insert_quoted_key = 1
optional_function( "enable_status_bar_messages" )
notify( "Press ASCII key to be inserted..." )
if (( key = getKey()) != EOF )
{
ascii = int_to_ascii(key)
if ( (ascii == 0 && key != KEYCODE_CTRL_AT) ||
(ascii == 0xe0 && key != ascii) )
{
warning( "non-ASCII key ignored" )
}
else
{
if (priorWindow)
current_window = priorWindow
if (ascii == ASCII_TAB)
insert_string( "\t" )
else
insert_key( ascii )
message( "" )
}
}
# remove temp dialog window if we created one above
optional_function( "restore_status_bar" )
reentrant_insert_quoted_key = 0
}
### convert a keycode to a "#"-sequence
#
global function key_encoding( key, distinguish )
{
if( distinguish )
return sprintf( "#%u", key )
else
return sprintf( "#%u", int_to_ascii(key) )
}
### returns the name of a key given a key code
#
global function key_name( keycode )
{
local ascii
# strip off the leading '#' if necessary
if ( keycode ~ /^#/ )
{
keycode = substr( keycode, 2 )
}
# there was code here that used the key_names[] array. int_to_key() seems
# much easier to use
return int_to_key( keycode )
}
## Return a keycode from the keyboard, waiting until a key is actually pressed.
# Escape prompts the user to return either the escape keycode or EOF.
local function getKey(esc_ok)
{
local ch, resp
ch = getkey()
if ( argcount() && esc_ok)
return ch
else if ( ( ch == KEYCODE_ESC ) &&
tolower(confirm( "Terminate key sequence? ", "YyNn\r" )) != "n")
{
return EOF
}
else
return ch
}
## Prompts the user to press a key and returns the Keycode pressed.
global function getKeystroke(text, handle)
{
local char
local id = function_id( "key_pressed" );
attach_event_handler( EVENT.INVALID_PCHAR, id )
keystroke = 0
char = confirm( text, "", handle )
if (!keystroke)
{
if (char == " ")
keystroke = key_to_int("<Space>")
else
keystroke = key_to_int(char)
}
delete_event( EVENT.INVALID_PCHAR, id )
return keystroke
}
global function key_pressed()
{
keystroke = current_key
current_key = KEYCODE_ESC
}
#----------------------------------------------------------------------
### view or edit the current key bindings
#
local IDM_FIRST_ITEM = 3809
local IDM_NEXT = 3809
local IDM_PREV = 3810
local IDM_DEL = 3811
local IDM_INS = 3812
local IDM_WIN = 3813
local IDM_EXIT_KEYS = 3814
local IDM_MKEYS = 3815
local IDM_LAST_ITEM = 3815
local bindingsInitialized = 0
local currentFunction = ""
local keysRead = 0
local bindingListBuffer
local bindingDispBuffer
local bindingListWindow
local bindingDispWindow
local lastBindingLine
local startingKeymap
local bindingKeymap
local windowHeight
local keyBindings[]
local deletedKeys[]
local insertedKeys[]
local old_window
local old_buffer
local old_mdi_mode
local old_toolbar
local old_menu
local function binding_init()
{
local i
local len
local str
local line
local eol_str
local txtfile
local buffOff
local symbol_list
local cb = current_buffer
# retrieve the current user key assignments from the config file.
#
if (!keysRead)
{
delete( keyBindings )
delete( deletedKeys )
delete( insertedKeys )
read_key_assignments()
keysRead = TRUE;
}
# search cpe path for the help menu file
if ( !(txtfile = locate_cpe_file(CPE_FILE_BINDINGS)))
txtfile = editor_path( CPE_FILE_BINDINGS )
eol_str = default_buffer_eol_string
default_buffer_eol_string = "\r\n"
current_buffer = \
bindingListBuffer = create_buffer( txtfile, txtfile, BUFFER_SYSTEM + \
BUFFER_NO_UNDO )
default_buffer_eol_string = eol_str
if (buffer_size)
{
while(current_line < buffer_last_line)
{
line = read_buffer(1)
if (line == "#")
delete_line()
else
down()
}
goto_buffer_top()
}
else
{
# couldn't find the help information
# in case symbol_match takes a long time
if ( status_bar_flags )
message( "Working..." )
# read a list of all primitives & global functions.
symbol_list = symbol_match("", 0x05)
if (symbol_list)
{
for (i in symbol_list)
{
insert_string(symbol_list[i])
insert_newline()
}
}
else
{
# couldn't find the help information
notify( "Cannot find binding information in: %s", txtfile )
current_buffer = cb
delete_buffer( bindingListBuffer )
return FALSE
}
}
filter("sort")
if ( status_bar_flags )
message( "" )
bindingDispBuffer = create_buffer( "Binding", "", \
BUFFER_SYSTEM+BUFFER_NO_UNDO)
current_buffer = cb
message( "" )
return TRUE
}
global function keys()
{
local i
local width
old_window = current_window
old_buffer = current_buffer
if (!bindingsInitialized)
{
if ( binding_init() )
bindingsInitialized = 1
else
return
}
optional_function( "enable_status_bar_messages" )
lastBindingLine = 0
startingKeymap = current_keymap
bindingKeymap = create_keymap( empty_keymap )
push_keymap( bindingKeymap )
# hide toolbar and change menus during keys
#
old_toolbar = optional_function( "toggle_toolbar", 0 )
# Turn MDI on,
#
old_mdi_mode = mdi_mode
if (!old_mdi_mode)
{
optional_function( "switch_to_mdi" )
delete_window( current_window )
}
keys_menu()
old_menu = change_menu(menu)
# calculate the window sizes.
#
windowHeight = display_height
width = display_width / 2
# create the list window and shadow which will contain the list of keys
# binding items
#
current_window = \
bindingListWindow = create_factory_window( 0, 0, width, windowHeight,
WINDOW_PLAIN + WINDOW_SYSTEM + \
WINDOW_VERT_SB )
window_name = "Functions"
# color_border = BAR_COLOR
# color_text = BAR_COLOR
attach_window_buffer( bindingListWindow, bindingListBuffer )
initBindingAttributes()
restore_window(bindingListWindow)
#
# create the display window and shadow which will contain the function names
#
current_window = \
bindingDispWindow = create_factory_window(width, 0, width, windowHeight, \
WINDOW_PLAIN + WINDOW_SYSTEM)
# color_border = BAR_COLOR
# color_text = BAR_COLOR
window_name = "Bindings"
initBindingAttributes()
attach_window_buffer( bindingDispWindow, bindingDispBuffer )
restore_window(bindingDispWindow)
current_window = bindingListWindow
goto_buffer_top()
begin_selection( LINE_SELECTION )
end_selection()
update_current_view()
updateBindItem()
# create a keymap for use in the keys windows
#
assign_key( "<Esc>", "exit_keys" )
assign_key( "<Home>", "bindHome" )
assign_key( "<End>", "bindEnd" )
assign_key( "<Up>", "bindUp 1" )
assign_key( "<Down>", "bindDown 1" )
assign_key( "<PageUp>", "bindPageUp" )
assign_key( "<PageDown>", "bindPageDown" )
assign_key( "<Tab>", "bindToggleWindow" )
assign_key( "<Left>", "bindToggleWindow 1" )
assign_key( "<Right>", "bindToggleWindow 0" )
assign_key( "<Alt-H>", "display_help_item keys" )
assign_key( "<Delete>", "bindDelete" )
assign_key( "<Insert>", "bindIns" )
# redefine the mouse actions.
#
attach_event_handler(EVENT.MOUSE_LEFT_DOWN, function_id("bindMouseDown"))
attach_event_handler(EVENT.MOUSE_LEFT_UP, function_id("updateBindItem"))
attach_event_handler(EVENT.LMOUSE_DRAG, function_id("bindMouseDown"))
attach_event_handler(EVENT.RESIZE_EDITWIN, function_id("bindResize"))
delete_event(EVENT.LMOUSE_DRAG, function_id("lmouse_drag"))
delete_event(EVENT.MOUSE_LEFT_DOWN, function_id("mouse_left_down"))
delete_event(EVENT.MOUSE_LEFT_UP, function_id("mouse_left_up"))
delete_event(EVENT.RESIZE_EDITWIN, function_id("resize_editwin"))
current_window = bindingDispWindow
bindToggleWindow( 1 )
# process_begin()
}
global function read_key_assignments()
{
local i
local p
local s
local key
local fun
local cmt
local data = read_config_section( "$KEY_ASSIGNMENTS$", 0, 1, 1 )
for (i in data)
{
s = data[i]
if (prefix(s, 11) == "assign_key ")
{
s = substr(s, 12)
p = cindex(s, " ")
key = unquote_string(substr(s, 2, p-3))
fun = substr(s, p+1)
# strip off surrounding quotes
if ( prefix(fun, 1) == "\"" && suffix(fun, 1) == "\"" )
fun = substr( fun, 2, length(fun) - 2 )
if (fun == "beep")
{
if (match(cmt, /\<.*\> was /))
deletedKeys[ key ] = substr(cmt, RSTART+RLENGTH)
else
deletedKeys[ key ] = "unknown"
}
else
insertedKeys[ key ] = fun
}
else if(prefix(s, 1) == "#")
cmt = s
}
}
global function exit_keys()
{
local i
# process_end()
pop_keymap()
saveKeys()
attach_event_handler(EVENT.LMOUSE_DRAG, function_id("lmouse_drag"))
attach_event_handler(EVENT.MOUSE_LEFT_DOWN, function_id("mouse_left_down"))
attach_event_handler(EVENT.MOUSE_LEFT_UP, function_id("mouse_left_up"))
attach_event_handler(EVENT.RESIZE_EDITWIN, function_id("resize_editwin"))
delete_event(EVENT.MOUSE_LEFT_DOWN, function_id("bindMouseDown"))
delete_event(EVENT.MOUSE_LEFT_UP, function_id("updateBindItem"))
delete_event(EVENT.LMOUSE_DRAG, function_id("bindMouseDown"))
delete_event(EVENT.RESIZE_EDITWIN, function_id("bindResize"))
delete_keymap( bindingKeymap )
delete_window( bindingListWindow )
delete_window( bindingDispWindow )
change_menu( old_menu )
# delete our local list that maps function id's to menu item
# id's. This list was created during the append_menuitem calls.
for ( i = IDM_FIRST_ITEM; i <= IDM_LAST_ITEM; i++ )
if ( i in menu_functions )
delete menu_functions[i]
delete_menu( submenu )
delete_menu( menu )
# Restore the MDI mode to it's previous value.
#
if (!old_mdi_mode)
optional_function( "switch_to_sdi" )
current_buffer = old_buffer
# re-enable both toolbar and menu
optional_function( "toggle_toolbar", old_toolbar )
current_key = 0
display_redraw()
optional_function( "restore_status_bar" )
message( "" )
}
#
# initialize the attribute and window names for the binding windows
# win == 1 setting display window, win == 2 setting list window
#
local function initBindingAttributes()
{
# color_highlight = HBAR_COLOR
visible_virtual_lines = ""
visible_virtual_spaces = ""
visible_end_buffer = ""
}
function showBindingItem( lineNum )
{
local cw = current_window
local ln
local i
local arr
local msg_lvl
if (current_window == bindingDispWindow)
return
delete( keyBindings )
goto_bol()
ln = read_buffer()
if (match(ln, chr(29)".*$"))
ln = suffix(ln, RLENGTH - 1)
goto_bol()
current_window = bindingDispWindow
goto_buffer_top()
while (delete_line())
continue
goto_bol()
if ((ln != "") && (!keyboard_input_pending))
{
msg_lvl = message_level
message_level = 2
currentFunction = ln
ln = function_binding( function_id( ln ), startingKeymap )
message_level = msg_lvl
split( ln, arr, " " ) + 1
for (i in arr)
{
ln = keyAssignmentName( arr[i] )
insert_string( ln )
keyBindings[ ln ] = arr[i]
if (i+1 in arr)
insert_newline()
}
}
goto_buffer_top()
current_window = cw
}
local function keyAssignmentName( str )
{
local keyarr
local i
local ln = ""
if (prefix(str, 1) == "<" && suffix(str, 1) == ">")
return str
else
{
split( str, keyarr, "#" )
for (i in keyarr)
{
if (keyarr[i])
ln = ln key_name( atoi(keyarr[i]) )
}
delete( keyarr )
return ln
}
}
global function bindResize()
{
local width, height
frame_window( 0, 0, display_width / 2, display_height, bindingListWindow )
frame_window( display_width / 2, 0, display_width / 2, display_height, \
bindingDispWindow )
}
global function bindMouseDown()
{
local line
if (current_window == bindingDispWindow)
bindToggleWindow( 0 )
else if (current_window == bindingListWindow)
bindToggleWindow( 1 )
line = mouse_event_y + window_first
if (line != mark_line(selection_mark_top()))
{
remove_selection()
update_current_view()
goto_pos(line, mouse_event_x + 1 )
begin_selection( LINE_SELECTION )
end_selection()
update_current_view()
}
}
function bindToggleWindow( left )
{
if (current_window == bindingDispWindow)
{
message( " , \x1a=window, <Esc>, <Ins>, <Alt-H>=HELP" )
if (argcount() && !(left+0))
return
remove_selection()
update_current_view()
current_window = bindingListWindow
}
else
{
message( " , \x1b=window, <Esc>, <Ins>, <Del> <Alt-H>=HELP" )
if (argcount() && left+0)
return
current_window = bindingDispWindow
begin_selection( LINE_SELECTION )
end_selection()
update_current_view()
}
}
global function bindHome()
{
remove_selection()
update_current_view()
current_line = 1
begin_selection( LINE_SELECTION )
end_selection()
update_current_view()
updateBindItem()
}
global function bindEnd()
{
remove_selection()
update_current_view()
current_line = 65535
begin_selection( LINE_SELECTION )
end_selection()
update_current_view()
updateBindItem()
}
global function bindPageUp()
{
remove_selection()
update_current_view()
page_up( 1 )
begin_selection( LINE_SELECTION )
end_selection()
update_current_view()
updateBindItem()
}
global function bindPageDown()
{
remove_selection()
update_current_view()
page_down( 1 )
begin_selection( LINE_SELECTION )
end_selection()
update_current_view()
updateBindItem()
}
global function bindDown( lines )
{
if ( down( lines ))
{
remove_selection()
update_current_view()
begin_selection( LINE_SELECTION )
end_selection()
update_current_view()
}
updateBindItem()
}
global function bindUp( lines )
{
if ( up( lines ))
{
remove_selection()
update_current_view()
begin_selection( LINE_SELECTION )
end_selection()
update_current_view()
}
updateBindItem()
}
global function bindDelete()
{
local ln
local kn
local fn
if (current_window == bindingDispWindow)
{
goto_bol()
kn = read_buffer()
ln = keyBindings[ kn ]
if (ln)
{
current_keymap = startingKeymap
fn = keymap_binding( ln )
assign_key( ln, "beep" )
current_keymap = bindingKeymap
if (ln in insertedKeys)
delete( insertedKeys[ ln ] )
else
deletedKeys[ kn ] = fn
delete_line()
if (read_buffer() == "")
backspace()
}
goto_bol()
}
else
beep()
}
local function waitForKey()
{
local ch
while ((ch = getkey()) == -1)
continue
return ch
}
global function bindIns()
{
local ch
local ln = ""
local kn
local switchWindows = (current_window == bindingListWindow)
if (switchWindows)
bindToggleWindow( 0 )
remove_selection()
update_current_view()
insert_newline()
up()
begin_selection( LINE_SELECTION )
end_selection()
update_current_view()
message( " <Esc>=discard, <Enter>=accept " )
ch = waitForKey()
while( (ch != KEYCODE_ENTER ) && (ch != KEYCODE_KEYPAD_ENTER ) \
&& (ch != KEYCODE_ESC))
{
kn = key_name( ch )
insert_string( kn )
ln = ln "#" ch
update_current_view()
ch = waitForKey()
}
if ( (ch == KEYCODE_ENTER) || (ch == KEYCODE_KEYPAD_ENTER) )
{
if ( !function_id( currentFunction ))
{
warning( "Assignment to nonexistent function: " currentFunction )
if (!pause_on_error)
ch = waitForKey()
goto_bol()
delete_line()
update_current_view()
}
else
{
current_keymap = startingKeymap
assign_key( ln, currentFunction )
current_keymap = bindingKeymap
goto_bol()
kn = read_buffer()
keyBindings[ kn ] = ln
if (kn in deletedKeys)
delete( deletedKeys[ kn ] )
insertedKeys[ ln ] = currentFunction
}
}
else
{
delete_line()
goto_bol()
if (read_buffer() == "")
backspace()
}
goto_bol()
if (switchWindows)
bindToggleWindow( 1 )
}
global function updateBindItem()
{
local cb = current_buffer
if (keyboard_input_pending == 0)
{
if (lastBindingLine != current_line)
{
showBindingItem( current_line )
lastBindingLine = current_line
}
}
}
local function saveKeys(save_now, handle)
{
local i
local fn
local index
local keyname
local save_keys
local cb = current_buffer
local found = FALSE
local searchFlag = 0x0034 # ignore case | regex | forward
for (i in insertedKeys)
{
found = TRUE
break
}
for (i in deletedKeys)
{
found = TRUE
break
}
if (found)
{
# search cpe path for the config file
if ( !(fn = locate_cpe_file(CPE_FILE_CONFIG)))
{
fn = editor_path( CPE_FILE_CONFIG )
}
if (argcount() && save_now)
i = "Y"
else
i = toupper(confirm("Save changes to the keymap in " fn " [yn]? ",
"yYnN", handle))
if (i == "Y")
{
for (i in deletedKeys)
{
if (deletedKeys[i] != "unknown")
save_keys[index++] = "# " i " was " deletedKeys[i] "\n"
}
for (i in insertedKeys)
{
if (!(i in deletedKeys))
save_keys[index++] = "assign_key \"" quote_string(keyAssignmentName(i)) "\" \"" \
insertedKeys[i] "\"\n"
}
save_keys[index++] = "fix_menu_keys\n"
update_config_section( "$KEY_ASSIGNMENTS$", save_keys )
return TRUE
}
}
return FALSE
}
global function fix_menu_keys()
{
local fid
if ((fid = function_id(emulation_mode "_menu")))
execute_function(fid)
else if ((fid = function_id(tolower(emulation_mode) "_menu")))
execute_function(fid)
else
optional_function( "fix_menu_text" )
}
local menu = 0
local submenu = 0
local function keys_menu()
{
menu = create_menu()
submenu = create_menu()
append_menuitem( submenu, IDM_PREV, 0x0408, "~Previous", "bindUp 1" )
append_menuitem( submenu, IDM_NEXT, 0x0408, "~Next", "bindDown 1" )
append_menuitem( submenu, 0, 0x0100)
append_menuitem( submenu, IDM_DEL, 0x0408, "~Delete", "bindDelete" )
append_menuitem( submenu, IDM_INS, 0x0408, "~Insert", "bindIns" )
append_menuitem( submenu, 0, 0x0100)
append_menuitem( submenu, IDM_EXIT_KEYS, 0x0408, "~Exit Keys", "exit_keys" )
append_menuitem( submenu, 0, 0x0100)
append_menuitem( submenu, IDM_WIN, 0x0408, "Switch ~Windows", "bindToggleWindow" )
append_menuitem( menu, IDM_MKEYS , 0x0208, "~Keys", submenu )
return menu
}
######################## KEYMAP BINDINGS DIALOG #############################
local IDD_KEY_BINDINGS = 1190
local IDT_FNAME = 1191
local IDB_BIND = 1192
local IDB_UNBIND = 1193
local IDT_FUNCTION_NAME = 1194
local IDB_SAVE = 1195
local IDC_CTRL_KEY = 1196
local IDC_ALT_KEY = 1197
local IDC_SHIFT_KEY = 1198
local IDC_NUM = 1199
local IDL_KEY_LIST = 1200
local IDL_KEYS = 1201
local IDL_COMMANDS = 1202
local IDB_SELECT = 1203
local IDB_FUNCTION_HELP = 1204
local IDE_PARMS = 1205
local IDB_SHOW_BINDINGS = 1206
local key_lists_created = 0
local selecting_key = 0
local keys_set = 0
local dhKeysDialog
global function keys_dialog()
{
set_busy_cursor()
dhKeysDialog = create_dialog(function_id( "keys_dialog_callback" ), 0,
IDD_KEY_BINDINGS, resource_dll)
attach_help(editor_helpfile, dhKeysDialog)
set_dialog_item(dhKeysDialog, IDL_KEYS, DAC_SORT_ASCENDING)
add_dialog_item(dhKeysDialog, IDL_KEY_LIST, DCTRL_COMBO_BOX)
set_dialog_item(dhKeysDialog, IDL_KEY_LIST, DAC_SORT_ASCENDING)
add_dialog_item(dhKeysDialog, IDL_COMMANDS, DCTRL_COMBO_BOX)
set_dialog_item(dhKeysDialog, IDL_COMMANDS, DAC_SORT_ASCENDING)
set_dialog_item(dhKeysDialog, IDT_FUNCTION_NAME, DAC_TEXT, "")
set_dialog_item(dhKeysDialog, IDT_FNAME, DAC_TEXT, "")
key_lists_created = FALSE
initialize_keys_dialog( dhKeysDialog )
set_normal_cursor()
begin_dialog(dhKeysDialog)
delete_dialog(dhKeysDialog)
key_lists_created = FALSE
}
global function initialize_keys_dialog( handle )
{
if (!key_lists_created)
{
# retrieve the current user key assignments from the config file.
#
if (!keysRead)
{
delete( keyBindings )
delete( deletedKeys )
delete( insertedKeys )
read_key_assignments()
keysRead = TRUE;
}
load_keys(handle)
load_commands(handle)
key_lists_created = TRUE
}
set_buttons(handle)
}
local function load_keys(handle)
{
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Alt")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Ctrl")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Shift")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Backspace")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "BackTab")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "CapsLock")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Delete")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Down")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Enter")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Execute")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "End")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Esc")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Home")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Insert")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Left")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Num Lock")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "PageUp")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "PageDown")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Right")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Space")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Tab")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Up")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F1")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F2")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F3")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F4")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F5")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F6")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F7")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F8")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F9")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F10")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F11")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F12")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F13")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F14")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F15")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F16")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F17")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F18")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F19")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F20")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F21")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F22")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F23")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F24")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "A")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "B")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "C")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "D")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "E")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "F")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "G")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "H")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "I")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "J")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "K")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "L")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "M")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "N")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "O")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "P")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Q")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "R")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "S")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "T")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "U")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "V")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "W")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "X")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Y")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "Z")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "1")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "2")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "3")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "4")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "5")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "6")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "7")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "8")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "9")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "0")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "-")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "=")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "[")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "]")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "\\")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, ";")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "'")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, ",")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, ".")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "/")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "`")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "!")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "@")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "#")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "$")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "%")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "^")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "&")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "*")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "(")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, ")")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "_")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "+")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "{")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "}")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "|")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, ":")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "\"")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "<")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, ">")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "?")
set_dialog_item(handle, IDL_KEY_LIST, DAC_ADD_ITEM, "~")
}
local function load_commands(handle)
{
local i
local len
local str
local size
local line
local func
local eol_str
local txtfile
local buffOff
local cb = current_buffer
if ( symbol_list )
{
for (i in symbol_list)
{
set_dialog_item(handle, IDL_COMMANDS, DAC_ADD_ITEM, symbol_list[i])
}
for (i in addToBindings)
{
set_dialog_item(handle, IDL_COMMANDS, DAC_ADD_ITEM, i )
}
}
else
{
# search cpe path for the help menu file
if ( !(txtfile = locate_cpe_file(CPE_FILE_BINDINGS)))
txtfile = editor_path( CPE_FILE_BINDINGS )
current_buffer = create_buffer( txtfile, txtfile, BUFFER_SYSTEM + \
BUFFER_NO_UNDO )
# couldn't find the help information
# in case symbol_match takes a long time
if ( status_bar_flags )
message( "Working..." )
if (buffer_size)
{
for(;current_line < buffer_last_line; down())
{
line = read_buffer()
if (line && length(line) && prefix(line, 1) != "#")
{
if (match(line, chr(29)".*$"))
func = suffix( line, RLENGTH - 1 )
else
func = line
set_dialog_item( handle, IDL_COMMANDS, DAC_ADD_ITEM, func )
symbol_list[ current_line ] = func
}
}
}
else
{
# read a list of all primitives & global functions.
symbol_list = symbol_match("", 0x05)
if (symbol_list)
{
for (i in symbol_list)
{
set_dialog_item(handle, IDL_COMMANDS, DAC_ADD_ITEM, symbol_list[i])
}
if ( status_bar_flags )
message( "" )
}
else
{
# couldn't find the help information
notify( "Cannot find binding information in: %s", txtfile )
}
}
delete_buffer()
}
current_buffer = cb
}
global function keys_dialog_callback()
{
local func
if ( ( callback_msg == DM_CLICK && callback_index == DI_HELP ) ||
( callback_msg == DM_HELPREQUESTED ) )
{
display_help("keys", callback_dialog_handle)
return DRC_MSG_PROCESSED
}
else if ( (callback_msg == DM_CLICK) )
{
if ( callback_index == IDB_SHOW_BINDINGS )
{
lookup_commands( callback_dialog_handle )
lookup_keys( callback_dialog_handle )
set_buttons( callback_dialog_handle )
}
else if ( callback_index == IDB_SELECT )
{
selecting_key = TRUE
optional_function( "disable_status_bar_prompts" )
getKeystroke("Press key to be bound...", callback_dialog_handle)
optional_function( "restore_status_bar" )
selecting_key = FALSE
select_key(callback_dialog_handle, key_name(keystroke))
func = keymap_binding( query_key_name( callback_dialog_handle ) )
set_dialog_item(callback_dialog_handle, IDT_FUNCTION_NAME, DAC_TEXT, func)
set_buttons(callback_dialog_handle)
}
else if ( callback_index == IDB_BIND )
{
bind_key(callback_dialog_handle)
}
else if ( callback_index == IDB_FUNCTION_HELP )
{
func = query_function_name(callback_dialog_handle)
if (length(func))
display_help_item(func)
}
else if ( callback_index == IDB_UNBIND )
{
unbind_key(callback_dialog_handle)
}
else if ( callback_index == IDB_SAVE )
{
saveKeys(TRUE)
keys_set = FALSE
}
else if ( callback_index == IDC_CTRL_KEY ||
callback_index == IDC_ALT_KEY ||
callback_index == IDC_SHIFT_KEY ||
callback_index == IDC_NUM )
{
set_buttons(callback_dialog_handle)
}
return DRC_MSG_PROCESSED
}
else if ( callback_msg == DM_SELECT )
{
if ( callback_index == IDL_KEY_LIST )
{
func = keymap_binding( query_key_name( callback_dialog_handle ) )
set_dialog_item(callback_dialog_handle, IDT_FUNCTION_NAME, DAC_TEXT, func)
set_buttons(callback_dialog_handle)
return DRC_MSG_PROCESSED
}
else if ( callback_index == IDL_COMMANDS )
{
set_dialog_item(callback_dialog_handle, IDE_PARMS, DAC_EDIT_TEXT, "")
lookup_keys(callback_dialog_handle)
set_buttons(callback_dialog_handle)
return DRC_MSG_PROCESSED
}
else if ( callback_index == IDL_KEYS )
{
set_buttons(callback_dialog_handle)
return DRC_MSG_PROCESSED
}
}
else if ( callback_msg == DM_KILL_FOCUS )
{
if ( callback_index == IDE_PARMS )
{
lookup_keys(callback_dialog_handle)
set_buttons(callback_dialog_handle)
return DRC_MSG_PROCESSED
}
}
else if ( callback_msg == DM_CHANGE )
{
if ( callback_index == IDE_PARMS )
{
set_buttons(callback_dialog_handle)
return DRC_MSG_PROCESSED
}
else if ( callback_index == IDL_COMMANDS &&
query_dialog_item( callback_dialog_handle,
IDL_COMMANDS,
DAC_SELECT_INDEX) == -1 )
{
lookup_keys(callback_dialog_handle)
set_buttons(callback_dialog_handle)
return DRC_MSG_PROCESSED
}
}
else if ( callback_msg == DM_DOUBLE_CLICK )
{
if ( callback_index == IDL_COMMANDS )
{
# bind_key(callback_dialog_handle)
set_dialog_item(callback_dialog_handle, IDL_COMMANDS, DAC_DESELECT_INDEX)
set_dialog_item(callback_dialog_handle, IDE_PARMS, DAC_EDIT_TEXT, "")
lookup_keys(callback_dialog_handle)
set_buttons(callback_dialog_handle)
return DRC_MSG_PROCESSED
}
else if ( callback_index == IDL_KEYS )
{
# unbind_key(callback_dialog_handle)
return DRC_MSG_PROCESSED
}
}
else if ( callback_msg == DM_OK || callback_msg == DM_CLOSE )
{
set_busy_cursor()
if (keys_set)
{
optional_function( "disable_status_bar_prompts" )
saveKeys(FALSE, callback_dialog_handle)
optional_function( "restore_status_bar" )
keys_set = FALSE
}
updateBindings()
fix_menu_keys()
set_normal_cursor()
return DRC_EXIT
}
else if ( callback_msg == DM_CANCEL )
{
set_busy_cursor()
updateBindings()
set_normal_cursor()
return DRC_EXIT
}
return DRC_CONTINUE
}
local function updateBindings()
{
local func
local bind_buf
local old_buf = current_buffer
if ( addToBindings )
{
if ( (bind_buf = create_buffer("", editor_path( CPE_FILE_BINDINGS ),
BUFFER_SYSTEM + BUFFER_NO_UNDO )) )
{
current_buffer = bind_buf
goto_buffer_bottom()
for ( func in addToBindings )
{
if ( addToBindings[func] )
{
addToBindings[ func ] = FALSE
if ( current_line_length )
{
goto_eol()
insert_newline()
}
insert_string( "User Functions" )
current_column = 25
insert_string( chr(29) func "\n" )
}
}
write_buffer()
delete_buffer()
current_buffer = old_buf
}
}
}
local function query_function_name(handle)
{
local func = query_dialog_item(handle, IDL_COMMANDS, DAC_SELECT_ITEM)
local parm = query_dialog_item(handle, IDE_PARMS, DAC_EDIT_TEXT)
if (func && length(func))
{
if (parm && length(parm))
func = func " " parm
}
else
{
func = query_dialog_item( handle, IDL_COMMANDS, DAC_EDIT_TEXT )
if ( !function_id( func ) )
func = ""
}
return func
}
local function query_key_name(handle)
{
local name
local key = query_dialog_item(handle, IDL_KEY_LIST, DAC_SELECT_ITEM)
if (length(key))
{
name = "<"
if (query_dialog_item(handle, IDC_CTRL_KEY, DAC_CHECK))
name = name "Ctrl-"
if (query_dialog_item(handle, IDC_ALT_KEY, DAC_CHECK))
name = name "Alt-"
if (query_dialog_item(handle, IDC_SHIFT_KEY, DAC_CHECK))
name = name "Shift-"
if (numOK(key))
{
set_dialog_item(handle, IDC_NUM, DAC_ENABLE)
if (query_dialog_item(handle, IDC_NUM, DAC_CHECK))
name = name "Num-"
}
else
{
if (query_dialog_item(handle, IDC_NUM, DAC_CHECK))
set_dialog_item(handle, IDC_NUM, DAC_UNCHECK)
set_dialog_item(handle, IDC_NUM, DAC_DISABLE)
}
return name key ">"
}
return key
}
local function numOK(key)
{
return (key == "Home" || key == "End" || key == "PageUp" ||
key == "PageDown" || key == "Up" || key == "Left" ||
key == "Right" || key == "Down" || key == "Insert" ||
key == "Delete" || key == "Enter" || key == "Center" ||
key == "/" || key == "*" || key == "-" ||
key == "+" || key == "." || (key >= "0" && key <= "9"))
}
local function select_key(handle, name)
{
local pos, cmp, label
if (name)
{
if (length(name) == 1)
{
set_dialog_item(handle, IDC_CTRL_KEY, DAC_UNCHECK)
set_dialog_item(handle, IDC_ALT_KEY, DAC_UNCHECK)
set_dialog_item(handle, IDC_NUM, DAC_UNCHECK)
if (isupper(name))
set_dialog_item(handle, IDC_SHIFT_KEY, DAC_CHECK)
else
set_dialog_item(handle, IDC_SHIFT_KEY, DAC_UNCHECK)
label = toupper(name)
}
else
{
cmp = tolower(name)
if (index(cmp, "ctrl-"))
set_dialog_item(handle, IDC_CTRL_KEY, DAC_CHECK)
else
set_dialog_item(handle, IDC_CTRL_KEY, DAC_UNCHECK)
if (index(cmp, "alt-"))
set_dialog_item(handle, IDC_ALT_KEY, DAC_CHECK)
else
set_dialog_item(handle, IDC_ALT_KEY, DAC_UNCHECK)
if (index(cmp, "shift-"))
set_dialog_item(handle, IDC_SHIFT_KEY, DAC_CHECK)
else
set_dialog_item(handle, IDC_SHIFT_KEY, DAC_UNCHECK)
if (index(cmp, "num-"))
set_dialog_item(handle, IDC_NUM, DAC_CHECK)
else
set_dialog_item(handle, IDC_NUM, DAC_UNCHECK)
if ((pos = rindex(name, "-")) > 0)
{
if (pos < length(name))
label = substr(name, pos + 1, length(name) - pos - 1)
else
label = "-"
}
else
label = substr(name, 2, length(name) - 2)
}
set_dialog_item(handle, IDL_KEY_LIST, DAC_SELECT_ITEM, label)
}
}
local function lookup_keys(handle)
{
local i
local pos
local list
local keys
local func = query_function_name(handle)
if (length(func))
{
if (func == "insert_key") # The insert_key list is too HUGE!!!!!
{
set_dialog_item(handle, IDL_KEYS, DAC_CLEAR_LIST)
set_dialog_item(handle, IDT_FNAME, DAC_TEXT, "")
}
else if (func != query_dialog_item(handle, IDT_FNAME, DAC_TEXT))
{
set_dialog_item(handle, IDL_KEYS, DAC_CLEAR_LIST)
set_dialog_item(handle, IDT_FNAME, DAC_TEXT, func)
keys = function_binding_key(func, FALSE, FALSE, TRUE)
if (keys && length(keys))
{
split(keys, list, "|")
for (i in list)
{
set_dialog_item(handle, IDL_KEYS, DAC_ADD_ITEM,
ltrim(trim(list[i])))
}
}
}
}
else
{
set_dialog_item(handle, IDL_KEYS, DAC_CLEAR_LIST)
set_dialog_item(handle, IDT_FNAME, DAC_TEXT, "")
}
}
local function lookup_commands(handle)
{
local pos
local func
local parm
local name = query_key_name(handle)
if (length(name))
{
func = keymap_binding(name)
if (length(func))
{
set_dialog_item(handle, IDT_FUNCTION_NAME, DAC_TEXT, func)
if ((pos = cindex(func, " ")))
{
parm = substr(func, pos+1)
func = prefix(func, pos-1)
}
else
parm = ""
if (!set_dialog_item(handle, IDL_COMMANDS, DAC_SELECT_ITEM, func))
{
addToBindings[ func ] = TRUE
set_dialog_item(handle, IDL_COMMANDS, DAC_ADD_ITEM, func)
set_dialog_item(handle, IDL_COMMANDS, DAC_SELECT_ITEM, func)
}
set_dialog_item(handle, IDE_PARMS, DAC_EDIT_TEXT, parm)
}
else
{
set_dialog_item(handle, IDT_FUNCTION_NAME, DAC_TEXT, "")
set_dialog_item(handle, IDE_PARMS, DAC_EDIT_TEXT, "")
set_dialog_item(handle, IDL_COMMANDS, DAC_DESELECT_INDEX)
}
}
}
local function set_buttons(handle)
{
if (length(query_function_name(handle)))
{
set_dialog_item(dhKeysDialog, IDB_FUNCTION_HELP, DAC_ENABLE)
if (query_dialog_item(handle, IDL_KEY_LIST, DAC_SELECT_INDEX) >= 0)
set_dialog_item(dhKeysDialog, IDB_BIND, DAC_ENABLE)
else
set_dialog_item(dhKeysDialog, IDB_BIND, DAC_DISABLE)
}
else
{
set_dialog_item(dhKeysDialog, IDB_BIND, DAC_DISABLE)
set_dialog_item(dhKeysDialog, IDB_FUNCTION_HELP, DAC_DISABLE)
}
if (query_dialog_item(handle, IDL_KEYS, DAC_SELECT_INDEX) >= 0)
set_dialog_item(dhKeysDialog, IDB_UNBIND, DAC_ENABLE)
else
set_dialog_item(dhKeysDialog, IDB_UNBIND, DAC_DISABLE)
}
# DWM This function will bind the current key with the current function and
# parameters, and keep track of this information in order to save it to
# the config file. If function_id() of the function and its parameters
# returns 0, it will warn the user that the parameters are invalid, and
# not try to bind.
local function bind_key(handle)
{
local i
local key
local func
local list
local old_poe
local name = query_key_name(handle)
if (length(name))
{
if (name == "<Ctrl-Esc>" || name == "<Ctrl-Alt-Delete>" || \
name == "<Ctrl-Alt-Num-.>" || name == "<Ctrl-Alt-Num-Delete>")
{
warning("Invalid key %s can not be bound", name)
}
else
{
func = query_function_name(handle)
if ( length(func) )
{
if ( function_id(func) )
{
# Make sure the key is not already bound to this function.
key = key_to_int(name)
split(function_binding(function_id(func)), list, "#")
for (i in list)
{
if (list[i]+0 == key)
return
}
if ( query_dialog_item(handle, IDL_COMMANDS, DAC_FIND, func) == -1 )
{
addToBindings[ func ] = TRUE
set_dialog_item(handle, IDL_COMMANDS, DAC_ADD_ITEM, func)
set_dialog_item(handle, IDL_COMMANDS, DAC_SELECT_ITEM, func)
}
# Assign the function to the key.
set_dialog_item(handle, IDL_KEYS, DAC_ADD_ITEM, name)
if (name in deletedKeys)
delete( deletedKeys[ name ] )
assign_key(name, func)
insertedKeys[ name ] = func
keys_set = TRUE
}
else
{
old_poe = pause_on_error
pause_on_error = TRUE
warning( "You must provide valid parameters to function " func )
pause_on_error = old_poe
}
}
}
}
}
local function unbind_key(handle)
{
local name = query_dialog_item(handle, IDL_KEYS, DAC_SELECT_ITEM)
if (length(name))
{
if (name in insertedKeys)
delete( insertedKeys[ name ] )
else
deletedKeys[ name ] = keymap_binding( name )
set_dialog_item(handle, IDL_KEYS, DAC_DELETE_ITEM, name)
assign_key(name, "beep")
keys_set = TRUE
}
}