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

Inline edit field

 [1/3] from: henrik:webz:dk at: 25-Feb-2004 21:01


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. 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? I'm using the latest beta 1.2.40 to test this. -- Regards, Henrik Mikael Kristensen

 [2/3] 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
<<quoted lines omitted: 6>>
> 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
<<quoted lines omitted: 3>>
> 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 ;~>

 [3/3] from: brett::codeconscious::com at: 27-Feb-2004 22:20


> 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?
Focus directs keystroke events to a specific face - the focal face. When a Field is the focal-face, its Feel object (ctx-text/edit) has an Engage function which processes Key events - it actually delegates the key processing to another function (ctx-text/edit-text). The Edit-text function performs focussing functionality when it receives Enter and Tab keys. As Ammon pointed out you can intercept key events using an event function. Alternatively you can use a detect function in any face that contains the focal-face (the parent-face or the parent of the parent,etc) For example - here panel intercepts events directed to the box - type some keys to test it: view layout [ style testbox box green feel [ engage: func [face action event] [ if event/key [print [face/var event/key]] ] ] p1: panel feel [ detect: func [face event] [ print [event/type event/key] event ; Must return the event or None ] ] [ b1: testbox] do [focus b1] ] HTH Brett.

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted