home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
BRIEF.PEL
< prev
next >
Wrap
Text File
|
1995-03-21
|
24KB
|
749 lines
# $Header: P:\source\wmacros\brief.pev 1.59 21 Mar 1995 09:02:34 WALKER $
## $Tabs:4 7$
##############################################################################
#
# 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: brief.pel $: Key bindings for Brief compatibility
local brief_keymap = -1
##
## BriefKeymap() - define Brief key bindings
##
# key #- found in startup keymap
# # already defined
# # not implemented yet
global function brief() #PUBLIC #VOID
{
local prevPauseOnError
if (emulation_mode == "brief")
return;
emulation_mode = "brief"
execute_event_handler( EVENT.EMULATION_CHANGED )
attach_event_handler(EVENT.EMULATION_CHANGED, function_id("brief_exit"))
# pause if an error or warning occurs during initialization
prevPauseOnError = pause_on_error
pause_on_error = 1
create_brief_keymap()
brief_menu()
pause_on_error = prevPauseOnError
}
global function create_brief_keymap()
{
# Enable the keymap. Subsequent mods to the keymap will persist
# through the end of the session.
# Only one-time initialization should follow this point.
if( brief_keymap >= 0 )
{
current_keymap = brief_keymap
return
}
else
{
current_keymap = brief_keymap = create_keymap( factory_keymap )
assign_brief_keys()
# assign_brief_f_keys()
# assign_brief_misc_keys()
optional_function("local_keys")
}
}
global function assign_brief_keys()
{
#--------------------------------------------------------------
# Alt key combinations on the main keyboard:
#--------------------------------------------------------------
assign_key( "<Alt-A>", "set_exclusive_mark" )
assign_key( "<Alt-B>", "buffer_list" )
assign_key( "<Alt-C>", "set_column_mark" )
assign_key( "<Alt-D>", "delete_line" )
# assign_key( "<Alt-E>", "edit_file_key" )
assign_key( "<Alt-E>", "create_buf_and_win_key" )
assign_key( "<Alt-F>", "display_filename" )
assign_key( "<Alt-G>", "goto_line_key" )
assign_key( "<Alt-H>", "display_help_item")
assign_key( "<Alt-I>", function_id("toggle_buffer_flags", BUFFER_OVERTYPE_MODE))
assign_key( "<Alt-J>", "goto_bookmark")
assign_key( "<Alt-K>", "delete_to_eol" )
assign_key( "<Alt-L>", "set_line_mark" )
assign_key( "<Alt-M>", "set_inclusive_mark" )
assign_key( "<Alt-N>", "next_buffer_mask" )
assign_key( "<Alt-O>", "change_output_name" )
assign_key( "<Alt-P>", "gui_print" )
assign_key( "<Alt-Q>", "insert_quoted_key" )
assign_key( "<Alt-R>", "read_file_key" )
assign_key( "<Alt-S>", "search_forward" )
assign_key( "<Alt-T>", "replace_forward" )
assign_key( "<Alt-U>", "undo" )
assign_key( "<Alt-V>", "print_version" )
assign_key( "<Alt-W>", "write_block_key" )
assign_key( "<Alt-X>", "done" )
assign_key( "<Alt-F4>", "done2" )
assign_key( "<Alt-Y>", "redo" )
assign_key( "<Alt-Z>", "system" )
#--------------------------------------------------------------
# Ctrl key combinations on the main keyboard:
#--------------------------------------------------------------
assign_key( "<Ctrl-A>", "optional_function display_ascii_table" )
assign_key( "<Ctrl-B>", "scroll_window_bottom")
assign_key( "<Ctrl-C>", "center_cursor" )
assign_key( "<Ctrl-D>", "scroll_up_1" )
assign_key( "<Ctrl-G>", "optional_function routines" )
assign_key( "<Ctrl-N>", "goto_next_error" )
# assign_key( "<Ctrl-P>", "display_errors" )
assign_key( "<Ctrl-R>", "optional_function repeat_key_action" )
assign_key( "<Ctrl-T>", "scroll_window_top" )
assign_key( "<Ctrl-U>", "scroll_down_1")
assign_key( "<Ctrl-W>", "toggle_file_backup" )
assign_key( "<Ctrl-X>", "write_and_exit" )
# }
# global function assign_brief_f_keys()
# {
#--------------------------------------------------------------
# Function Key bindings
#--------------------------------------------------------------
# assign_key( "<F1>", "brief_change_window" )
# assign_key( "<F2>", "adjust_window" )
assign_key( "<F3>", "brief_create_window" )
assign_key( "<F4>", "brief_delete_window" )
assign_key( "<F5>", "search_forward" )
assign_key( "<F6>", "replace_forward" )
assign_key( "<F7>", "record_macro" )
assign_key( "<F8>", "playback_macro" )
assign_key( "<F9>", "system_key" )
assign_key( "<F10>", "invoke_function" )
assign_key( "<Alt-F1>", "toggle_borders" )
# assign_key( "<Alt-F2>", "toggle_window_zoom" )
assign_key( "<Alt-F5>", "search_backward" )
assign_key( "<Alt-F6>", "replace_backward" )
assign_key( "<Alt-F7>", "load_key_file" )
assign_key( "<Alt-F8>", "write_key_file" )
assign_key( "<Alt-F10>", "compile_buffer" )
assign_key( "<Shift-F5>", "search_again" )
assign_key( "<Shift-F6>", "replace_again" )
assign_key( "<Shift-F7>", "pause_recording" )
# assign_key( "<Shift-F9>", "" )
assign_key( "<Shift-F10>", "insert_keys" )
assign_key( "<Ctrl-F1>", "display_help_item" )
assign_key( "<Ctrl-F5>", function_id("toggle_search_flags", SEARCH_CASE))
assign_key( "<Ctrl-F6>", function_id("toggle_search_flags", SEARCH_REGEX))
#}
#
#global function assign_brief_misc_keys()
#{
#--------------------------------------------------------------
# Alt-digit codes:
#--------------------------------------------------------------
assign_key( "<Alt-1>", "place_bookmark 1")
assign_key( "<Alt-2>", "place_bookmark 2")
assign_key( "<Alt-3>", "place_bookmark 3")
assign_key( "<Alt-4>", "place_bookmark 4")
assign_key( "<Alt-5>", "place_bookmark 5")
assign_key( "<Alt-6>", "place_bookmark 6")
assign_key( "<Alt-7>", "place_bookmark 7")
assign_key( "<Alt-8>", "place_bookmark 8")
assign_key( "<Alt-9>", "place_bookmark 9")
assign_key( "<Alt-0>", "place_bookmark 10")
#--------------------------------------------------------------
# Numpad keys
#--------------------------------------------------------------
# assign_key( "<Num-1>", "goto_window_right" )
assign_key( "<Num-2>", "insert_key")
assign_key( "<Num-4>", "insert_key")
assign_key( "<Num-6>", "insert_key")
# assign_key( "<Num-7>", "goto_window_left" )
assign_key( "<Num-8>", "insert_key")
assign_key( "<Num-+>", "copy_to_scrap_key" )
assign_key( "<Num-->", "delete_to_scrap")
assign_key( "<Num-*>", "undo" )
assign_key( "<Num-/>", "redo" ) # Extension to Brief
assign_key( "<Num-Enter>", "auto_indent_cr" )
assign_key( "<Alt-Num-->", "prev_buffer_mask" )
assign_key( "<Ctrl-Num-->", "brief_delete_buffer" )
#--------------------------------------------------------------
# non-ASCII keys on main keyboard:
#--------------------------------------------------------------
assign_key( "<Esc>", "expand_template_key" )
assign_key( "<Enter>", "auto_indent_cr" )
assign_key( "<Tab>", "indent_tab_maybe" )
assign_key( "<Space>", "indent_space_maybe" )
assign_key( "<Backspace>", "brief_backspace" )
assign_key( "<Shift-Backspace>", "brief_backspace" )
assign_key( "<Shift-Space>", "insert_key 32");
assign_key( "<Ctrl-Space>", "insert_key 32");
# use BackTab for OS2 and Shift-Tab for windows
assign_key( "<BackTab>", "outdent_tab_maybe" )
assign_key( "<Ctrl-->", "brief_delete_buffer" )
assign_key( "<Alt-->", "prev_buffer_mask" )
#--------------------------------------------------------------
# keypad keys:
#--------------------------------------------------------------
assign_key( "<Insert>", "insert_scrap" )
assign_key( "<Delete>", "delete_chars" )
assign_key( "<Up>", "up" )
assign_key( "<PageUp>", "page_up" )
assign_key( "<Home>", "home_key" )
assign_key( "<End>", "end_key" )
assign_key( "<Num-Home>", "home_key" )
assign_key( "<Num-End>", "end_key" )
assign_key( "<Down>", "down" )
assign_key( "<PageDown>", "page_down" )
assign_key( "<Left>", "left" )
assign_key( "<Right>", "right" )
assign_key( "<Ctrl-Left>", "prev_word" )
assign_key( "<Ctrl-Right>", "next_word" )
assign_key( "<Ctrl-Backspace>", "delete_prev_word" )
assign_key( "<Ctrl-PageUp>", "goto_buffer_top" )
assign_key( "<Ctrl-Home>", "goto_window_top" )
assign_key( "<Ctrl-End>", "goto_window_bottom" )
assign_key( "<Ctrl-PageDown>", "goto_buffer_bottom" )
assign_key( "<Ctrl-Enter>", "auto_indent_nl" )
assign_key( "<Alt-Space>", "outdent_space_maybe" )
assign_key( "<Alt-Backspace>", "delete_word" )
assign_key( "<Alt-Up>", "n_window")
assign_key( "<Alt-Right>", "e_window")
assign_key( "<Alt-Down>", "s_window")
assign_key( "<Alt-Left>", "w_window")
}
#
# EVENT.EMULATION_CHANGED Occured - Brief Emulation is no longer active.
#
global function brief_exit()
{
# delete event handlers
delete_event(EVENT.EMULATION_CHANGED, function_id("brief_exit"))
}
# this function is used to customize the menu so that the keys you have
# assigned to do the same thing as the menuitem will show on the menu
# It should be global and start with the string inside emulation_mode
function brief_menu()
{
local menu = menu_info( 0 , MI_MENUHANDLE );
local temp_array[]
temp_array[ IDM_ADDFILE ].mapped = "create_buf_and_win_key"
temp_array[ IDM_SAVE ].mapped = "write_block_key"
temp_array[ IDM_FIND ].mapped = "search_forward"
temp_array[ IDM_FINDAGAIN ].mapped = "search_again"
temp_array[ IDM_CHANGE ].mapped = "replace_forward"
temp_array[ IDM_COMMAND ].mapped = "invoke_function"
temp_array[ IDM_CLOSE ].mapped = "brief_delete_buffer"
temp_array[ IDM_INSERTFILE ].mapped = "read_file_key"
mapped_menu_functions = temp_array
# add keys to menu that contain non-special-dialog box functions
# optional_function( "fix_menu_text", IDM_ADDFILE, "create_buf_and_win_key" )
# optional_function( "fix_menu_text", IDM_SAVE, "write_block_key" )
# optional_function( "fix_menu_text", IDM_FIND, "search_forward" )
# optional_function( "fix_menu_text", IDM_FINDAGAIN, "search_again" )
# optional_function( "fix_menu_text", IDM_CHANGE, "replace_forward" )
# optional_function( "fix_menu_text", IDM_COMMAND, "invoke_function" )
# optional_function( "fix_menu_text", IDM_CLOSE, "brief_delete_buffer" )
# optional_function( "fix_menu_text", IDM_INSERTFILE, "read_file_key" )
}
#---------------------------------------------------------------#
# #
# Functions required to support the brief calls #
# #
#---------------------------------------------------------------#
#------------- Basic text commands support ---------------------------------#
function brief_backspace()
{
if ((current_column > 1) || (and(buffer_flags, BUFFER_WP_ENABLED)))
backspace()
}
#------------- Playback/record and Macros functions unique to brief --------#
#------------- Miscellaneous functions unique to brief ---------------------#
function brief_delete_buffer()
{
delete_buffer_key("", 1);
}
#------------- Window functions unique to brief ---------------------#
local NORTH = 0x1
local EAST = 0x2
local SOUTH = 0x4
local WEST = 0x8
local function get_window_direction( msg )
{
local ch
if (msg)
{
notify( msg "(use arrow keys)." )
}
ch = getkey()
if (ch == KEYCODE_UP || ch == KEYCODE_NUM_UP) return NORTH
else if (ch == KEYCODE_DOWN || ch == KEYCODE_NUM_DOWN) return SOUTH
else if (ch == KEYCODE_LEFT || ch == KEYCODE_NUM_LEFT) return WEST
else if (ch == KEYCODE_RIGHT || ch == KEYCODE_NUM_RIGHT) return EAST
return 0
}
## brief-style window resize (or as close to it as need be)
#
function brief_resize_window( ironside, amount )
{
local direction
local x0 = window_x0
local y0 = window_y0
local xExt = window_width
local yExt = window_height
local useAmount
local minSize = 20
if (!argcount())
{
ironside = get_window_direction( "Select side to move " )
amount = 10
}
else if ( argcount() != 2 )
{
amount = 10
}
if (ironside)
{
direction = get_window_direction( "Move window edge " )
while (direction)
{
if (ironside == NORTH)
{
if (direction == NORTH)
{
yExt += amount
}
else if (direction == SOUTH)
{
if (yExt > minSize)
{
yExt -= amount;
}
}
}
else if (ironside == SOUTH)
{
if (direction == NORTH)
{
if (yExt > minSize)
{
yExt -= amount
y0 += amount
}
}
else if (direction == SOUTH)
{
if (y0 > 0)
{
yExt += amount
y0 -= amount
}
}
}
else if (ironside == WEST)
{
if (direction == WEST)
{
if (x0 > 0)
{
x0 -= amount
xExt += amount
}
}
else if (direction == EAST)
{
if (xExt > minSize)
{
x0 += amount
xExt -= amount
}
}
}
else if (ironside == EAST)
{
if (direction == WEST)
{
if (xExt > minSize)
xExt -= amount
}
else if (direction == EAST)
{
xExt += amount
}
}
frame_window( x0, y0, xExt, yExt )
# display_update()
direction = get_window_direction( "Move window edge " )
}
}
message( "" )
}
function point_in_rect( x, y, left, right, bottom, top )
{
if ( (x >= left) && (x <= right) &&
(y >= bottom) && (y <= top))
return TRUE
else
return FALSE
}
function window_containing_point( x, y )
{
local cur_win = current_window
local w
local found_win = 0
while ( !found_win && ( (w = next_window("", 0, 1)) != cur_win ) )
{
if (point_in_rect(x, y, window_x0, window_x0+window_width,
window_y0, window_y0+window_height) )
found_win = w
}
return found_win
}
## Returns TRUE if the current window is intersected by a horizontal
# or vertical line. Returns FALSE if not.
#
# Note: either input x or y must be zero.
#
function line_intersects_current_window( x, y )
{
local w
if (x)
{
if ( (x >= window_x0) && (x <= window_x0+window_width) )
return TRUE
}
else
{
if ( (y >= window_y0) && (y <= window_y0+window_height) )
return TRUE
}
return FALSE
}
function adjacent_window( direction )
{
local line_x = 0
local line_y = 0
local NULL = 0
local savewin = current_window
local target_edge
local wflags
local cur_win = current_window
local w
local found_win = 0
local margin = 10 # Minimum amount of target window visisble
if (direction == NORTH )
{
line_x = window_x0 + (window_width/2)
# target_edge = window_y0 + window_height - margin
target_edge = window_y0 + margin
}
else if (direction == SOUTH)
{
line_x = window_x0 + (window_width/2)
# target_edge = window_y0 + margin
target_edge = window_y0 + window_height - margin
}
else if (direction == EAST)
{
line_y = window_y0 + (window_height/2)
# target_edge = window_x0 + window_width - margin
target_edge = window_x0 + margin
}
else
{
line_y = window_y0 + (window_height/2)
# target_edge = window_x0 + margin
target_edge = window_x0 + window_width - margin
}
while ( !found_win && ( (w = next_window("", 0, 1)) != savewin) )
{
if (line_intersects_current_window(line_x, line_y) )
{
if (direction == NORTH && window_y0 >= target_edge)
found_win = w
else if ( (direction == SOUTH) &&
(window_y0+window_height <= target_edge) )
found_win = w
else if ( (direction == EAST) &&
(window_x0 >= target_edge) )
found_win = w
else if ( (direction == WEST) &&
(window_x0+window_width <= target_edge) )
found_win = w
}
}
current_window = savewin
return found_win
}
global function n_window() {
return move_to_adjacent_window( NORTH )
}
global function s_window() {
return move_to_adjacent_window( SOUTH )
}
global function w_window() {
return move_to_adjacent_window( WEST )
}
global function e_window() {
return move_to_adjacent_window( EAST )
}
local function move_to_adjacent_window( direction )
{
local win = adjacent_window( direction )
if ( win ) {
current_window = win
display_filename()
return TRUE
} else {
notify("No window found.")
return FALSE
}
}
## brief-style window change
#
function brief_change_window( direction ) {
local status = FALSE
if (!argcount())
direction = get_window_direction( "Select new current window " )
if ( direction == NORTH ) status = n_window()
else if (direction == SOUTH) status = s_window()
else if (direction == WEST) status = w_window()
else if (direction == EAST) status = e_window()
else message( "" )
return status
}
## brief-style window creation
#
function brief_create_window( direction )
{
local ch
if (!argcount())
{
direction = get_window_direction( "Select side for new window ")
message( "" )
}
if (direction)
{
if (!mdi_mode)
toggle_window_mode()
if (and( direction, NORTH+SOUTH) )
{
if (split_window_horizontal())
{
if ( direction == NORTH )
prev_window()
return TRUE
}
}
else # direction = EAST or WEST
{
if (split_window_vertical())
{
if (direction == WEST)
prev_window()
return TRUE
}
}
}
return FALSE
}
## brief-style window delete
#
function brief_delete_window( direction )
{
local w = current_window
local ch
if ( next_window("", 0, 1) == w )
{
warning( "Cannot delete last window" )
return
}
else
{
if (w)
current_window = w
}
if (!argcount())
{
direction = get_window_direction( "Select edge to delete ")
message( "" )
}
if (direction)
delete_window_edge( direction )
}
## delete a window's edge given the direction of the edge
# the edge is not deleted unless an adjoining window can be found
local function delete_window_edge( dir )
{
local x0 = window_x0
local y0 = window_y0
local x1 = x0 + window_width - 1
local y1 = y0 + window_height - 1
local cw = current_window;
local cur;
if (and(window_flags,WINDOW_SYSTEM))
cur = next_window("", 0, 1);
else
cur = cw;
do
{
if( current_window != cur &&
delete_adjacent_edge( dir, cur, x0, y0, x1, y1 ))
{
delete_window_key()
if (cw)
current_window = cw
return
}
next_window("", 0, 1)
} while( cur != current_window )
if (cw)
current_window = cw;
warning( "Edge does not have exactly two adjoining windows" )
}
local function delete_adjacent_edge( dir, cur, x0, y0, x1, y1 )
{
local cx0 = window_x0
local cy0 = window_y0
local cx1 = cx0 + window_width - 1
local cy1 = cy0 + window_height - 1
local margin = 2 # pixels window edges can be separated or overlap
if( (cx0 >= x0 - margin) && (cx0 <= x0 + margin) &&
(cx1 >= x1 - margin) && (cx1 <= x1 + margin) )
{
if( (dir == SOUTH) && (cy1 >= y0 - margin) && (cy1 <= y0 + margin) ) # above
{
frame_window( x0, cy0, window_width, y1 - cy0 + 1, cur )
return 1
}
else if( dir == NORTH && (cy0 >= y1 - margin) && (cy0 <= y1 + margin) ) # below
{
frame_window( x0, y0, window_width, cy1 - y0 + 1, cur )
return 1
}
}
else if( (cy0 >= y0 - margin) && (cy0 <= y0 + margin) &&
(cy1 >= y1 - margin) && (cy1 <= y1 + margin) )
{
if( (dir == WEST) && (cx1 >= x0 - margin) && (cx1 <= x0 + margin) ) # left
{
frame_window( cx0, cy0, x1 - cx0 + 1, window_height, cur )
return 1
}
else if( (dir == EAST) && (cx0 >= x1 - margin) && (cx0 <= x1 + margin) ) # right
{
frame_window( x0, y0, cx1 - x0 + 1, window_height, cur )
return 1
}
}
return 0
}