eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'EditField':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: EditField


Inheritance:

   Object
   |
   +--GraphicsMedium
      |
      +--DisplaySurface
         |
         +--SimpleView
            |
            +--View
               |
               +--ListView
                  |
                  +--TextView
                     |
                     +--EditTextView
                        |
                        +--EditField
                           |
                           +--EditFieldWithCompletion
                           |
                           +--FilenameEditField

Package:
stx:libwidg
Category:
Views-Text
Version:
rev: 1.313 date: 2024/04/29 13:35:04
user: cg
file: EditField.st directory: libwidg
module: stx stc-classLibrary: libwidg

Description:


an editable text-field. Realized by using an EditTextView,
and forcing its size to 1 line - disabling cursor movement
in the vertical direction.

Basically, an editField is an editor for a single line text,
and provides the usual access protocol as defined in its superClasses
(especially: #contents / #contents:).

The above underlying internal mechanism can be used for fields which
are passive; i.e. into which text can be entered and the value (string)
is extracted actively by someone else.

accepting:
  The opposite way to use editFields is to connect them to a model
  and let the field notify changes to it.
  This notification is called ``accepting''.
  Unless accepted, the models value is not updated from the editFields contents
  this default is the normal operation and way things should work, since most
  uses of editFields are not interested in every individual change
  (i.e. getting each keyStroke when a long number is entered).
  The default behavior is to ``accept'' when either return or a cursorUp/Down
  key is pressed in a field.
  However, the field can setup to accept/not accept on leave, on return
  or on each individual key input.
  See the method's #acceptOnLeave: / #acceptOnReturn: / #immediateAccept.

  In addition, the set of keys which are considered ``leaveKeys'' can be
  specified by #leaveKeys: (in case you need keys other than Return, CursorUp/Down).

models value vs. field contents:
  Although the field internally keeps its contents as some string object,
  the application may prefer to think of numbers, floats, yes/no values etc.
  To support this, a converter may defined, which is responsible for conversion of
  strings to/from the models domain value.
  If present (i.e. nonNil), the converter is asked to convert a string to the models
  domain with #readValueFrom:aString and vice versa, a value to a string by #printStringFor:.
  The PrintConverter class already provides a number of standard conversions, see the examples.
  To access a converted value directly (i.e. not via the model), use #editValue.

grouping:
  Individual fields do not know about being included in a group. This must be arranged on the
  outside, by placing multiple fields into an EnterFieldGroup.
  This groupObject keeps a reference to one active field, and forwards input from any other
  field to the active one. Also have a look at the examples for this.

input completion:
  To support input completion (i.e. filename completion, classname completion etc.),
  a completionBlock can be defined which (if non-nil) is evaluated when the completion-key
  is pressed and its value is taken as the new field-contents. 
  The physical completion-key is the Tab key (this one cannot be defined by
  the keyboardTranslation mechanism, since that would disable the Tab-key on regular text views.

special key handling:
  usually, editFields are embedded in a form (as in a dialog), 
  which has OK and Cancel buttons at the bottom.
  However, if the editField is in some other popup, it may be required to customize its behavior
  upon certain key events. 
  For this, the following flags are used:
    leaveKeys       - the set of keys, which will lead to an accept (of the value into the model),
                      and leave the focus. If that happens, the responsible key is left in the leaveKey variable.
                      Default are CursorUp, Down and Return

    leaveAction     - if not nil, that action is called after the accept, passing the leaveKey as argument

    acceptOnLeave   - if true, an accept will be performed on leave.

    cancelKeys      - the set of keys which will leve without accepting. If that happens, the responsible
                      key is left in the cancelKey variable.

    cancelAction    - if not nil, that action is called, passing the cancelKey as argument.

    
[Instance variables:]

  leaveAction    <Block | nil>              if non-nil, this is evaluated with
                                            the key (#Return, #CursorUp etc.) when
                                            the field is left via keyboard keys.
                                            (fieldGroups use this to decide which
                                             field has to be enabled next)

  enabled        <Boolean>                  if false, input is ignored.

  clickAction    <Block | nil>              action performed if the field is
                                            clicked upon.
                                            (this is used by the group to
                                             set the active field to the clicked upon field)

  crAction       <Block | nil>              if non-nil, keyboard input of a cr are not
                                            handled specially, instead this block is evaluated
                                            (however, this block can perform additional checks and send
                                             a #accept then)

  tabAction      <Block | nil>              if non-nil, keyboard input of a tab character
                                            is not entered into the text, instead this block
                                            is evaluated. Also, no input completion is performed if
                                            tabAction is nonNil.

  converter      <PrintConverter | nil>     if non-nil, this is supposed to convert between
                                            the object and its printed representation and vice versa.
                                            Defaults to nil i.e. assume that strings are edited.

  leaveKeys      <Collection>               keys which are interpreted as 'leaving the field'

  immediateAccept   <Boolean>               if true, every change of the text is immediately
                                            forwarded to the model/acceptBlock. If false,
                                            the changed value is only stored in the model
                                            if the field is left or accepted.
                                            Default is false.

  acceptOnLeave  <Boolean>                  if true, leaving the field (via cursor keys)
                                            automatically accepts the value into the model.
                                            Default is true.

  acceptOnReturn <Boolean>                  if true, leaving the field via return
                                            automatically accepts the value into the model.
                                            Default is true.

  acceptOnTab    <Boolean>                  if true, the Tab key accepts and leaves the field.
                                            If false, Tabs are entered into the contents field like
                                            ordinary non-control keys.
                                            AcceptOnTab is ignored if the entryCompletion block is nonNil.
                                            Default is true.

  lengthLimit    <Number>                   the max. number of allowed characters

  entryCompletionBlock <BlockOrNil>         if non-nil, this is evaluated to complete the entry
                                            when <entryCompletionCharacter> is pressed.
                                            Entry completion is used with Filenamefields or in the
                                            browser for classname/selector completion.
                                            Setting a nonNil entryCompletion disables acceptOnTab.

  entryCompletionCharacter <CharacterOrNil> if non-nil AND entryCompletionBlock is nonNil, that one
                                            is evaluated for completion. Typically used to complete
                                            a fileName (also, classNames in the browser)
                                            Default is #Tab.

  passwordCharacter     <CharacterOrNil>    if non-nil, typed input is replaced by this character
                                            for display. Used for secret-input fields (such as password entry).
                                            Default is nil.

copyright

COPYRIGHT (c) 1990 by Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

defaults
o  defaultBorderColor

o  defaultBorderWidth

o  defaultLeaveKeys
return the set of keys which are taken as leave-keys.
If the field is in an enterFieldGroup, all leave keys will be
forwarded to the group and possible step to the next/previous field.
Also, if acceptOnLeave is true, leave keys will store the current
value into their model (if any)

o  defaultLevel

o  defaultNumberOfLines
the number of lines in the field

o  updateStyleCache
extract values from the styleSheet and cache them in class variables

Usage example(s):

     self updateStyleCache

image specs
o  hidePasswordIcon24x24
This resource specification was automatically generated
by the ImageEditor of ST/X.

Usage example(s):

     self hidePasswordIcon24x24 inspect
     ImageEditor openOnClass:self andSelector:#hidePasswordIcon24x24
     Icon flushCachedIcons

o  showPasswordIcon24x24
This resource specification was automatically generated
by the ImageEditor of ST/X.

Usage example(s):

     self showPasswordIcon24x24 inspect
     ImageEditor openOnClass:self andSelector:#showPasswordIcon24x24
     Icon flushCachedIcons


Instance protocol:

accepting
o  accept
accept the current contents by executing the accept-action and/or
changeMessage.
Do this only if the contents of the EditField differs
from the printed representation of the model.

accessing-behavior
o  acceptIfUnchanged
return the acceptIfUnchanged flag setting.
if set (the default), an accept notification is sent on accept,
even if the fields value is the same. If cleared,
the notification is suppressed, if the fields contents is the same.

o  acceptIfUnchanged: aBoolean
if set (the default), an accept notification is sent on accept,
even if the fields value is the same. If cleared,
the notification is suppressed, if the fields contents is the same.

o  acceptOnLeave
return the acceptOnLeave flag. The default is false.
If true, leaving the box (via return, cursor etc.) accepts my
string into the valueHolder (if any).
(actually, the set of keys can be specified with #leaveKeys:)

o  acceptOnLeave: aBoolean
set/clear the acceptOnLeave flag. The default is false.
If true, leaving the box (via return, cursor etc.) accepts my
string into the valueHolder (if any).
(actually, the set of keys can be specified with #leaveKeys:)

o  acceptOnLostFocus

o  acceptOnLostFocus: aBoolean
set/clear the acceptOnLostFocus flag. The default is false.
If true, a lost focus (via mouse-pointer motion etc.) accepts my
string into the valueHolder (if any).

o  acceptOnPointerLeave: aBoolean
set/clear the acceptOnPointerLeave flag. The default is false.
If true, a pointer leave (via mouse-pointer motion etc.) accepts my
string into the valueHolder (if any).

o  acceptOnReturn: aBoolean
set/clear the acceptOnReturn flag. The default is false.
If true, leaving the box via return accepts my
string into the valueHolder (if any).

o  acceptOnTab: aBoolean
set/clear the acceptOnTab flag. The default is true.
If true, a pressed Tab key accepts and leaves the box.
If false, the Tab key is treated like any normal input character
(i.e. inserted into the contents).

o  autoScroll: aBoolean
turn on/off automatic scrolling upon keyboard entry
to make the cursor visible.

o  cancelKey
only valid after the editField has been left via a cancelCharacter.
Allows for users of the EditField to advance the selection
(especially: DataSets to select next/prev if editor is left via CrsrUp/Down).
This is probably a stupid interface - better use onKey:cancelWith: for a directed action

o  cancelKeys
return (a copy of) the collection of keys which are interpreted as cancelKeys.
I.e. those that make the field inactive and pass the focus to the next field
(without accept)

o  cancelKeys: aCollectionOfKeySymbols
define the set of keys which are interpreted as cancelKeys.
I.e. those that make the field inactive without accept.

o  clickAction: aBlock
define an action to be evaluated when being clicked upon

o  converter
return the converter (if any).

o  converter: aConverter
set the converter. If non-nil,
the converter is applied to the text to convert from the string
representation to the actual object value and vice versa.
The default converter is nil, meaning no-conversion
(i.e. the edited object is the string itself.

Usage example(s):

     |field model|

     model := 0.5 asValue.
     field := EditField new.
     field model:model.
     field converter:(PrintConverter new initForNumber).
     model onChangeEvaluate:[ Transcript showCR: model value ].
     field open.

o  crAction: aBlock
define an action to be evaluated when the return key is pressed.

o  doubleClickAction: aBlock
define an action to be evaluated when being double clicked upon

o  enabled
return true, if the field is enabled (i.e. accepts keyboard input)

o  enabled: aBoolean
enable/disable the field; show/hide the cursor and allow/disallow input

o  entryCompletionBlock
the action to be evaluated when Tab (EntryCompletionCharacter) is pressed.
The block gets the current contents and the field itself as optional arguments
(i.e. it can be a 0, 1 or 2-arg block).

Usage example(s):

read comment in entryCompletionBlockHolder: on why the following kludge is present

o  entryCompletionBlock: aZeroOneOrTwoArgBlock
define an action to be evaluated when Tab (EntryCompletionCharacter) is pressed.
The block gets the current contents and the field itself as optional arguments
(i.e. it can be a 0, 1 or 2-arg block).

o  entryCompletionBlockHolder: aZeroOneOrTwoArgBlock
a holder for an action to be evaluated when Tab (EntryCompletionCharacter) is pressed.
The block gets the current contents and the field itself as optional arguments
(i.e. it can be a 0, 1 or 2-arg block).

o  entryCompletionCharacter
return the value of the instance variable 'entryCompletionCharacter' (automatically generated)

o  immediateAccept: aBoolean
set/clear the immediateAccept flag. The default is false.
If true, every pressed key immediately accepts my
string into the valueHolder (if any).

o  isAcceptOnLeave
return the acceptOnLeave flag. The default is false.
If true, leaving the box (via return, cursor etc.) accepts my
string into the valueHolder (if any).
(actually, the set of keys can be specified with #leaveKeys:)

o  isAcceptOnLostFocus
return the acceptOnLostFocus flag. The default is false.
If true, a lost focus (via mouse-pointer motion etc.) accepts my
string into the valueHolder (if any).

o  isAcceptOnReturn
return the acceptOnReturn flag. The default is false.
If true, leaving the box via return accepts my
string into the valueHolder (if any).

o  isAcceptOnTab
return the acceptOnTab flag. The default is true.
If true, a pressed Tab key accepts and leaves the box.
If false, the Tab key is treated like any normal input character
(i.e. inserted into the contents).

o  isImmediateAccept
return the immediateAccept flag. The default is false.
If true, every pressed key immediately accepts my
string into the valueHolder (if any).

o  leaveAction: aBlock
define an action to be evaluated when field is left by a leave-key
(by default: return or cursor keys.
Actually, the set of keys can be specified with #leaveKeys:
On leave, the precedence of actions is:
1) explicit leaveAction per key
2) this general leaveAction
3) tab or return action

o  leaveKey
only valid after the editField has been left via a leaveCharacter.
Allows for users of the EditField to advance the selection
(especially: DataSets to select next/prev if editor is left via CrsrUp/Down).
This is probably a stupid interface - better use onKey:leaveWith: for a directed action

o  leaveKeys
return (a copy of) the collection of keys which are interpreted as leaveKeys.
I.e. those that make the field inactive and pass the focus to the next field
(and accept, if acceptOnLeave is true)

o  leaveKeys: aCollectionOfKeySymbols
define the set of keys which are interpreted as leaveKeys.
I.e. those that make the field inactive and accept (if acceptOnLeave is true).
The default is a set of #CursorUp, #CursorDown, #Next, #Prior and #Return.

o  makeTabable
arrange for Tab to accept & leave the field
If the field is part of a group, the next field gets the
input focus

o  onKey: aKey cancelWith: aBlock
arrange for aKey to leave the field (without accept) and evaluate aBlock.
On cancel, the precedence of actions is:
1) explicit cancelAction per key
1) explicit leaveAction per key
2) general leaveAction
3) tab or return action
Can be used to arrange for escape to deal with special operations (such as closing some view),
The cancel-action block will be called with 0,1 (the key) or 2 (self + key) arguments

o  onKey: aKey leaveWith: aBlock
arrange for aKey to leave the field and evaluate aBlock.
On leave, the precedence of actions is:
1) explicit leaveAction per key
2) general leaveAction
3) tab or return action
Can be used to arrange for cursorDown to pass focus to another widget,
or to override builtin ctrl- shortcuts.
The leave-action block will be called with 0,1 (the key) or 2 (self + key) arguments

o  readOnly: aBoolean
make the text readonly or writable

o  returnKeyIsFocusNext
arrange for the return key to act as a focus-next key

o  tabAction: aBlock
define an action to be evaluated when the tabulator key is pressed.

o  tabKey: aKeySymbol
arrange for aKeySymbol to accept & leave the field
If the field is part of a group, the next field gets the
input focus

accessing-contents
o  contents
return contents as a string
- redefined since EditFields hold only one line of text.
In your application, please use #editValue;
it uses a converter (if any) and is compatible to ST-80.

o  contents: someText
set the contents from a string
- redefined to place the cursor to the end.
In your application, please use #editValue: -
it uses a converter (if any) and is compatible to ST-80.

o  convertEditValueToString: aStringOrObject
convert a aStringOrObject to a printed representation.
If there is a converter, use it to convert
the object into a printed representation.
Use asString to convert the object,
and used directly.

o  editValue
if the field edits a string, this is a name alias for #contents.
Otherwise, if there is a converter, return the edited string
converted to an appropriate object.

o  editValue: anObject
set the contents. If there is a converter, use it to convert
the object into a printed representation.
Otherwise, convert anObject to a string using #asString
(this is equivalent to sending #contents:).

o  editValue: anObject selected: isSelected
set the contents. If there is a converter, use it to convert
anObject into a printed representation.
Otherwise, use anObject asString
(i.e. this is equivalent to sending #initialText:selected:).

o  initialText: aString
set the initialText and select it.
Better use #editValue: - it uses the type converter.

o  initialText: aString selected: isSelected
set the initialText and select it if isSelected is true
Better use #editValue:selected: - it uses the type converter.

o  list: someText
low level access to the underlying contents' list.
Redefined to force text to 1 line, and notify dependents
of any changed extent-wishes (for automatic box resizing).

o  stringValue
alias for #contents - for compatibility with ST-80's InputField

accessing-look
o  bePassword
make me a password entry field (i.e. show *'s for typed characters)

o  bePassword: aBoolean
if true, make me a password entry field (i.e. show *'s for typed characters)

o  emptyFieldReplacementText
the string to show in grey if nothing has been entered (and the field is passive)

o  emptyFieldReplacementText: aString
the string to show in grey if nothing has been entered (and the field is passive)

o  font: aFont
(comment from inherited method)
set the font for all shown text.
Redraws everything.
CAVEAT: with the addition of Text objects,
this method is going to be obsoleted by a textStyle
method, which allows specific control over
normalFont/boldFont/italicFont parameters.

o  isPassword
am I a password entry field ?(i.e. showing *'s for typed characters)

o  maxChars
return the maximum number of characters that are allowed in
the field.
A limit of nil means: unlimited. This is the default.

o  maxChars: aNumberOrNil
set the maximum number of characters that are allowed in
the field. Additional input will be ignored by the field.
A limit of nil or zero means: unlimited. This is the default.
If set, a lengthLimit must be defined before any contents is placed
into the field, because the contents is not cut when the max is
changed later. I.e. it should be set early after creation of the field.

This method has been renamed from #lengthLimit: for ST-80
compatibility.

o  passwordCharacter
return the passwordCharacter;
If nonNil, that one is replacing typed input
(for secret input)

o  passwordCharacter: aCharacter
set the passwordCharacter;
If nonNil, that one is replacing typed input
(for secret input)

cursor drawing
o  cursorShown: aBoolean
make cursor visible if currently invisible - but only if this
EditField is enabled.
Return the previous cursor-shown-state

o  drawFromVisibleLine: startVisLineNr to: endVisLineNr with: fg and: bg
(comment from inherited method)
draw a visible line range in fg/bg

cursor movement
o  cursorDown
catch cursor movement

o  cursorLeft
(comment from inherited method)
move cursor to left

o  cursorLine: line col: col
catch cursor movement

o  cursorLine: line col: col makeVisible: aBoolean
catch cursor movement

o  cursorToEnd
catch cursor movement

o  validateCursorCol: colNr inLine: lineNr
check of col is a valid cursor position;
return a fixed value if not.

drag & drop
o  dropFileObject: aDropObject
drop objects
Redefined to always drop the name only

editing
o  paste: someText
redefined to force text to 1 line

event handling
o  buttonPress: button x: x y: y
enable myself on mouse click

Usage example(s):

super buttonPress:button x:x y:y.

Usage example(s):

super buttonPress:button x:x y:y

o  buttonRelease: button x: x y: y
if the selection is empty (because of validateSelection,
clear it alltogether, so that the cursor becomes visible again

o  canHandle: aKey
return true, if the receiver would like to handle aKey
(usually from another view, when the receiver is part of
a more complex dialog box).
We do return true here, since the editfield will handle
all keys.
OBSOLETE: don't use this anymore - its a leftover for the tableWidget

o  doubleClickX: x y: y
(comment from inherited method)
double-click - select word under pointer

o  handleCompletionService
none here

o  handleFocusKey: key
handle a focus key, to assign the focus to another field in my group

o  keyPress: key x: x y: y
if keyHandler is defined, pass input; otherwise check for leave
keys

o  keyboardZoom: largerBoolean
ALT+/- (was: CTRL+/-) zoom action

o  pointerLeave: state
(comment from inherited method)
mouse pointer left

o  resizeOrScroll
helper for keyPress.
Extracted for easier subclass redefinition.

o  sizeChanged: how from: oldExtentOrNil
my view has changed the size (not the contents);
scroll to origin, if all fits

o  tripleClickX: x y: y
triple-click - select all

focus handling
o  hasKeyboardFocus: aBoolean
the view got/lost the keyboard focus

o  showFocus: explicit
the view got the keyboard focus
(either explicit, via tabbing; or implicit, by pointer movement)
- change any display attributes as req'd.

o  showNoFocus: explicit
the view lost the keyboard focus
(either explicit, via tabbing; or implicit, by pointer movement)
- change any display attributes as req'd.

o  wantsFocusWithPointerEnter
return true, if I want the focus when
the mouse pointer enters

help
o  helpTextAt: aPoint
(comment from inherited method)
fallback to avoid DNU for those which do a super (which they should not)

initialization & release
o  computeTopMargin
textStartTop := 2.

o  initStyle
setup viewStyle specifics

o  initialize
(comment from inherited method)
initialize a new EditTextView;
setup some instance variables

menu actions
o  browseImplementors

o  editMenu
return a popUpMenu for the receiver

o  hideAsPassword
hide passwords (i.e. turn on password mode)

o  openFileBrowser

o  showPasswordCharacters
show the plain text (i.e. turn off password mode)

native widget support
o  nativeWindowType
return a symbol describing my native window type
(may be used internally by the device as a native window creation hint,
if the device supports native windows)

private
o  argForChangeMessage
redefined to send use converted value (if I have one)

o  doCompletion

o  getListFromModel
redefined to acquire the text via the aspectMsg - not the listMsg,
and to ignore updates resulting from my own change.

o  startAutoScrollDown: y
no vertical scrolling in editfields

o  startAutoScrollUp: y
no vertical scrolling in editfields

o  textChanged
this is sent by mySelf (somewhere in a superclass) whenever
my contents has changed.
A good place to add immediateAccept functionality and check for the
lengthLimit.

o  textChangedButNoSizeChange
this is sent by mySelf (somewhere in a superclass) whenever
my contents has changed.
A good place to add immediateAccept functionality.

o  updateBackground
make my background grey, whenever either readOnly or disable

o  visibleAt: visLineNr
return the string at lineNr for display.
If there is a password character, return a string consisting of those only.
visLineNr is a visible lineNr (i.e. not the absolute lineNr)

queries
o  computePreferredExtent
return the preferred extent of this view.
That is the width of the string plus some extra,
but not wider than half of the screen

o  hasSelectionForCopy
return true, if there is a selection which can be copied.

o  isInputField
return true, if the receiver is some kind of input view,
i.e. it should (can) be part of an enterGroup.
Return true here

o  specClass
returns my spec class (for UI editor)

Usage example(s):

redefined, since the name of my specClass is nonStandard (i.e. not EditFieldSpec)

o  tabMeansNextField
return true, if Tab character should shift focus to the next field

realization
o  realize
redefined to scroll back to beginning when realized,
and also to init the password character if the user applied
hideAsPassword the last time on a field like me.

redrawing
o  redrawPasswordIcon
a region must be redrawn

o  redrawVisibleLine: visLine
(comment from inherited method)
redraw a visible line

o  redrawVisibleLine: visLine col: colNr
(comment from inherited method)
redraw the single character in visibleline at colNr

o  redrawVisibleLine: visLine from: startCol
(comment from inherited method)
redraw a visible line from startCol to the end of line

o  redrawVisibleLine: visLine from: startCol to: endCol
(comment from inherited method)
redraw a visible line from startCol to endCol

o  redrawX: x y: y width: w height: h
a region must be redrawn

scrolling
o  makeColVisible: col inLine: lineNr
don't scroll for the cursor, if it's beyond the text and a lengthLimit
is present.

selections
o  copySelection
refuse to copy a password to the clipboard

o  selectAll
select the whole text.
redefined to send super selectFrom... since we don't want the
cursor to be moved in this case.

o  selectFrom: firstColToSelect
select the right part of the text

o  setClipboardText: aString
redefined to refuse to copy the password to the clipboard

o  setLastStringToReplace: sel
redefined to refuse to remember the password

o  validateNewSelection
make certain that only one line is ever selected;
also check that the selection is within the string


Examples:


see more examples in EnterFieldGroup>>examples. Step-by-step introduction: basic field in some view:
    |top field|

    top := StandardSystemView new.
    top extent:200@100.

    field := EditField origin:0.0@0.0 in:top.
    field width:1.0.                                'let its height as-is'.

    top open
forward input in topView to the field: (currently, the field does not know this - therefore, its been told here ... this may change)
    |top field|

    top := StandardSystemView new.
    top extent:200@100.

    field := EditField origin:0.0@0.0 in:top.
    field width:1.0.                                'let its height as-is'.

    top delegate:(KeyboardForwarder toView:field).
    field hasKeyboardFocus:true.
    top open
to make it look better: set some inset:
    |top field spacing|

    top := StandardSystemView new.
    top extent:200@100.

    spacing := View viewSpacing.
    field := EditField origin:(0.0 @ spacing) in:top.
    field width:1.0.                                        'let its height as-is'.
    field leftInset:spacing; rightInset:spacing.

    top open
give it an initial contents:
    |top field|

    top := StandardSystemView new.
    top extent:200@100.

    field := EditField origin:(0.0 @ 0.0) in:top.
    field width:1.0.

    field editValue:'hello world'.

    top open
have it preselected:
    |top field|

    top := StandardSystemView new.
    top extent:200@100.

    field := EditField origin:(0.0 @ 0.0) in:top.
    field width:1.0.
    field editValue:'hello world' selected:true.

    top open
have part of it preselected:
    |top field|

    top := StandardSystemView new.
    top extent:200@100.

    field := EditField origin:(0.0 @ 0.0) in:top.
    field width:1.0.

    field editValue:'hello world'.
    field selectFromCharacterPosition:1 to:5.

    top open
set a size limit:
    |top field|

    top := StandardSystemView new.
    top extent:200@100.

    field := EditField origin:(0.0 @ 0.0) in:top.
    field width:1.0.
    field editValue:'hello'.

    field maxChars:8.

    top open
set a size limit, initial width and stop it from scrolling notice: you may prefer a constant-pitch font (such as courier):
    |top field|

    top := StandardSystemView new.
    top extent:200@100.

    field := EditField origin:(0.0 @ 0.0) in:top.
    field innerWidth:(field font widthOf:'00000000').
    field editValue:'12345678'.

    field maxChars:8.
    field autoScroll:false.

    top open
enable / disable:
    |top panel check field ena|

    top := StandardSystemView new.
    top extent:200@100.

    panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
    panel borderWidth:0.
    panel horizontalLayout:#left.
    panel horizontalInset:View viewSpacing.

    check := CheckBox label:'enable' in:panel.
    check turnOn.
    check action:[:onOff | onOff ifTrue:[field enable] ifFalse:[field disable]].

    panel add:(View new height:30; borderWidth:0).

    field := EditField in:panel.
    field width:1.0.
    field editValue:'hello'.

    top open
enable / disable using a channel:
    |top panel check field ena|

    top := StandardSystemView new.
    top extent:200@100.

    panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
    panel borderWidth:0.
    panel horizontalLayout:#left.
    panel horizontalInset:View viewSpacing.

    ena := true asValue.

    check := CheckBox label:'enable' in:panel.
    check model:ena.

    panel add:(View new height:30; borderWidth:0).

    field := EditField in:panel.
    field enableChannel:ena.
    field width:1.0.
    field editValue:'hello'.

    top open
use a converter: - numbers (default to 0):
    |top field spacing|

    top := StandardSystemView new.
    top extent:200@100.

    spacing := View viewSpacing.

    field := EditField origin:0.0 @ spacing in:top.
    field width:1.0.
    field horizontalInset:spacing.

    field converter:(PrintConverter new initForNumber).
    field editValue:1234.
    field acceptAction:[:value | Transcript showCR:value].
    field crAction:[field accept. top destroy].
    top open.
- dates:
    |top field spacing|

    top := StandardSystemView new.
    top extent:200@100.

    spacing := View viewSpacing.

    field := EditField origin:0.0 @ spacing in:top.
    field width:1.0.
    field horizontalInset:spacing.

    field converter:(PrintConverter new initForDate).
    field editValue:Date today.
    field acceptAction:[:value | Transcript showCR:value class name , ' ' , value printString].
    field crAction:[field accept. top destroy].
    top open.
setting immediateAccept, makes the field update with every key: - immediate accept numbers, defaulting to nil:
    |top field spacing|

    top := StandardSystemView new.
    top extent:200@100.

    spacing := View viewSpacing.

    field := EditField origin:0.0 @ spacing in:top.
    field width:1.0.
    field horizontalInset:spacing.

    field converter:(PrintConverter new initForNumberOrNil).
    field immediateAccept:true.
    field editValue:1234.
    field acceptAction:[:value | Transcript showCR:value].
    field crAction:[field accept. top destroy].
    top open.
grouping multiple fields, and forward keyPres from the outer view to the active field (i.e. actually: to the group):
    |top field1 field2 field3 group|


    top := StandardSystemView new.
    top extent:200@100.

    field1 := EditField origin:(0.0 @ 0.0) in:top.
    field1 width:1.0.

    field2 := EditField origin:(0.0 @ 0.0) in:top.
    field2 width:0.5.
    field2 topInset:(field1 height); bottomInset:(field1 height negated).

    field3 := EditField origin:(0.5 @ 0.0) in:top.
    field3 width:0.5.
    field3 topInset:(field1 height); bottomInset:(field1 height negated).

    group := EnterFieldGroup new.
    group add:field1; add:field2; add:field3.

    top delegate:(KeyboardForwarder to:group).

    top open.
in addition: tell the group to close when the last field is left:
    |top field1 field2 field3 group|


    top := StandardSystemView new.
    top extent:200@100.

    field1 := EditField origin:(0.0 @ 0.0) in:top.
    field1 width:1.0.

    field2 := EditField origin:(0.0 @ 0.0) in:top.
    field2 width:0.5.
    field2 topInset:(field1 height); bottomInset:(field1 height negated).

    field3 := EditField origin:(0.5 @ 0.0) in:top.
    field3 width:0.5.
    field3 topInset:(field1 height); bottomInset:(field1 height negated).

    group := EnterFieldGroup new.
    group add:field1; add:field2; add:field3.
    group leaveAction:[top destroy].

    top delegate:(KeyboardForwarder to:group).

    top open.
use a model: (see changing model value in inspector when return is pressed in the field)
    |top field model|

    model := 'hello world' asValue.

    top := StandardSystemView new.
    top extent:200@100.

    field := EditField origin:(0.0 @ 0.0) in:top.
    field width:1.0.
    field model:model.
    field acceptOnReturn:true.

    top open.
    model inspect.
like above, but also accept the value, when the focus is changed (i.e. out of the input field): (see changing model value in inspector)
    |top field model|

    model := 'hello world' asValue.

    top := StandardSystemView new.
    top extent:200@100.

    field := EditField origin:(0.0 @ 0.0) in:top.
    field width:1.0.
    field model:model.
    field acceptOnLostFocus:true.

    top open.
    InspectorView openOn:model monitor:'value'.
two views on the same model (each accepts on return):
    |top1 top2 field1 field2 model|

    model := 'hello world' asValue.

    top1 := StandardSystemView new.
    top1 extent:200@100.
    field1 := EditField origin:(0.0 @ 0.0) in:top1.
    field1 width:1.0.
    field1 model:model.
    field1 acceptOnReturn:true.
    top1 open.

    top2 := StandardSystemView new.
    top2 extent:200@100.
    field2 := EditField origin:(0.0 @ 0.0) in:top2.
    field2 width:1.0.
    field2 model:model.
    field2 acceptOnReturn:true.
    top2 open.
two views on the same model (no accept on return):
    |top1 top2 field1 field2 model|

    model := 'hello world' asValue.

    top1 := StandardSystemView new.
    top1 extent:200@100.
    field1 := EditField origin:(0.0 @ 0.0) in:top1.
    field1 width:1.0.
    field1 model:model; acceptOnReturn:false.
    top1 open.

    top2 := StandardSystemView new.
    top2 extent:200@100.
    field2 := EditField origin:(0.0 @ 0.0) in:top2.
    field2 width:1.0.
    field2 model:model; acceptOnReturn:false.
    top2 open.
with immediate accept (every key updates the model):
    |top1 top2 field1 field2 model|

    model := 'hello world' asValue.

    top1 := StandardSystemView new.
    top1 extent:200@100.
    field1 := EditField origin:(0.0 @ 0.0) in:top1.
    field1 width:1.0.
    field1 model:model; immediateAccept:true.
    top1 open.

    top2 := StandardSystemView new.
    top2 extent:200@100.
    field2 := EditField origin:(0.0 @ 0.0) in:top2.
    field2 width:1.0.
    field2 model:model; immediateAccept:true.
    top2 open.
just an example; a checkBox and an editField on the same model:
    |top1 top2 field1 box model|

    model := false asValue.

    top1 := StandardSystemView new.
    top1 extent:200@100.
    field1 := EditField origin:(0.0 @ 0.0) in:top1.
    field1 width:1.0.
    field1 converter:(PrintConverter new initForYesNo).
    field1 model:model.
    top1 open.

    top2 := StandardSystemView new.
    top2 extent:200@100.
    box := CheckBox on:model.
    box label:'on/off'.
    top2 add:box.
    top2 open.

    model inspect.
multiple editFields on multiple models (value holders): (the fields are connected by a group to allow tabbing)
    |top panel group field1 field2 field3 box
     v1 v2 v3 spacing|

    v1 := true asValue.
    v2 := 'some string' asValue.
    v3 := 1.2 asValue.

    top := StandardSystemView new.
    top extent:200@100.

    panel := VerticalPanelView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.

    spacing := View viewSpacing.

    field1 := EditField new.
    field1 width:1.0.
    field1 horizontalInset:spacing.
    field1 converter:(PrintConverter new initForYesNo).
    field1 model:v1.
    panel add:field1.

    field2 := EditField new.
    field2 width:1.0.
    field2 horizontalInset:spacing.
    field2 model:v2.
    panel add:field2.

    field3 := EditField new.
    field3 width:1.0.
    field3 horizontalInset:spacing.
    field3 converter:(PrintConverter new initForNumber).
    field3 model:v3.
    panel add:field3.

    group := EnterFieldGroup new.
    group add:field1; add:field2; add:field3.

    top openModal.

    Transcript showCR:v1 value.
    Transcript showCR:v2 value.
    Transcript showCR:v3 value.
connecting fields: update field2 whenever field1 is changed. (normally, the processing below (xChanged) is done in your application class, or in a complex model. For the demonstration below, we use a Plug to simulate the protocol.)
    |application top field1 field2 value1 value2|

    application := Plug new.
    application respondTo:#value1Changed
                     with:[value2 value:(value1 value isNil ifTrue:[nil]
                                                            ifFalse:[value1 value squared])].

    value1 := 1 asValue.
    value2 := 1 asValue.

    top := Dialog new.
    top extent:200@200.

    (top addTextLabel:'some number:') layout:#left.
    top addVerticalSpace.

    (top addInputFieldOn:value1 tabable:false)
        converter:(PrintConverter new initForNumberOrNil);
        immediateAccept:true.
    top addVerticalSpace.

    (top addTextLabel:'squared:') layout:#left.
    top addVerticalSpace.
    (top addInputFieldOn:value2 tabable:false)
        converter:(PrintConverter new initForNumberOrNil).

    value1 onChangeSend:#value1Changed to:application.

    top openModeless.
two-way connect: each field updates the other (notice, that we have to turn off onChange: notification, to avoid an endless notification cycle)
    |application top field1 field2 value1 value2|

    application := Plug new.
    application respondTo:#value1Changed
                     with:[value2 retractInterestsFor:application.
                           value2 value:(value1 value isNil ifTrue:[nil]
                                                            ifFalse:[value1 value squared]).
                           value2 onChangeSend:#value2Changed to:application.
                          ].
    application respondTo:#value2Changed
                     with:[value1 retractInterestsFor:application.
                           value1 value:(value2 value isNil ifTrue:[nil]
                                                            ifFalse:[value2 value sqrt]).
                           value1 onChangeSend:#value1Changed to:application.
                          ].

    value1 := 1 asValue.
    value2 := 1 asValue.

    top := Dialog new.
    top extent:200@200.

    (top addTextLabel:'some number:') layout:#left.
    top addVerticalSpace.

    (top addInputFieldOn:value1 tabable:false)
        converter:(PrintConverter new initForNumberOrNil);
        immediateAccept:true.
    top addVerticalSpace.

    (top addTextLabel:'squared:') layout:#left.
    top addVerticalSpace.
    (top addInputFieldOn:value2 tabable:false)
        converter:(PrintConverter new initForNumberOrNil);
        immediateAccept:true.

    value1 onChangeSend:#value1Changed to:application.
    value2 onChangeSend:#value2Changed to:application.

    top openModeless.


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Thu, 21 Nov 2024 11:14:58 GMT