11 " |
11 " |
12 |
12 |
13 'From Smalltalk/X, Version:2.10.5 on 4-may-1995 at 8:46:55 am'! |
13 'From Smalltalk/X, Version:2.10.5 on 4-may-1995 at 8:46:55 am'! |
14 |
14 |
15 EditTextView subclass:#EditField |
15 EditTextView subclass:#EditField |
16 instanceVariableNames:'leaveAction enabled enableAction alwaysAccept crAction tabAction |
16 instanceVariableNames:'leaveAction enabled enableAction crAction tabAction |
17 converter acceptAction leaveKeys' |
17 converter acceptAction leaveKeys alwaysAccept acceptOnLeave acceptOnReturn' |
18 classVariableNames:'DefaultForegroundColor DefaultBackgroundColor |
18 classVariableNames:'DefaultForegroundColor DefaultBackgroundColor |
19 DefaultSelectionForegroundColor DefaultSelectionBackgroundColor |
19 DefaultSelectionForegroundColor DefaultSelectionBackgroundColor |
20 DefaultFont' |
20 DefaultFont' |
21 poolDictionaries:'' |
21 poolDictionaries:'' |
22 category:'Views-Text' |
22 category:'Views-Text' |
69 field has to be enabled next) |
69 field has to be enabled next) |
70 |
70 |
71 enabled <Boolean> if false, input is ignored. |
71 enabled <Boolean> if false, input is ignored. |
72 |
72 |
73 enableAction <Block | nil> |
73 enableAction <Block | nil> |
|
74 |
|
75 crAction <Block | nil> if non-nil, keyboard input of a cr are not |
|
76 handled specially, instead this block is evaluated |
|
77 (however, this block can perform additional checks and send |
|
78 a #accept then) |
|
79 |
|
80 tabAction <Block | nil> if non-nil, keyboard input of a tab character |
|
81 is not entered into the text, instead this block |
|
82 is evaluated. |
|
83 |
|
84 converter <PrintConverter | nil> if non-nil, this is supposed to convert between |
|
85 the object and its printed representation. |
|
86 Defaults to nil i.e. assume that strings are edited. |
|
87 |
|
88 acceptAction <Block | nil> if non-nil, this is performed in addition to |
|
89 the leaveAction. |
|
90 |
|
91 leaveKeys <Collection> keys which are interpreted as 'leving the field' |
|
92 |
74 alwaysAccept <Boolean> if true, every change of the text is immediately |
93 alwaysAccept <Boolean> if true, every change of the text is immediately |
75 forwardd to the model/acceptBlock. |
94 forwardd to the model/acceptBlock. |
76 Default is false i.e. only forward changes |
95 Default is false i.e. only forward changes |
77 on accept. |
96 on accept. |
78 |
97 |
79 crAction <Block | nil> if non-nil, keyboard input of a cr are not |
98 acceptOnLeave <Boolean> if true, leaving the field (via cursor keys) |
80 handled specially, instead this block is evaluated |
99 automatically accepts the value into the model. |
81 (however, this block can perform additional checks and send |
100 Default is false. |
82 a #accept then) |
101 |
83 |
102 acceptOnReturn <Boolean> if true, leaving the field via return |
84 tabAction <Block | nil> if non-nil, keyboard input of a tab character |
103 automatically accepts the value into the model. |
85 is not entered into the text, instead this block |
104 Default is true. |
86 is evaluated. |
|
87 |
|
88 converter <PrintConverter | nil> if non-nil, this is supposed to convert between |
|
89 the object and its printed representation. |
|
90 Defaults to nil i.e. assume that strings are edited. |
|
91 |
|
92 acceptAction <Block | nil> if non-nil, this is performed in addition to |
|
93 the leaveAction. |
|
94 |
|
95 leaveKeys <Collection> keys which are interpreted as 'leving the field' |
|
96 " |
105 " |
97 ! |
106 ! |
98 |
107 |
99 examples |
108 examples |
100 " |
109 " |
101 basic field: |
110 see more examples in EnterFieldGroup>>examples. |
|
111 |
|
112 |
|
113 basic field in a view: |
102 |
114 |
103 |top field| |
115 |top field| |
104 |
116 |
105 top := StandardSystemView new. |
117 top := StandardSystemView new. |
106 top extent:200@100. |
118 top extent:200@100. |
107 |
119 |
108 field := EditField origin:0.0@0.0 in:top. |
120 field := EditField origin:0.0@0.0 in:top. |
109 field width:1.0. 'let its height as-is'. |
121 field width:1.0. 'let its height as-is'. |
110 |
122 |
111 top open |
123 top open |
|
124 |
|
125 |
|
126 forward input in topView to field: |
|
127 |
|
128 |top field| |
|
129 |
|
130 top := StandardSystemView new. |
|
131 top extent:200@100. |
|
132 |
|
133 field := EditField origin:0.0@0.0 in:top. |
|
134 field width:1.0. 'let its height as-is'. |
|
135 |
|
136 top delegate:(KeyboardForwarder toView:field). |
|
137 top open |
|
138 |
112 |
139 |
113 just to make it look better: set some inset: |
140 just to make it look better: set some inset: |
114 |
141 |
115 |top field| |
142 |top field| |
116 |
143 |
470 ] |
507 ] |
471 ! |
508 ! |
472 |
509 |
473 contents:someText |
510 contents:someText |
474 "set the contents from a string |
511 "set the contents from a string |
475 - redefined to place the cursor to the end" |
512 - redefined to place the cursor to the end. |
|
513 In your application, please use #editValue:; |
|
514 it uses a converter (if any) and is compatible to ST-80." |
476 |
515 |
477 super contents:someText. |
516 super contents:someText. |
478 self cursorCol:(someText size + 1). |
517 self cursorCol:(someText size + 1). |
479 ! |
518 ! |
480 |
519 |
481 contents |
520 contents |
482 "return contents as a string |
521 "return contents as a string |
483 - redefined since EditFields hold only one line of text" |
522 - redefined since EditFields hold only one line of text. |
|
523 In your application, please use #editValue; |
|
524 it uses a converter (if any) and is compatible to ST-80." |
484 |
525 |
485 list isNil ifTrue:[^ '']. |
526 list isNil ifTrue:[^ '']. |
486 (list size == 0) ifTrue:[^ '']. |
527 (list size == 0) ifTrue:[^ '']. |
487 ^ list at:1 |
528 ^ list at:1 |
488 ! |
529 ! |
503 "define an action to be evaluated when field is left by return key" |
544 "define an action to be evaluated when field is left by return key" |
504 |
545 |
505 leaveAction := aBlock |
546 leaveAction := aBlock |
506 ! |
547 ! |
507 |
548 |
|
549 leaveKeys:aCollectionOfKeySymbols |
|
550 "define the set of keys which are interpreted as leaveKeys. |
|
551 I.e. those that make the field inactive and accept (if acceptOnLeave is true). |
|
552 The default is a set of #CursorUp, #CursorDown, #Next, #Prior and #Return." |
|
553 |
|
554 leaveKeys := aCollectionOfKeySymbols |
|
555 ! |
|
556 |
508 crAction:aBlock |
557 crAction:aBlock |
509 "define an action to be evaluated when the return key is pressed." |
558 "define an action to be evaluated when the return key is pressed." |
510 |
559 |
511 crAction := aBlock |
560 crAction := aBlock |
512 ! |
561 ! |
522 |
571 |
523 tabAction := aBlock |
572 tabAction := aBlock |
524 ! |
573 ! |
525 |
574 |
526 alwaysAccept:aBoolean |
575 alwaysAccept:aBoolean |
527 "set/clear the alwaysAccept flag" |
576 "set/clear the alwaysAccept flag. The default is false." |
528 |
577 |
529 alwaysAccept := aBoolean |
578 alwaysAccept := aBoolean |
|
579 ! |
|
580 |
|
581 acceptOnReturn:aBoolean |
|
582 "set/clear the acceptOnReturn flag. The default is true." |
|
583 |
|
584 acceptOnReturn := aBoolean |
|
585 ! |
|
586 |
|
587 acceptOnLeave:aBoolean |
|
588 "set/clear the acceptOnLeave flag. The default is false." |
|
589 |
|
590 acceptOnLeave := aBoolean |
530 ! |
591 ! |
531 |
592 |
532 converter |
593 converter |
533 "return the converter (if any)." |
594 "return the converter (if any)." |
534 |
595 |