Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] [view] field key trapping hook [patch]!

From: moliad::aei::ca at: 26-Aug-2006 3:03

here is a patch function which will allow you guys the capability to trap key events outside of the normal view operation. basically, you can trap key events and do anything you like with them without breaking normal view field input. When you are done, you decide if you want those key presses to continue to the normal text editing, by returning true or false in your hook function. in theory this is only guaranteed to work for version 1.3 , but it might work in older versions too. ;-------------------------------------------- the patching func ----------------------------------------------- hookup-field: func [ face [object!] hook [function!] /all "all fields sharing the same feel as the supplied face will be hooked" /local blk bword ][ unless all [ face/feel: make face/feel []; appy the hook to this field only. ] engage: get in face/feel 'engage blk: at third second :engage 6 bword: second second :engage change/only blk bind compose/deep [unless hook face event (blk)] bword ] ;------------------------------------------------------------------------------------------- here is a short example on how to use this, you can replace the key-hook by any appropriate function you need, obviously. This example simply unfocuses the field when escape is pressed, without calling the action func. something I've often found usefull. ;---------------------------------- an examble using the patch ----------------------------------------------------- key-hook: func [face event][ ; escape key calls unfocus! (without calling action) either event/key = #"^[" [ unfocus face ; we consumed the event, do not let view know about it. true ][ ; we did not consume the event, continue as normal. false ] ] view/new layout [fld: field button "close" [unview]] hookup-field fld :key-hook do-events ;------------------------------------------------------- have fun :-) -MAx