Limit Field Length
[1/2] from: jrichards10::adelphia::net at: 2-Mar-2003 8:17
Content-Type: Text/Plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
=0D
Hi All,=0D
=0D
Is there a quick and easy way to limit the amount of data put into a View
field?=0D
=0D
Thanks
-- Binary/unsupported file stripped by Listar --
-- Err : No filename to use for decode, file stripped.
-- Type: image/gif
[2/2] from: carl:cybercraft at: 3-Mar-2003 9:50
On 03-Mar-03, Jim Richards wrote:
> Hi All,
>
> Is there a quick and easy way to limit the amount of data put into a
> View field?
Hi Jim,
Not sure if it's quick and easy, but you can do it by using a modified
feel/engage. See what a standard engage function looks like by
entering the following at the console...
layout [f: field] probe f/feel
The key block there is where key presses are processed, so you can
block them at that point if you wish. So, here's a modified version
of engage with an example of how to use it. Hope it helps...
rebol []
new-engage: func [face act event][
switch act [
down [
either not-equal? face system/view/focal-face [
focus face
system/view/caret: offset-to-caret face event/offset
] [
system/view/highlight-start:
system/view/highlight-end: none
system/view/caret: offset-to-caret face event/offset
]
show face
]
over [
if not-equal? system/view/caret offset-to-caret face
event/offset [
if not system/view/highlight-start [
system/view/highlight-start: system/view/caret
]
system/view/highlight-end: system/view/caret:
offset-to-caret face event/offset
show face
]
]
key [
if any [
; Alter or add to these conditions to restrict key
; behaviour.
5 > length? face/text
event/key = #"^M" ; Return
event/key = #"^~" ; Delete
event/key = #"^H" ; Backspace
event/key = #"^-" ; Tab
event/key = 'left
event/key = 'right
][
system/words/ctx-text/edit-text face event get in face
'action
]
]
]
]
view layout [
across
label "Normal Field:" right 120 field
return
label "Limited Field:" right 120 field feel [engage: :new-engage]
]
--
Carl Read