KeyboardMap.st
branchjv
changeset 8037 d01faa4c1b02
parent 8036 e248f3b96260
child 8420 76e39223f5ab
equal deleted inserted replaced
8036:e248f3b96260 8037:d01faa4c1b02
    72     Typical prefixes are Cmd (for Alt or Meta), Ctrl etc.
    72     Typical prefixes are Cmd (for Alt or Meta), Ctrl etc.
    73     Some keyboards offer both Alt and Meta keys - on those, the first has a
    73     Some keyboards offer both Alt and Meta keys - on those, the first has a
    74     prefix of Alt, the second has Cmd as prefix. Keyboards with only an Alt
    74     prefix of Alt, the second has Cmd as prefix. Keyboards with only an Alt
    75     key will will create prefix codes of Cmd for that.
    75     key will will create prefix codes of Cmd for that.
    76 
    76 
       
    77     A convenient way to create initialize a keyboard map is to use
       
    78     #loadKeyboadMapDefinition: as in:
       
    79 
       
    80         |m|
       
    81 
       
    82         m := Display keyboardMap.
       
    83         m loadKeyboadMapDefinition: #(
       
    84             (Cut    Ctrlx   Cmdx)
       
    85             (Copy   Ctrlc   Cmdc)
       
    86             (Paste  Ctrlv   (Cmdv ShiftInsert)
       
    87         )
       
    88 
       
    89     For details about the format of definition array see commebt in
       
    90     KeyboardMap >> #loadKeyboardMapDefinition: .
       
    91 
    77     To remove a mapping, use the same value for both logical and physical key,
    92     To remove a mapping, use the same value for both logical and physical key,
    78     as in:
    93     as in:
    79 
    94 
    80         |m|
    95         |m|
    81 
    96 
    82         m := Display keyboardMap.
    97         m := Display keyboardMap.
    83         m bindValue:#Cmdd to:#Cmdd.
    98         m bindValue:#Cmdd to:#Cmdd.
    84 
       
    85     In addition to (primary) shortcut mapping (defined by #bindValue:to:) one may also
       
    86     define an alias, kind of secondary mapping. This is to support users coming from other
       
    87     environments with other default shortcuts so 'their' shortcuts just work without need
       
    88     to manually customize Smalltalk/X. Just to be a little friendly to foreigners.
       
    89 
       
    90     To define an alias, use #bindAlias:to: as in:
       
    91 
       
    92         |m|
       
    93 
       
    94         m := Display keyboardMap.
       
    95         m bindAlias:#Paste to:#Shiftnsert.
       
    96 
    99 
    97     [see also:]
   100     [see also:]
    98         WindowEvent WindowSensor WindowGroup
   101         WindowEvent WindowSensor WindowGroup
    99         View DeviceWorkstation
   102         View DeviceWorkstation
       
   103         KeyboardMap >> #loadKeyboardMapDefinition:
   100 
   104 
   101     [author:]
   105     [author:]
   102         Claus Gittinger
   106         Claus Gittinger
       
   107         Jan Vrany
   103 "
   108 "
   104 ! !
   109 ! !
   105 
   110 
   106 !KeyboardMap class methodsFor:'instance creation'!
   111 !KeyboardMap class methodsFor:'instance creation'!
   107 
   112 
   454     Screen current keyboardMap rawKeysForLogical: #Copy
   459     Screen current keyboardMap rawKeysForLogical: #Copy
   455     "
   460     "
   456 
   461 
   457     "Created: / 08-02-2017 / 23:43:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   462     "Created: / 08-02-2017 / 23:43:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   458     "Modified: / 15-05-2017 / 21:29:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   463     "Modified: / 15-05-2017 / 21:29:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   464 
       
   465     Screen current keyboardMap valueFor: #Alti
       
   466     "Modified (comment): / 14-05-2017 / 10:44:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   459 ! !
   467 ! !
   460 
   468 
   461 !KeyboardMap methodsFor:'testing'!
   469 !KeyboardMap methodsFor:'testing'!
   462 
   470 
   463 isKeyboardMap
   471 isKeyboardMap
   464     ^ true
   472     ^ true
   465 ! !
   473 ! !
   466 
   474 
       
   475 !KeyboardMap methodsFor:'utilities'!
       
   476 
       
   477 loadKeyboardMapDefinition: definitions
       
   478     "Load keyboard mapping from given `definition`. The `definition` is a collection
       
   479      mapping definitions. Each mapping definition is an array consisting of:
       
   480 
       
   481         #( <logical key>     <primary shortcut>  <aliases>?  <description>? )
       
   482 
       
   483     where:
       
   484         <logical key>   the symbolic name of the action as used in menu specs
       
   485                         #keyPress:x:y: methods and so on.
       
   486                         Examples: #Copy, #Find, #Undo
       
   487 
       
   488         <primary shortcut> the actual shortcut in Smalltalk/X key event notation.
       
   489                         This is the shortcut that will be shown in menus and/or
       
   490                         tooltips and so.
       
   491                         Examples: #Ctrlv (means Ctrl + V), CmdF (means Alt + Shift + F), F10
       
   492 
       
   493         <aliases>       an alternative shortcut or array of those. Aliases won't be shown in
       
   494                         menu items but one may define some for user's convenience (for exampple,
       
   495                         define aliases used in other environments so users using both can just
       
   496                         keep using them. Optional.
       
   497                         Examples: #Ctrlv, #(#Cmdv #ShiftInsert)
       
   498 
       
   499         <description>   A textual description of the action. This may be used to generate some
       
   500                         form of documentation. Optional.
       
   501                         Examples: 'DoIt - evaluate expression', 'Replace selection with today''s date'
       
   502 
       
   503     "
       
   504     definitions do:[:definition | 
       
   505         | logical shortcut aliases|
       
   506 
       
   507         logical := definition first.
       
   508         shortcut := definition second.
       
   509         "/ aliases are optional as well as description, so it may happen that third
       
   510         "/ element is description rather than alias. Hence the check.
       
   511         aliases := (definition size > 2) ifTrue:[ definition third ] ifFalse:[ #() ].
       
   512         aliases isSymbol ifTrue:[ aliases := Array with: aliases ].
       
   513         aliases isArray ifFalse:[ aliases := #() ].
       
   514 
       
   515         self bindValue: logical to: shortcut.
       
   516         aliases do:[:alias | self bindAlias: logical to: alias ]
       
   517     ].
       
   518 
       
   519     "
       
   520     KeyboardMap new loadKeyboardMapDefinition: #( (Paste Ctrlv (Cmdv CtrlInsert)) )
       
   521     KeyboardMap new loadKeyboardMapDefinition: #( (Paste Ctrlv Cmdv) )
       
   522     KeyboardMap new loadKeyboardMapDefinition: #( (Paste Ctrlv 'Paste') )   
       
   523     "
       
   524 
       
   525     "Created: / 12-05-2017 / 22:12:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   526     "Modified (comment): / 14-05-2017 / 10:24:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   527 ! !
       
   528 
   467 !KeyboardMap class methodsFor:'documentation'!
   529 !KeyboardMap class methodsFor:'documentation'!
   468 
   530 
   469 version
   531 version
   470     ^ '$Header: /cvs/stx/stx/libview/KeyboardMap.st,v 1.15 2014-12-18 16:13:06 cg Exp $'
   532     ^ '$Header: /cvs/stx/stx/libview/KeyboardMap.st,v 1.15 2014-12-18 16:13:06 cg Exp $'
   471 !
   533 !