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

[REBOL] Re: Inline edit field

From: ammon:addept:ws at: 25-Feb-2004 16:17

----- Original Message ----- From: "Henrik Mikael Kristensen" <[henrik--webz--dk]> To: <[rebol-list--rebol--com]> Sent: Wednesday, February 25, 2004 1:01 PM Subject: [REBOL] Inline edit field
> Hi > > I'm trying to put together a real inline edit field, such as the one > used in spreadsheets or in the Windows file requester when renaming a > file, and I can't find anything related directly to what I want to do. > > Basically I'm using a button and change the feel to that of a field and > I want the Enter key, tab, escape or clicking outside the field to > revert the feel to button with new contents. > > It seems that ctx-text/edit makes the field editable, but I can't figure > out how to make it behave as a single line edit field and how to get out > of the editing state again in a simple fasion.
You can change the way any face reacts to any key-press by altering the FEEL/ENGAGE function. This: feel/engage: func [f a e] [ if e/key [print e/key] ] will print the key that has been pressed if indeed a key has been pressed. I would recomend building your own custom feel that does just what you want (i.e. special case handling for Esc, Enter and Tab) and then create a function that looks something like this... ;********************************************************** ; WARNING! Untested Code ;********************************************************** custom-feel: make ctx-text/edit [ ;your engage funciton goes here ] current-face: none set-feel: func [face event][ if event/type = 'down [ if none? current-face [current-face: event/face] either current-face = event/face [ current-face/feel: custom-feel ][ current-face/feel: ctx-text/swipe current-face: event/face current-face/feel: custom-feel ] ] event ] insert-event-func :set-feel using insert-event-func plugs your function into the event pipeline so whatever you do, you want to make sure that your event-func *always* returns the event that is passed to it. Also this particular function will only handle mouse presses and sets the face's feel no matter what face it is. You will prolly need to set the TYPE facet to a particular value and check for this before setting the feel. To handle keyboard events you can actually alter the event-func I gave you and just check for the event/type to be 'key instead of 'down. I would recomend making sure that none of your faces has 'return or 'tabbed in their FLAGS facet (more on the FLAGS facet below...) and handle them all on your own via the event-func.
> Probing the feels of the button, field and textarea gadgets with: > > layout [r: button] probe r/feel > layout [r: field] probe r/feel > layout [r: textarea] probe r/feel > > reveals the code to do this, and I can't figure out how field captures > an enter or tab key to unfocus the field, where a textarea sets it to a > new line. The button behaves the same way. Any ideas?
The FLAGS facet controls this...
>> get in (get-style 'field) 'flags
== [field return tabbed on-unfocus]
>> get in (get-style 'area) 'flags
== [tabbed on-unfocus]
>> get in (get-style 'button) 'flags
== [] That should give you enough info to get you started. HTH ~~Ammon ;~>