home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-27 | 24.1 KB | 1,010 lines |
- # $Header: P:/source/ppee/macros/history.pev 1.106 24 Sep 1990 17:25:02 skipr $
-
- ##############################################################################
- #
- # Sage Software - POLYTRON Division
- # 1700 NW 167th Place
- # Beaverton, OR 97006
- #
- # Copyright 1990, Sage Software, Inc.
- #
- # Permission is hereby granted for licensed users of Sage Professional
- # Editor and PolyAwk to copy and modify this source code for their own
- # personal use. These derivative works may be distributed only to other
- # licensed Sage Professional Editor and PolyAwk users. All other usage
- # is prohibited without express written permission from Sage Software.
- #
- ##############################################################################
-
- #### $Workfile: history.pel $: Response history support
-
-
- ## local variables
- #
- local FIELD_SIZE = 14 # width of the directory window
- local saveBuffer
- local saveWindow
- local ALT_H = 0x2300
- local ALT_K = 0x2500
- local ALT_L = 0x2600
-
- local historyArray
- local historyName
- local historyElement
- local historyPromptString # current prompt string displayed by prompt_history
-
- #------------------------------------------------------------------#
-
- global edit_file_dir # set to 1 to display dir list from edit_file_key()
-
- ## prompt_history()
- #
- # Prompt the user for a string and process all illegally typed characters
- # through the _bapPromptKey() function. The parameters passed are as
- # follows:
- #
- # index - a string identifying which history stack to use
- # promptstr - first parameter to prompt()
- # defaultstr- second parameter to prompt()
- # usehistory- if defaultstr == "" and usehistory == 1, use the
- # last history item
- #
- # Example:
- # prompt_history( "SEARCH", "Search for: ", "noname" )
- #
- # Each time this is called an a valid input string is entered
- # and returned by prompt(), it is added to the history stack for
- # "SEARCH" and subsequent calls can access this stack.
- #
- global function prompt_history( index, promptstr, defaultstr, usehistory ) {
- local patt;
- local i = 0;
- local id = function_id( "_bad_prompt_key" );
-
- if (!(index i in historyArray))
- historyArray[ index i ] = i;
-
- #
- # install an event handler to make command history
- # available to the prompt function.
- #
- attach_event_handler( EVENT_INVALID_PCHAR, id )
-
- #
- # let the command history functions know where to find
- # the command history for this specified call.
- #
- historyName = index;
- historyElement = defaultstr ? -1 : 0;
-
- #
- # prompt for the search pattern and provide command history
- #
- if ((historyElement == 0) && (usehistory)) {
- defaultstr = current_history_item( index );
- historyElement = -1;
- }
- patt = prompt( historyPromptString = promptstr, defaultstr )
-
- #
- # remove the prompt event handler
- #
- delete_event( EVENT_INVALID_PCHAR, id )
-
- if (patt)
- add_prompt_history( index, patt )
- return patt;
- }
-
-
- ## _bad_prompt_key()
- #
- # This is the event handler used to handle bad keys entered from the prompt
- # primitive.
- #
- # A few notes:
- #
- # o This function will receive any key which is not a simple upper
- # or lower case letter, including <Enter>, <Spacebar>, <Ctrl-A> etc.
- #
- # o The "prompt_response" variable contains the current input string
- # at the prompt. This string can be modified in any manner and will
- # be reflected at the prompt line.
- #
- # o The value of "current_key" will be processed when this function
- # returns as if this function was never called. If you wish that
- # the key not be processed, set "current_key = 0"; or if you wish to
- # replace it with a different key, set "current_key = <your_keycode>".
- # For example, setting current_key to "KEYCODE_HOME" will cause the
- # cursor to move to the beginning of the prompt response.
- #
- # o Setting current_key to the magic value -1 resets prompt() to its
- # initial state, i.e. it highlights the current prompt_response value
- # and places the cursor at the end of the response. If the
- # prompt_response variable is changed without setting current_key
- # to -1, the cursor position will be left unchanged.
- #
- global function _bad_prompt_key() {
-
- local min = 0;
- local max;
- local saveBuffer
- local scancode
- local orig_x, orig_y,x,y,x_diff,y_diff,new_x0,new_y0, winid, save_winid
-
-
- if (current_key == ALT_H) {
- display_help_item( "prompt " historyName );
- current_key = 0;
- return;
- }
-
-
- if (current_key == KEYCODE_TAB) {
- #
- # if we are performing an edit_file and a TAB
- # was pressed, then display dir listing
- #
- if (historyName == "EDITFILE") {
- displayDirContents()
- return;
- }
- #
- # if we are performing an invoke_function (F10) and a TAB
- # was pressed, then display function listing
- #
- if (historyName == "XMACRO") {
- displayFunctionList()
- return;
- }
- } else if (current_key == ALT_L) {
- if (historyName == "EDITFILE") {
- defaultFileName();
- return;
- }
- } else if (current_key == ALT_K) {
- prompt_response = substr(prompt_response,1,
- window_cursor_x - length(historyPromptString));
- return;
- } else if ((current_key == LEFT_PRESS) &&
- ((winid = window_containing( mouse_event_x, mouse_event_y))) &&
- !(window_border_contains( mouse_event_x, mouse_event_y, winid ))){
-
-
- save_winid = current_window;
- current_window = winid;
-
- new_x0 = orig_x = mouse_event_x - window_text_x0;
- new_y0 = orig_y = mouse_event_y - window_text_y0;
-
- x_diff = 1;
- y_diff = 1;
-
- highlight_window( new_x0, new_y0, x_diff, y_diff, color_highlight );
-
- x = mouse_display_x;
- y = mouse_display_y;
-
- while ( and(mouse_buttons, LEFT_BUTTON) ){
- if ((x != mouse_display_x) || (y != mouse_display_y)){
- x = mouse_display_x;
- y = mouse_display_y;
-
- if (!window_contains( x, y ) ||
- window_border_contains( x, y ))
- continue;
-
- highlight_window( new_x0, new_y0, x_diff, y_diff, color_text );
-
- new_x0 = mouse_display_x - window_text_x0;
- new_y0 = mouse_display_y - window_text_y0;
-
- if (orig_x > new_x0) {
- x_diff = orig_x - new_x0 + 1;
- } else {
- x_diff = new_x0 - orig_x + 1;
- new_x0 = orig_x;
- }
-
- if (orig_y > new_y0) {
- y_diff = orig_y - new_y0 + 1;
- } else {
- y_diff = new_y0 - orig_y + 1;
- new_y0 = orig_y;
- }
-
- highlight_window( new_x0, new_y0, x_diff, y_diff, color_highlight );
- display_update();
- }
- }
-
- highlight_window( new_x0, new_y0, x_diff, y_diff, color_text );
-
- if ((x_diff != 1) || (y_diff != 1)){
- prompt_response = ""
- while (y_diff-- > 0) {
- window_cursor_x = new_x0;
- window_cursor_y = new_y0++;
- prompt_response = prompt_response read_window( x_diff )
- }
- }
- assign_current_window( save_winid );
- display_update();
- current_key = KEYCODE_END;
- return;
- }
-
-
-
-
- #
- # is there something in the buffer?
- #
- max = historyArray[ historyName min ];
-
- scancode = shiftr(current_key, 8)
- if (scancode == SCANCODE_DOWN) {
- # get previous command
- if (max)
- historyElement = (historyElement + 1) % max
- } else if (scancode == SCANCODE_UP) {
- # get next command
- if (max) {
- if (historyElement <= 0) # skip first entry if < 0
- historyElement = max + historyElement;
- if (historyElement)
- historyElement--;
- }
- } else {
- #
- # Didn't find any keys that we want to handle so
- # just return.
- #
- return;
- }
-
- #
- # read the response out of the buffer
- #
- # index was 0..n-1, it should be 1..n
- current_key = 0;
- if (max <= 0)
- return;
- prompt_response = historyArray[ historyName (historyElement + 1) ];
- current_key = -1 # highlight the new prompt response
- }
-
- ## find an item in the command history array
- #
- global function current_history_item( index ){
- local i = 0;
-
- if (index i in historyArray) {
- i = historyArray[ index i ];
- if (i)
- return historyArray[ index i ];
- }
- return "";
- }
-
-
- ## add an item to the command history array
- #
- global function add_prompt_history( index, patt ) {
- local i = 0;
- local promptCount = 0;
-
- if (index i in historyArray)
- promptCount = historyArray[ index i ];
-
- #
- # don't add this pattern to the history if the previous pattern
- # is the same.
- #
- if ( !promptCount || \
- (promptCount && (historyArray[ index promptCount ] != patt)) ) {
- historyArray[ index i ] = ++promptCount;
- historyArray[ index promptCount ] = patt;
- }
-
- return patt
- }
-
-
-
- #--------- display directory specified and allow movement within it --------#
-
-
- ## displayDirContents()
- #
- # Display all of the files in the current directory which start with
- # the pattern specified of *.* if none.
- #
- # Maybe add changing directories and other items later.
- #
- local function displayDirContents() {
-
- local ch
- local fname
- local numOfEntries = 0 # number of files in current directory
- local lastname
- local dir_buffer # buffer which contains the file names
- local windowHeight
- local prompt_start
- local l,r,c,i
- local nname
- local srchname
- local tmp
- local insert_prev_dir = FALSE;
- local find_flags;
- local windowlines;
- local cr_pressed
- local dir_list
- local file_list
- local dirInfo = ""
- local maxWidth = FIELD_SIZE
-
-
- init_menu_colors();
-
- prompt_start = prompt_response
- l = rindex( prompt_start, "\\" )
- r = rindex( prompt_start, "/" )
- c = rindex( prompt_start, ":" )
- l = l > r ? l : r
- l = l > c ? l : c
- prompt_start = prefix( prompt_start, l )
-
- saveWindow = current_window;
- saveBuffer = current_buffer;
-
- # create a new buffer to put the filenames into
- current_buffer = \
- dir_buffer = \
- create_buffer( "", "", BUFFER_SYSTEM + BUFFER_NO_UNDO )
-
- #
- # read in all of normal file names from the current directory
- # and insert them into the current_buffer
- #
- srchname = prompt_response
- if ( (!srchname) || (rindex(srchname, "?") != length( srchname ))) {
- tmp = path_ext( srchname )
- if ( !tmp ) {
- if ( length(path_fname(srchname)) >= 8 )
- srchname = srchname ".*"
- else
- srchname = srchname "*.*"
- } else {
- if ( length(tmp) < 4 ) {
- srchname = srchname "*"
- }
- }
- }
-
- find_flags = _SUBDIR # include only directories
-
- # in case directory search takes a long time
- message( "Working..." )
-
- for (i=0; i < 2; i++) {
- fname = findfirst( srchname, find_flags );
- fname = path_fname( fname ) path_ext( fname )
-
- while (fname) {
- if (i == 0) {
- lastname = fname "\\"
- dir_list[ toupper(lastname) ] = ""
- } else {
- lastname = tolower(fname)
- if ( edit_file_dir ){
- dirInfo = filesize()
- if ( dirInfo >= 0 ) {
- dirInfo = sprintf( "%7d %s",
- filesize(),
- ctime( filetime()))
- } else {
- dirInfo = ""
- }
- }
- file_list[ lastname ] = dirInfo
- }
- numOfEntries++
- fname = findnext()
- }
- find_flags = _NORMAL # include normal files
- }
-
- if (".\\" in dir_list) {
- numOfEntries--;
- delete( dir_list[ ".\\" ] )
- }
-
- for (i in dir_list) {
- insert_string( i "\n" )
- }
-
- for (i in file_list) {
- if ( edit_file_dir ){
- i = i substr( " ", \
- 1, \
- FIELD_SIZE - length(i)) \
- file_list[i]
- if ( length(i) > maxWidth ){
- maxWidth = length(i)
- }
- }
- insert_string( i "\n" )
- }
-
- backspace();
-
- # restore the old buffer for the current window
- current_buffer = saveBuffer;
-
- #
- # create the window making it just wide enough for a file name
- #
- windowlines = display_height - 8;
- if (numOfEntries > 1 || insert_prev_dir) {
- windowHeight = (numOfEntries > windowlines) ? windowlines : numOfEntries;
- current_window =
- create_factory_window( 10, \
- display_height - windowHeight -6, \
- maxWidth + 2, \
- windowHeight + 2, \
- WINDOW_MENU0 + WINDOW_SB_RIGHT )
-
- highlight_screen( 11, \
- display_height - windowHeight -5, \
- maxWidth + 2, \
- windowHeight + 2, \
- SHADOW_COLOR );
-
- visible_end_buffer = ""
- visible_tabs = ""
- visible_virtual_lines = ""
-
- # current_buffer = dir_buffer;
- attach_window_buffer( current_window, dir_buffer )
- }
-
- if ( numOfEntries == 0 ) {
- # no files match the file pattern
- delete_buffer( dir_buffer );
- current_key = 0;
- current_buffer = saveBuffer
- return;
- } else if ((numOfEntries == 1) && (!insert_prev_dir)) {
- #
- # only one file that matched, just set the prompt response
- #
- delete_buffer( dir_buffer );
- prompt_response = prompt_start lastname;
- current_buffer = saveBuffer
- current_key = KEYCODE_END
- return;
- }
-
- message( "File: " prompt_response )
-
- #
- # reset the position to the top of the list and highlight the
- # first entry
- #
- goto_buffer_top()
- drop_anchor( LINE_SELECTION )
-
- do {
- display_update(); # update the screen
-
- ch = getchar();
-
- if (ch == 0) {
- ch = getchar(); # expanded code, get rest of key
-
- if (ch == SCANCODE_DOWN) {
- menu_down_key(1)
- } else if (ch == SCANCODE_UP) {
- menu_up_key(1)
- } else if (ch == SCANCODE_PGUP) {
- menu_up_key( windowHeight )
- } else if (ch == SCANCODE_PGDN) {
- menu_down_key( windowHeight )
- } else if (ch == SCANCODE_HOME) {
- menu_home_key()
- } else if (ch == SCANCODE_END) {
- menu_end_key()
- } else if (ch == 0x23) { # HELP
- display_help_item( "directory menu" );
- } else if ((ch == SCANCODE_LEFT_PRESS) || \
- (ch == SCANCODE_LEFT_CLICK)) {
- menu_mouse_key()
- }
- } else {
- if (ch == ASCII_ESC) {
- remove_menu( 1 );
- current_key = KEYCODE_ESC
- return;
- } else if (ch == ASCII_BACKSPACE) {
- remove_menu( 1 )
- current_key = KEYCODE_END;
- return;
- } else if (ch == ASCII_CR) {
- cr_pressed = TRUE;
- } else if (chr(ch) ~ /[\\/]/) {
- remove_menu( 1 )
- current_key = ch
- return
- } else {
- dir_search_i( ch );
- }
- }
- } while ( !cr_pressed );
-
- #
- # read the response out of the buffer
- # and instruct prompt to accept it
- # immediately.
- #
- goto_bol()
- i = read_buffer()
- if ( edit_file_dir ){
- if ( match( i, / / )){
- i = substr( i, 1, RSTART-1 )
- }
- }
- prompt_response = prompt_start i
-
- remove_menu( 1 )
- if ( prompt_response ~ /\\$/ ) { # is it a subdir?
- current_key = 0;
- ungetkey( KEYCODE_TAB ) # yes, push a TAB
- } else {
- current_key = KEYCODE_ENTER # no, exit prompt with a CR
- }
- }
-
-
- ## perform an incremental search through the display list of file names
- # As the search pattern is entered, it is display in a dialog window
- # at the bottom of the screen and a highlight is placed over the
- # appropriate entry.
- #
- local function dir_search_i( ch ) {
- local pattern = "",
- char = "",
- level = 0,
- is_diag = 0+dialog_window;
-
- if (!is_diag) {
- toggle_dialog();
- }
- display_update();
-
-
- while (TRUE) {
-
- if ((ch == 0) || (ch == ASCII_ESC) || (ch == ASCII_CR)) {
- break;
- } else if (ch == ASCII_BACKSPACE) {
- #
- # remove the last char in the search string and
- # restore the previous position
- #
- pattern = substr( pattern, 0, length( pattern ) - 1)
- if (level) {
- raise_anchor()
- restore_position( TRUE );
- drop_anchor( LINE_SELECTION );
- level--;
- }
- } else {
- #
- # It is a normal ascii character.
- # Let's search for the new pattern. If we find it,
- # save the previous position and advance to the
- # newly found string.
- #
- char = chr( ch );
- raise_anchor();
- save_position();
- message( "Directory-Search for: %s\137", pattern char)
- if (search( "^" quote_regex(pattern char), \
- SEARCH_REGEX+SEARCH_MAXIMAL_MATCH+SEARCH_WRAPS+SEARCH_FORWARD+SEARCH_IGNORE_CASE)) {
- pattern = pattern char
- level++;
- } else {
- beep();
- restore_position( FALSE );
- }
- drop_anchor( LINE_SELECTION );
- }
- display_update()
-
- # display the prompt message with a fake cursor
- message( "Directory-Search for: %s\334", pattern)
-
- # get the next ascii character from the keyboard
- # ignore extended character which have an ascii code of 0
- ch = getchar()
- }
-
- message( "" );
-
- while (level--)
- restore_position( FALSE );
-
- toggle_dialog( is_diag );
- display_update();
- ungetkey( ch );
- }
-
-
- ## determine the buffer name of the current buffer.
- #
- local function defaultFileName(){
- if (historyArray[ historyName 0 ]) {
- prompt_response = buffer_name;
- current_key = KEYCODE_END
- } else {
- beep();
- }
- }
-
-
- #--------- display list of functions and allow movement within it --------#
-
-
- ## displayFunctionList()
- #
- # Display all of the functions available which start with
- # the pattern specified of at least two characters (zero or one might
- # take too long)
- #
- local function displayFunctionList() {
-
- local symbol_list
- local sorted_symbol_list
- local searchFor
- local priorBuffer = current_buffer
- local tempBuffer
- local numOfEntries
- local windowHeight
- local windowWidth
- local prefix
- local i
- local result
- local symbolMatchFlag = 0x0f
-
- current_key = 0
-
- # extract question mark
- if ( substr( prompt_response, 1, 1 ) == "?" ) {
- prefix = "?"
- searchFor = substr( prompt_response, 2 )
- } else {
- searchFor = prompt_response
- # uncomment the following line to omit variables from
- # <F10> command completion (if no "?" is present)
- #symbolMatchFlag = 0x05
- }
-
- # in case symbol_match takes a long time
- message( "Working..." )
-
- # read a list of all symbols beginning with the specified pattern
- if ( length( searchFor ) < 2 || !(symbol_list = \
- symbol_match( searchFor, symbolMatchFlag )) ) {
- message( "Command: " )
- beep()
- return
- }
-
- message( "" )
-
- # create a system buffer for the list
- current_buffer = tempBuffer = \
- create_buffer( "Function List", \
- "", \
- BUFFER_SYSTEM + BUFFER_NO_UNDO )
-
- # how many did we get?
- for (i in symbol_list) {
- sorted_symbol_list[ symbol_list[i] ] = numOfEntries++
- }
-
- # build the menu buffer
- for (i in sorted_symbol_list) {
- insert_string( i "\n" )
- if ( windowWidth < length(i)) {
- windowWidth = length(i)
- }
- }
- backspace() # delete the last newline
-
- delete( symbol_list ) # deallocate the arrays
- delete( sorted_symbol_list )
-
- # restore the old buffer for the current window
- current_buffer = priorBuffer
-
- if ( numOfEntries == 0 ) { # no match
- beep()
-
- } else if ( numOfEntries == 1 ) { # only one match
- prompt_response = prefix i
- current_key = KEYCODE_END
-
- } else {
-
- # create the window just wide enough for the longest string
-
- windowHeight = (numOfEntries > display_height - 8) \
- ? display_height - 8 \
- : numOfEntries;
- if ( windowWidth > (display_width - 20) ) {
- windowWidth = display_width - 20
- }
-
- result = menu_vertical( tempBuffer, \
- 10, display_height - windowHeight - 4, \
- windowWidth, windowHeight )
-
- if (result) {
- prompt_response = prefix result
- current_key = KEYCODE_END
- } else {
- current_key = KEYCODE_ESC
- }
- }
-
- delete_buffer( tempBuffer )
- }
-
-
- #--------------------- menu functions -------------------------------------#
-
- ## display a vertical menu at the given x,y,width,height coordinates
- # on the screen. The str contains the list of items for
- # the menu with a '\n' separating each entry.
- #
- # This function just inserts the string into a buffer and
- # calls menu_vertical.
- #
- # Use of the left mouse button to select entries is available.
- #
- global function list_vertical( str, x, y, width, height, rettype ){
- local cb = current_buffer;
- local buffer;
- local eol_str = default_buffer_eol_string;
-
- default_buffer_eol_string = "\n";
- current_buffer =
- buffer = create_buffer( "", "", BUFFER_SYSTEM+BUFFER_NO_UNDO+BUFFER_REAL_SPACE_ONLY );
- default_buffer_eol_string = eol_str;
-
- insert_string( str );
- current_buffer = cb;
-
- str = menu_vertical( buffer, x,y,width,height, rettype );
- delete_buffer( buffer );
- return str;
- }
-
-
- ## display a vertical menu at the given x,y,width,height coordinates
- # on the screen. The buffer is any system or regular buffer
- # containing the list of items for the menu with a '\n'
- # separating each entry.
- #
- # Use of the left mouse button to select entries is available.
- #
- # buffer = buffer where each line is an element of the menu
- # x,y,width,height = dimensions of menu box
- # rettype = 0 - return a string
- # = 1 - return index of selected item
- #
- global function menu_vertical( buffer, x, y, width, height, rettype ) {
- local retstr
- local ch
- local retindex;
-
- retindex = -1;
-
- init_menu_colors()
-
- saveWindow = current_window
- saveBuffer = current_buffer
-
- highlight_screen( x+1, y+1, width+2, height+2, SHADOW_COLOR )
-
- #
- # create the window using the dimensions given
- #
- current_window =
- create_factory_window( x,y,width+2,height+2, \
- WINDOW_MENU0 + WINDOW_SB_RIGHT )
-
- color_text = BAR_COLOR
- color_border = BAR_COLOR
- color_highlight = HBAR_COLOR
-
- attach_window_buffer( current_window, buffer )
-
- goto_buffer_bottom();
- if (current_line <= height)
- window_flags = and( window_flags, not( WINDOW_SB_RIGHT ));
-
-
- #
- # reset the position to the top of the list and highlight the
- # first entry
- #
- goto_buffer_top()
- drop_anchor( LINE_SELECTION )
-
- do {
- display_update() # update the screen
-
- ch = getchar()
-
- if (ch == 0) {
- ch = getchar() # expanded code, get rest of key
- if (ch == SCANCODE_DOWN) {
- menu_down_key(1)
- } else if (ch == SCANCODE_UP) {
- menu_up_key(1)
- } else if (ch == SCANCODE_PGUP) {
- menu_up_key( height )
- } else if (ch == SCANCODE_PGDN) {
- menu_down_key( height )
- } else if (ch == 0x23) { # HELP
- goto_bol()
- display_help_item( ltrim( trim( read_buffer())) )
- } else if (ch == 0x3B){ # F1
- goto_bol()
- library( read_buffer() );
- } else if ((ch == SCANCODE_LEFT_PRESS) || \
- (ch == SCANCODE_LEFT_CLICK)) {
- menu_mouse_key()
- }
- } else {
- if (ch == ASCII_ESC) {
- break
- } else if (ch == ASCII_CR) {
- #
- # read the response out of the buffer
- #
- goto_bol()
- retindex = current_line
- retstr = read_buffer()
- break
- } else {
- beep()
- }
- }
- } while (TRUE)
-
- remove_menu( 0 );
- return rettype ? retindex : retstr
- }
-
-
- ## take down a menu and associated buffer
- #
- local function remove_menu( del_buffer ) {
-
- # remove the selection
- raise_anchor()
-
- # optionally remove the system buffer
- if ( del_buffer ) {
- delete_buffer()
- }
-
- # remove the system window
- delete_window()
- if ( saveWindow ) {
- current_window = saveWindow
- }
-
- # retore the original buffer
- current_buffer = saveBuffer
-
- # remove the shadow window
- display_redraw()
-
- current_key = 0
- message( "" )
- }
-
-
- ## process a down key press from within a menu
- #
- local function menu_down_key( lines ) {
-
- if ( down( lines )) {
- #
- # redisplay the highlight on the new selection
- #
- raise_anchor()
- drop_anchor( LINE_SELECTION )
- }
- }
-
-
- ## process an up key press from within a menu
- #
- local function menu_up_key( lines ){
-
- if ( up( lines )) {
- #
- # redisplay the highlight on the new selection
- #
- raise_anchor()
- drop_anchor( LINE_SELECTION )
- }
- }
-
- ## process a home key press from within a menu
- #
- local function menu_home_key(){
-
- raise_anchor()
- goto_buffer_top();
- drop_anchor( LINE_SELECTION )
- }
-
- ## process an end key press from within a menu
- #
- local function menu_end_key(){
-
- raise_anchor()
- goto_buffer_bottom();
- drop_anchor( LINE_SELECTION )
- }
-
- ## process a mouse press from within a menu
- #
- global function menu_mouse_key(){
- local mousePos
-
- if ( window_contains( mouse_event_x, mouse_event_y )) {
- mousePos = mouse_position(1)
- if ( mousePos == MOUSE_IN_TEXT || mousePos == MOUSE_E ) {
-
- # track the mouse cursor, highlighting the
- # current line, for as long as the mouse cursor
- # is depressed
-
- setHighlightedScrolling( current_window )
- left_press( 1 )
- goto_bol()
- display_update()
- setHighlightedScrolling( 0 )
-
- if ( !region_type() ) {
- drop_anchor( LINE_SELECTION )
- }
-
- if ( mousePos == MOUSE_E ) { # right scroll bar
- return 1
- }
-
- # if they end up in the text region, consider
- # it a selection
- if ( window_contains( mouse_event_x, mouse_event_y ) &&
- !window_border_contains(
- mouse_event_x, mouse_event_y )) {
- ungetkey( KEYCODE_ENTER )
- }
- }
- return 1
- }
-
- # mouse was clicked outside of current window
- ungetkey( KEYCODE_ESC )
- return 0
- }
-