EditField.st
changeset 594 b9c5a5e5f905
parent 586 032b3245e53a
child 601 2ec9efffff79
--- a/EditField.st	Sat Apr 27 20:21:37 1996 +0200
+++ b/EditField.st	Sat Apr 27 20:25:18 1996 +0200
@@ -172,6 +172,9 @@
 
     [see also:]
         DialogBox
+        EnterFieldGroup
+        EnterBox EnterBox2
+        FilenameEditField EditTextView
 "
 !
 
@@ -184,7 +187,7 @@
 
 
     basic field in some view:
-
+                                                                        [exBegin]
         |top field|
 
         top := StandardSystemView new.
@@ -194,12 +197,13 @@
         field width:1.0.                                'let its height as-is'.
 
         top open
+                                                                        [exEnd]
 
 
     forward input in topView to the field:
     (currently, the field does not know this - therefore,
      its been told here ... this may change)
-
+                                                                        [exBegin]
         |top field|
 
         top := StandardSystemView new.
@@ -211,10 +215,11 @@
         top delegate:(KeyboardForwarder toView:field).
         field hasKeyboardFocus:true.
         top open
+                                                                        [exEnd]
 
 
     to make it look better: set some inset:
-
+                                                                        [exBegin]
         |top field spacing|
 
         top := StandardSystemView new.
@@ -226,25 +231,27 @@
         field leftInset:spacing; rightInset:spacing.
 
         top open
+                                                                        [exEnd]
 
 
     give it an initial contents:
-
+                                                                        [exBegin]
         |top field|
 
         top := StandardSystemView new.
         top extent:200@100.
 
-        field := EditField origin:(0.0 @ 0@0) in:top.
+        field := EditField origin:(0.0 @ 0.0) in:top.
         field width:1.0.       
 
         field editValue:'hello world'.
 
         top open
+                                                                        [exEnd]
 
 
     have it preselected:
-
+                                                                        [exBegin]
         |top field|
 
         top := StandardSystemView new.
@@ -255,10 +262,11 @@
         field editValue:'hello world' selected:true.
 
         top open
+                                                                         [exEnd]
 
 
     have part of it preselected:
-
+                                                                        [exBegin]
         |top field|
 
         top := StandardSystemView new.
@@ -271,10 +279,11 @@
         field selectFromCharacterPosition:1 to:5.
 
         top open
+                                                                        [exEnd]
 
 
     set a size limit:
-
+                                                                        [exBegin]
         |top field|
 
         top := StandardSystemView new.
@@ -287,11 +296,12 @@
         field maxChars:8.
 
         top open
+                                                                        [exEnd]
 
 
     set a size limit, initial width and stop it from scrolling
     notice: you may prefer a constant-pitch font (such as courier):
-
+                                                                        [exBegin]
         |top field|
 
         top := StandardSystemView new.
@@ -305,10 +315,11 @@
         field autoScroll:false.
 
         top open
+                                                                        [exEnd]
 
 
     enable / disable:
-
+                                                                        [exBegin]
         |top panel check field ena|
 
         top := StandardSystemView new.
@@ -330,10 +341,11 @@
         field editValue:'hello'.
         
         top open
+                                                                        [exEnd]
 
 
     enable / disable using a channel:
-
+                                                                        [exBegin]
         |top panel check field ena|
 
         top := StandardSystemView new.
@@ -357,59 +369,65 @@
         field editValue:'hello'.
 
         top open
+                                                                        [exEnd]
 
 
     use a converter:
       - numbers (default to 0):
-
-        |top field|
+                                                                        [exBegin]
+        |top field spacing|
 
         top := StandardSystemView new.
         top extent:200@100.
 
-        field := EditField origin:0.0@ViewSpacing in:top.
+        spacing := View viewSpacing.
+
+        field := EditField origin:0.0 @ spacing in:top.
         field width:1.0.
-        field leftInset:ViewSpacing;
-              rightInset:ViewSpacing.
+        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.
+                                                                        [exEnd]
 
       - dates:
-
-        |top field|
+                                                                        [exBegin]
+        |top field spacing|
 
         top := StandardSystemView new.
         top extent:200@100.
 
-        field := EditField origin:0.0@ViewSpacing in:top.
+        spacing := View viewSpacing.
+
+        field := EditField origin:0.0 @ spacing in:top.
         field width:1.0.
-        field leftInset:ViewSpacing;
-              rightInset:ViewSpacing.
+        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.
+                                                                        [exEnd]
 
 
     setting immediateAccept, makes the field update with every key:
 
       - immediate accept numbers, defaulting to nil:
-
-        |top field|
+                                                                        [exBegin]
+        |top field spacing|
 
         top := StandardSystemView new.
         top extent:200@100.
 
-        field := EditField origin:0.0@ViewSpacing in:top.
+        spacing := View viewSpacing.
+
+        field := EditField origin:0.0 @ spacing in:top.
         field width:1.0.
-        field leftInset:ViewSpacing;
-              rightInset:ViewSpacing.
+        field horizontalInset:spacing.
 
         field converter:(PrintConverter new initForNumberOrNil).
         field immediateAccept:true.
@@ -417,12 +435,13 @@
         field acceptAction:[:value | Transcript showCr:value].
         field crAction:[field accept. top destroy].
         top open.
+                                                                        [exEnd]
 
 
 
     grouping multiple fields, and forward keyPres from the outer view to the active field
     (i.e. actually: to the group):
-
+                                                                        [exBegin]
         |top field1 field2 field3 group|
 
 
@@ -446,10 +465,11 @@
         top delegate:(KeyboardForwarder to:group).
 
         top open.
+                                                                        [exEnd]
 
         
     in addition: tell the group to close when the last field is left:
-
+                                                                        [exBegin]
         |top field1 field2 field3 group|
 
 
@@ -474,11 +494,12 @@
         top delegate:(KeyboardForwarder to:group).
 
         top open.
+                                                                        [exEnd]
 
 
     use a model:
     (see changing model value in inspector when return is pressed in the field)
-
+                                                                        [exBegin]
         |top field model|
 
         model := 'hello world' asValue.
@@ -493,10 +514,11 @@
 
         top open.
         model inspect.
+                                                                        [exEnd]
 
 
     two views on the same model (each accepts on return):
-
+                                                                        [exBegin]
         |top1 top2 field1 field2 model|
 
         model := 'hello world' asValue.
@@ -516,9 +538,10 @@
         field2 model:model.
         field2 acceptOnReturn:true.
         top2 open.
+                                                                        [exEnd]
 
     two views on the same model (no accept on return):
-
+                                                                        [exBegin]
         |top1 top2 field1 field2 model|
 
         model := 'hello world' asValue.
@@ -536,9 +559,10 @@
         field2 width:1.0.
         field2 model:model; acceptOnReturn:false.
         top2 open.
+                                                                        [exEnd]
 
     with immediate accept (every key updates the model):
-
+                                                                        [exBegin]
         |top1 top2 field1 field2 model|
 
         model := 'hello world' asValue.
@@ -556,9 +580,10 @@
         field2 width:1.0.
         field2 model:model; immediateAccept:true.
         top2 open.
+                                                                        [exEnd]
 
     just an example; a checkBox and an editField on the same model:
-
+                                                                        [exBegin]
         |top1 top2 field1 box model|
 
         model := false asValue.
@@ -579,12 +604,14 @@
         top2 open.
 
         model inspect.
+                                                                        [exEnd]
 
 
     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|
+                                                                        [exBegin]
+        |top panel group field1 field2 field3 box 
+         v1 v2 v3 spacing|
 
         v1 := true asValue.
         v2 := 'some string' asValue.
@@ -595,22 +622,24 @@
 
         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:ViewSpacing.
+        field1 horizontalInset:spacing.
         field1 converter:(PrintConverter new initForYesNo).
         field1 model:v1.
         panel add:field1.
 
         field2 := EditField new.
         field2 width:1.0.
-        field2 horizontalInset:ViewSpacing.
+        field2 horizontalInset:spacing.
         field2 model:v2.
         panel add:field2.
 
         field3 := EditField new.
         field3 width:1.0.
-        field3 horizontalInset:ViewSpacing.
+        field3 horizontalInset:spacing.
         field3 converter:(PrintConverter new initForNumber).
         field3 model:v3.
         panel add:field3.
@@ -623,6 +652,7 @@
         Transcript showCr:v1 value.
         Transcript showCr:v2 value.
         Transcript showCr:v3 value.
+                                                                        [exEnd]
 
 
     connecting fields:
@@ -630,7 +660,7 @@
     (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.)
-
+                                                                        [exBegin]
         |application top field1 field2 value1 value2|
 
         application := Plug new.
@@ -660,12 +690,13 @@
         value1 onChangeSend:#value1Changed to:application.
 
         top openModeless.
+                                                                        [exEnd]
 
 
     two-way connect:
     each field updates the other (notice, that we have to turn off
     onChange: notification, to avoid an endless notification cycle)
-
+                                                                        [exBegin]
         |application top field1 field2 value1 value2|
 
         application := Plug new.
@@ -706,6 +737,7 @@
         value2 onChangeSend:#value2Changed to:application.
 
         top openModeless.
+                                                                        [exEnd]
 "
 ! !
 
@@ -888,10 +920,36 @@
     leaveKeys := aCollectionOfKeySymbols
 !
 
+makeTabable
+    "arrange for Tab to accept & leave the field
+     If the field is part of a group, the next field gets the
+     input focus"
+
+    leaveKeys isNil ifTrue:[
+        leaveKeys := self class defaultLeaveKeys
+    ].
+    leaveKeys := leaveKeys copyWith:#Tab
+
+    "Created: 27.4.1996 / 17:09:48 / cg"
+!
+
 tabAction:aBlock
     "define an action to be evaluated when the tabulator key is pressed."
 
     tabAction := aBlock
+!
+
+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"
+
+    leaveKeys isNil ifTrue:[
+        leaveKeys := self class defaultLeaveKeys
+    ].
+    leaveKeys := leaveKeys copyWith:#Tab
+
+    "Created: 27.4.1996 / 17:08:54 / cg"
 ! !
 
 !EditField methodsFor:'accessing-channels'!
@@ -1270,7 +1328,9 @@
                 self accept.
             ]
         ].
-        ^ super keyPress:key x:x y:y
+        leave ifFalse:[
+            ^ super keyPress:key x:x y:y
+        ]
     ].
 
     (key == #Return) ifTrue:[
@@ -1323,7 +1383,7 @@
 
     self resizeOrScroll.
 
-    "Modified: 7.3.1996 / 13:16:20 / cg"
+    "Modified: 27.4.1996 / 17:01:43 / cg"
 !
 
 resizeOrScroll
@@ -1461,8 +1521,12 @@
     immediateAccept := false.
     acceptOnLeave := acceptOnReturn := acceptOnTab := true.
     cursorShown := true.
-    leaveKeys := self class defaultLeaveKeys.
+    leaveKeys isNil ifTrue:[
+        leaveKeys := self class defaultLeaveKeys.
+    ].
     cursorMovementWhenUpdating := #endOfLine
+
+    "Modified: 27.4.1996 / 16:59:39 / cg"
 ! !
 
 !EditField methodsFor:'private'!
@@ -1636,5 +1700,5 @@
 !EditField class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/EditField.st,v 1.54 1996-04-25 17:33:04 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/EditField.st,v 1.55 1996-04-27 18:24:00 cg Exp $'
 ! !