|
Class: EditField
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
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.
copyrightCOPYRIGHT (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.
defaults
-
defaultBorderColor
-
-
defaultBorderWidth
-
-
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)
-
defaultLevel
-
-
defaultNumberOfLines
-
the number of lines in the field
-
updateStyleCache
-
extract values from the styleSheet and cache them in class variables
Usage example(s):
image specs
-
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
|
-
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
|
accepting
-
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
-
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.
-
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.
-
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:)
-
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:)
-
acceptOnLostFocus
-
-
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).
-
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).
-
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).
-
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).
-
autoScroll: aBoolean
-
turn on/off automatic scrolling upon keyboard entry
to make the cursor visible.
-
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
-
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)
-
cancelKeys: aCollectionOfKeySymbols
-
define the set of keys which are interpreted as cancelKeys.
I.e. those that make the field inactive without accept.
-
clickAction: aBlock
-
define an action to be evaluated when being clicked upon
-
converter
-
return the converter (if any).
-
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.
|
-
crAction: aBlock
-
define an action to be evaluated when the return key is pressed.
-
doubleClickAction: aBlock
-
define an action to be evaluated when being double clicked upon
-
enabled
-
return true, if the field is enabled (i.e. accepts keyboard input)
-
enabled: aBoolean
-
enable/disable the field; show/hide the cursor and allow/disallow input
-
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
|
-
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).
-
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).
-
entryCompletionCharacter
-
return the value of the instance variable 'entryCompletionCharacter' (automatically generated)
-
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).
-
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:)
-
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).
-
isAcceptOnReturn
-
return the acceptOnReturn flag. The default is false.
If true, leaving the box via return accepts my
string into the valueHolder (if any).
-
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).
-
isImmediateAccept
-
return the immediateAccept flag. The default is false.
If true, every pressed key immediately accepts my
string into the valueHolder (if any).
-
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
-
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
-
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)
-
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.
-
makeTabable
-
arrange for Tab to accept & leave the field
If the field is part of a group, the next field gets the
input focus
-
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
-
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
-
readOnly: aBoolean
-
make the text readonly or writable
-
returnKeyIsFocusNext
-
arrange for the return key to act as a focus-next key
-
tabAction: aBlock
-
define an action to be evaluated when the tabulator key is pressed.
-
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
-
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.
-
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.
-
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.
-
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.
-
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:).
-
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:).
-
initialText: aString
-
set the initialText and select it.
Better use #editValue: - it uses the type converter.
-
initialText: aString selected: isSelected
-
set the initialText and select it if isSelected is true
Better use #editValue:selected: - it uses the type converter.
-
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).
-
stringValue
-
alias for #contents - for compatibility with ST-80's InputField
accessing-look
-
bePassword
-
make me a password entry field (i.e. show *'s for typed characters)
-
bePassword: aBoolean
-
if true, make me a password entry field (i.e. show *'s for typed characters)
-
emptyFieldReplacementText
-
the string to show in grey if nothing has been entered (and the field is passive)
-
emptyFieldReplacementText: aString
-
the string to show in grey if nothing has been entered (and the field is passive)
-
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.
-
isPassword
-
am I a password entry field ?(i.e. showing *'s for typed characters)
-
maxChars
-
return the maximum number of characters that are allowed in
the field.
A limit of nil means: unlimited. This is the default.
-
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.
-
passwordCharacter
-
return the passwordCharacter;
If nonNil, that one is replacing typed input
(for secret input)
-
passwordCharacter: aCharacter
-
set the passwordCharacter;
If nonNil, that one is replacing typed input
(for secret input)
cursor drawing
-
cursorShown: aBoolean
-
make cursor visible if currently invisible - but only if this
EditField is enabled.
Return the previous cursor-shown-state
-
drawFromVisibleLine: startVisLineNr to: endVisLineNr with: fg and: bg
-
(comment from inherited method)
draw a visible line range in fg/bg
cursor movement
-
cursorDown
-
catch cursor movement
-
cursorLeft
-
(comment from inherited method)
move cursor to left
-
cursorLine: line col: col
-
catch cursor movement
-
cursorLine: line col: col makeVisible: aBoolean
-
catch cursor movement
-
cursorToEnd
-
catch cursor movement
-
validateCursorCol: colNr inLine: lineNr
-
check of col is a valid cursor position;
return a fixed value if not.
drag & drop
-
dropFileObject: aDropObject
-
drop objects
Redefined to always drop the name only
editing
-
paste: someText
-
redefined to force text to 1 line
event handling
-
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
|
-
buttonRelease: button x: x y: y
-
if the selection is empty (because of validateSelection,
clear it alltogether, so that the cursor becomes visible again
-
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
-
doubleClickX: x y: y
-
(comment from inherited method)
double-click - select word under pointer
-
handleCompletionService
-
none here
-
handleFocusKey: key
-
handle a focus key, to assign the focus to another field in my group
-
keyPress: key x: x y: y
-
if keyHandler is defined, pass input; otherwise check for leave
keys
-
keyboardZoom: largerBoolean
-
ALT+/- (was: CTRL+/-) zoom action
-
pointerLeave: state
-
(comment from inherited method)
mouse pointer left
-
resizeOrScroll
-
helper for keyPress.
Extracted for easier subclass redefinition.
-
sizeChanged: how from: oldExtentOrNil
-
my view has changed the size (not the contents);
scroll to origin, if all fits
-
tripleClickX: x y: y
-
triple-click - select all
focus handling
-
hasKeyboardFocus: aBoolean
-
the view got/lost the keyboard focus
-
showFocus: explicit
-
the view got the keyboard focus
(either explicit, via tabbing; or implicit, by pointer movement)
- change any display attributes as req'd.
-
showNoFocus: explicit
-
the view lost the keyboard focus
(either explicit, via tabbing; or implicit, by pointer movement)
- change any display attributes as req'd.
-
wantsFocusWithPointerEnter
-
return true, if I want the focus when
the mouse pointer enters
help
-
helpTextAt: aPoint
-
(comment from inherited method)
fallback to avoid DNU for those which do a super (which they should not)
initialization & release
-
computeTopMargin
-
textStartTop := 2.
-
initStyle
-
setup viewStyle specifics
-
initialize
-
(comment from inherited method)
initialize a new EditTextView;
setup some instance variables
menu actions
-
browseImplementors
-
-
editMenu
-
return a popUpMenu for the receiver
-
hideAsPassword
-
hide passwords (i.e. turn on password mode)
-
openFileBrowser
-
-
showPasswordCharacters
-
show the plain text (i.e. turn off password mode)
native widget support
-
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
-
argForChangeMessage
-
redefined to send use converted value (if I have one)
-
doCompletion
-
-
getListFromModel
-
redefined to acquire the text via the aspectMsg - not the listMsg,
and to ignore updates resulting from my own change.
-
startAutoScrollDown: y
-
no vertical scrolling in editfields
-
startAutoScrollUp: y
-
no vertical scrolling in editfields
-
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.
-
textChangedButNoSizeChange
-
this is sent by mySelf (somewhere in a superclass) whenever
my contents has changed.
A good place to add immediateAccept functionality.
-
updateBackground
-
make my background grey, whenever either readOnly or disable
-
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
-
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
-
hasSelectionForCopy
-
return true, if there is a selection which can be copied.
-
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
-
specClass
-
returns my spec class (for UI editor)
Usage example(s):
redefined, since the name of my specClass is nonStandard (i.e. not EditFieldSpec)
|
-
tabMeansNextField
-
return true, if Tab character should shift focus to the next field
realization
-
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
-
redrawPasswordIcon
-
a region must be redrawn
-
redrawVisibleLine: visLine
-
(comment from inherited method)
redraw a visible line
-
redrawVisibleLine: visLine col: colNr
-
(comment from inherited method)
redraw the single character in visibleline at colNr
-
redrawVisibleLine: visLine from: startCol
-
(comment from inherited method)
redraw a visible line from startCol to the end of line
-
redrawVisibleLine: visLine from: startCol to: endCol
-
(comment from inherited method)
redraw a visible line from startCol to endCol
-
redrawX: x y: y width: w height: h
-
a region must be redrawn
scrolling
-
makeColVisible: col inLine: lineNr
-
don't scroll for the cursor, if it's beyond the text and a lengthLimit
is present.
selections
-
copySelection
-
refuse to copy a password to the clipboard
-
selectAll
-
select the whole text.
redefined to send super selectFrom... since we don't want the
cursor to be moved in this case.
-
selectFrom: firstColToSelect
-
select the right part of the text
-
setClipboardText: aString
-
redefined to refuse to copy the password to the clipboard
-
setLastStringToReplace: sel
-
redefined to refuse to remember the password
-
validateNewSelection
-
make certain that only one line is ever selected;
also check that the selection is within the string
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.
|
|