Key codes, Assigning actions, Default actions

Key codes

    For assigning actions to keys a configuration language has been designed. It is mostly based on the configuration language of Marko Macek's text editor FTE.

    Describing key code seems to be basic part of such a language. So let us start with it. Here is the grammer in BNF format:

      keycode :== '[' key_with_mod { '_' key_with_mod }* ']'
      key_with_mod :== modifier [ '+' | '-' ]  key
                     | key
      modifier :== 'C'
                 | 'S'
                 | 'A'
      key :== 'HOME'
            | 'LEFT'
            | 'END'
            etc.
    
    The modifier declares states of Shift, Control and Alt keys. The plus and minus signs determine if such modifier should be pressed (plus) or its state does not matter (minus).

    For example use:

    • [C+S+A-0] if you would like to test if Ctrl and Shift are down together with key '0' and you do not care about the Alt.
    • [C+S+A+X] to test if all modifiers are down and key X is pressed
    • [Z] means code Z and no modifier must be down
    • [C-A-S-Z] means Z again but the editor does not care about state of modifiers
    The key part identifies the key that should be pressed. For these purposes digits (0, 1, ..., 9), literals (A, ..., Z) and special constants ( HOME, END, LEFT, RIGHT, UP, DOWN, PGUP, PGDN, ENTER, DEL, BACKSP, ESC, F1,..., F12) can be used.

    As example [S+ENTER] means shift combined with enter. [S+S] means key S together with shift modifier.

    Not only one key but also a sequence of keys can be defined. To achive this you need only to join two key definition by underscope. As an example let's show how the clasic WordStar block copy sequnce can be described in our language:

    • [C+K_C] says that first of all you need to press key K together with Ctrl and then release all modifiers and press key C
    • [C+K_C-C] seems to be a better solution. Because the second key can now be pressed with or without Ctrl and this solves common problem of releasing Ctrl before pressing C.
    It is of course possible to define longer sequences. There are no limitations or restrictions.

Assigning actions

    Actions are predefined operations with the editor. To follow the Java spirit and achive maximum flexibility each actions is represented as one class. The predefined standard actions are stored in package xelfi.editor.actions but this is not requiered. Action can be any Java class in any package that implements xelfi.editor.keys.KeyActionHandler interface.

    To assign a action to for example left arrow the following code can be inserted into configuration file.

      key [LEFT] { MoveLeft; }
      key [S+LEFT] { BlockExtendBegin; MoveLeft; BlockExtendEnd; }
    
    The first line says that on LEFT arrow action MoveLeft (that moves the cursor one character to the left) should be called. The second line claims that on LEFT arrow together with Shift key the three actions should be executed with result that they extends marked block.

    Because actions are valid Java classes stored in packages the standard Java notation can be used to access them.

    • xelfi.extention.OpenBrowser describes action that is in class OpenBrowser in package xelfi.extention. (this is only example, no such action realy exists).
    • xelfi.editor.actions.MoveRight is action in class MoveRight in package xelfi.editor.actions.
    • MoveRight without any package specification also describes action in xelfi.editor.actions.MoveRight. That is because the package xelfi.editor.actions is always imported.
    It is possible to include other packages and actions too. And for this purpose command import can be inserted into configuration file.
      import xelfi.extension.OpenBrowser;
      import xelfi.additional.actions.*;
    
    As mention before remember that xelfi.editor.actions is always imported.

    To actions parameters can be passed. The type of parameters depends on action that should accept them but in generaly parameter can be of type string, character or integer number. As an example let us have a look at function InsertText that inserts text at cursor possition. The text is taken from its parameter.

      // instead of new line text
      //  Greetings from editor
      // is displayed.
      key [ENTER] { InsertText "Greetings from editor"; }
    

    Because default action on many keys is insert of itself it is not requiered to write such action for each alphanumeric character. Instead the editor inserts the character automaticly when no other action is assigned.

Default editor actions

    Default actions are predefined in package xelfi.editor.actions and because this package is allways imported they can be referenced without package prefix.
    • BackSpace deletes one character before cursor. If there is no nonspace character before the cursor till begin of line, the cursor aligns with the begin of word on previous line.
    • BlockBegin marks begin of selected block
    • BlockEnd marks end of selected block
    • BlockCopy copies content of selected block into clipboard
    • BlockCut also copies the block to clipboard; moreover deletes the block from text editor
    • BlockDirectCopy copies the selected block to cursor position
    • BlockDirectMove moves the selected block cursor position
    • BlockExtendBegin starts extending selected block
    • BlockExtendEnd ends extending
    • BlockIndent moves selected block one character to left
    • BlockUnindent moves selected block one character to right
    • BlockKill deletes content of selected block
    • BlockPaste insert text from clipboard
    • BlockUnmark unmarks selected block
    • Find opens find dialog
    • PlaceBookmark name_of_bookmark remembers current position of cursor and stores it under the name_of_bookmark which must be string.
    • GotoBookmark name_of_bookmark changes position of cursor to previously stored bookmark. If the mark has not been stored yet no change is done.
    • GotoBookmarkCol name_of_bookmark changes position of cursor but only its column it remains on the same line
    • GotoBookmarkRow name_of_bookmark changes line of cursro's position, the column remains the same
    • GoToLine opens go to line dialog
    • InsertIndent insert spaces to align cursor with the line above
    • InsertTab inserts spaces to stop on next TAB position
    • InsertText string inserts text at cursor position needs one string parameter
    • KillBlockOrChar deletes selected block if selected, otherwise deletes character at cursor position
    • KillChar deletes character at cursor position
    • KillCharPrev deletes character one position before cursor
    • KillLine deletes whole line where is cursor
    • KillToLineEnd deletes text from cursor position till end of line
    • KillToLineStart deleltes text from line begining to cursor position
    • KillWord deletes rest of word from cursor position
    • KillWordPrev deletes text from begin of word till cursor position
    • MoveBlockEnd moves cursor to the end of selected block
    • MoveBlockStart moves cursor to the begin of selected block
    • MoveFileEnd moves cursor
    • MoveFileStart moves cursor
    • MoveDown moves cursor
    • MoveLeft moves cursor
    • MoveLineEnd moves cursor
    • MoveLineStart moves cursor
    • MoveNext moves cursor one character to right. If end of line is reached then cursor is moved to begin of next one
    • MoveNextTab moves cursor to next TAB
    • MovePageDown moves cursor
    • MovePageEnd moves cursor
    • MovePageStart moves cursor
    • MovePageUp moves cursor
    • MovePrev moves cursor one character to left. If begin of line is reached cursor is moved to end of previous one
    • MovePrevTab moves cursor
    • MoveRight moves cursor
    • MoveUp moves cursor
    • MoveWordLeft moves cursor to previous word. Stops on line beginings and ends
    • MoveWordNext moves cursor to previous word. Does not stops at line beginings and ends
    • MoveWordPrev moves cursor to next word. Stops on line beginings and ends
    • MoveWordRightmoves cursor to next word. Does not stops at line beginings and ends
    • NewLine inserts new line and indents cursor to be aligned with first character on previous line
    • ScrollDown scrolls with screen view
    • ScrollUp scrolls with screen view
    • SelfInsert insert the currently pressed character. This is usually default action the is done by editor if no other action is assigned
    • Undo Undoes last action.
    At the end of this tutorial we would like to encourage you to write us if you create your own key configuration file. Do not wait if you have something useful that could come handy for others too.

    Xelfi Technologies