author | Claus Gittinger <cg@exept.de> |
Wed, 21 Feb 1996 01:02:15 +0100 | |
changeset 371 | ed0d15f84085 |
parent 319 | d78f5fbdee27 |
child 402 | ed4a635f43c6 |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1990 by Claus Gittinger |
59 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
EnterBox subclass:#ListSelectionBox |
|
371 | 14 |
instanceVariableNames:'selectionList' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Views-DialogBoxes' |
|
0 | 18 |
! |
19 |
||
38 | 20 |
!ListSelectionBox class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1990 by Claus Gittinger |
|
59 | 25 |
All Rights Reserved |
38 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
0 | 35 |
|
38 | 36 |
documentation |
37 |
" |
|
38 |
this class implements boxes for selection from a list. It offers |
|
39 |
both an ok- and abort-buttons. The ok-button, if pressed will |
|
40 |
evaluate the okAction (see EnterBox>>action). |
|
77 | 41 |
see examples for typical uses. |
42 |
||
43 |
Notice, for file selections there is a specialized FileSelectionBox, |
|
44 |
which supports matchPatterns, changing directory etc. |
|
45 |
" |
|
46 |
! |
|
47 |
||
48 |
examples |
|
49 |
" |
|
50 |
simple: |
|
38 | 51 |
|
59 | 52 |
|box| |
38 | 53 |
|
59 | 54 |
box := ListSelectionBox new. |
55 |
box title:'select something:'. |
|
56 |
box list:#('foo' 'bar' 'baz'). |
|
57 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel]. |
|
58 |
box showAtPointer |
|
77 | 59 |
|
155 | 60 |
|
77 | 61 |
with a default: |
62 |
||
63 |
|box| |
|
64 |
||
65 |
box := ListSelectionBox new. |
|
66 |
box title:'select something:'. |
|
67 |
box list:#('foo' 'bar' 'baz'). |
|
68 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel]. |
|
69 |
box initialText:'foo'. |
|
70 |
box showAtPointer |
|
155 | 71 |
|
72 |
||
73 |
opening the box modeless (a stand-by box): |
|
74 |
(in this case, the default ok- and abortActions do not hide the box; |
|
75 |
therefore, we have to set those explicitely) |
|
76 |
||
77 |
|box| |
|
78 |
||
79 |
box := ListSelectionBox new. |
|
80 |
box title:'select something:'. |
|
81 |
box list:#('foo' 'bar' 'baz'). |
|
82 |
box abortText:'close'. |
|
83 |
box okText:'apply'. |
|
84 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel]. |
|
85 |
box abortAction:[:dummy | box hide]. |
|
86 |
box openModeless |
|
38 | 87 |
" |
197 | 88 |
! ! |
89 |
||
90 |
!ListSelectionBox class methodsFor:'instance creation'! |
|
91 |
||
92 |
title:titleString okText:okText abortText:abortText list:aList action:aBlock |
|
93 |
"create and return a new listSelectionBox with list already defined" |
|
94 |
||
95 |
|newBox| |
|
96 |
||
97 |
newBox := super title:titleString okText:okText abortText:abortText |
|
98 |
action:aBlock. |
|
99 |
^ newBox list:aList |
|
38 | 100 |
! ! |
0 | 101 |
|
102 |
!ListSelectionBox class methodsFor:'defaults'! |
|
103 |
||
104 |
defaultExtent |
|
105 |
^ (Display pixelPerMillimeter * (80 @ 100)) rounded |
|
12 | 106 |
! |
107 |
||
108 |
listViewType |
|
109 |
"return the type of listView |
|
110 |
- for easier redefinition in subclasses" |
|
111 |
||
112 |
^ SelectionInListView |
|
0 | 113 |
! ! |
114 |
||
197 | 115 |
!ListSelectionBox methodsFor:'accessing'! |
116 |
||
117 |
initialText:someString |
|
118 |
"in addition to showing the initial text, also select it in the list" |
|
0 | 119 |
|
197 | 120 |
super initialText:someString. |
121 |
selectionList selectElement:someString. |
|
122 |
! |
|
123 |
||
124 |
list:aList |
|
125 |
"set the list to be displayed in selection list" |
|
126 |
||
127 |
selectionList list:aList |
|
128 |
! ! |
|
0 | 129 |
|
197 | 130 |
!ListSelectionBox methodsFor:'accessing-components'! |
131 |
||
132 |
listView |
|
133 |
"return the listView component" |
|
134 |
||
135 |
^ selectionList |
|
0 | 136 |
|
197 | 137 |
"Created: 26.10.1995 / 17:08:32 / cg" |
138 |
! ! |
|
139 |
||
140 |
!ListSelectionBox methodsFor:'accessing-look'! |
|
141 |
||
142 |
noEnterField |
|
143 |
enterField destroy. |
|
144 |
enterField := nil |
|
145 |
||
146 |
"Created: 26.10.1995 / 17:12:38 / cg" |
|
0 | 147 |
! ! |
148 |
||
149 |
!ListSelectionBox methodsFor:'initialization'! |
|
150 |
||
197 | 151 |
focusSequence |
152 |
^ Array with:enterField with:selectionList with:abortButton with:okButton |
|
153 |
! |
|
154 |
||
0 | 155 |
initialize |
166 | 156 |
|space2 halfSpace v vbw eH| |
0 | 157 |
|
158 |
super initialize. |
|
159 |
||
77 | 160 |
label := 'Select or enter'. |
161 |
||
0 | 162 |
"need more space than an enterBox" |
163 |
||
164 |
"self height:(height + (font height * 5)). " |
|
165 |
||
166 |
space2 := 2 * ViewSpacing. |
|
125 | 167 |
halfSpace := ViewSpacing // 2. |
0 | 168 |
|
12 | 169 |
v := ScrollableView for:(self class listViewType) in:self. |
0 | 170 |
|
132 | 171 |
"/ old: |
172 |
"/ v origin:[0.0 |
|
125 | 173 |
"/ @ |
132 | 174 |
"/ (enterField origin y + enterField height + ViewSpacing)] |
175 |
"/ extent:[1.0 |
|
125 | 176 |
"/ @ |
132 | 177 |
"/ (height |
125 | 178 |
"/ - ViewSpacing - labelField heightIncludingBorder |
179 |
"/ - ViewSpacing - enterField heightIncludingBorder |
|
180 |
"/ - buttonPanel heightIncludingBorder - ViewSpacing |
|
181 |
"/ - space2) |
|
132 | 182 |
"/ ]. |
183 |
||
184 |
"/ new: |
|
166 | 185 |
v origin:[enterField notNil ifTrue:[ |
186 |
0.0 @ (enterField origin y + enterField height + ViewSpacing) |
|
187 |
] ifFalse:[ |
|
188 |
0.0 @ (labelField origin y + labelField height + ViewSpacing) |
|
189 |
] |
|
190 |
] |
|
132 | 191 |
corner:(1.0 @ 1.0). |
192 |
v bottomInset:(buttonPanel preferredExtent y + ViewSpacing). |
|
193 |
||
139 | 194 |
vbw := v borderWidth. |
195 |
v leftInset:halfSpace+vbw; |
|
196 |
rightInset:halfSpace+vbw. |
|
110 | 197 |
|
0 | 198 |
selectionList := v scrolledView. |
199 |
||
200 |
"self updateList." |
|
201 |
||
132 | 202 |
"I am interested in what is done int the selectionList |
203 |
(could also create a SelectionInList-model and catch its changes ...)" |
|
204 |
selectionList action:[:lineNr | self selectionChanged]. |
|
205 |
selectionList doubleClickAction:[:lineNr | self doubleClick]. |
|
206 |
||
130 | 207 |
enterField removeDependent:self. "dont want preferredExtent-changes" |
128 | 208 |
|
38 | 209 |
" |
210 |
mhm: the lists keyboard functions are disabled, |
|
319
d78f5fbdee27
dont forward Cursor-motion to the enterField
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
211 |
and input passed to the enterfield (except cursor keys) |
38 | 212 |
" |
319
d78f5fbdee27
dont forward Cursor-motion to the enterField
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
213 |
selectionList delegate:( |
d78f5fbdee27
dont forward Cursor-motion to the enterField
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
214 |
KeyboardForwarder |
d78f5fbdee27
dont forward Cursor-motion to the enterField
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
215 |
toView:enterField |
d78f5fbdee27
dont forward Cursor-motion to the enterField
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
216 |
condition:#noFocus |
d78f5fbdee27
dont forward Cursor-motion to the enterField
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
217 |
filter:[:key | (key ~~ #CursorUp) and:[key ~~ #CursorDown]] |
d78f5fbdee27
dont forward Cursor-motion to the enterField
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
218 |
) |
166 | 219 |
|
220 |
"Modified: 26.10.1995 / 17:18:23 / cg" |
|
0 | 221 |
! |
222 |
||
223 |
realize |
|
224 |
self updateList. |
|
225 |
super realize |
|
77 | 226 |
! |
227 |
||
197 | 228 |
updateList |
229 |
"setup contents of list; nothing done here but redefined in subclasses" |
|
230 |
||
231 |
^ self |
|
0 | 232 |
! ! |
233 |
||
59 | 234 |
!ListSelectionBox methodsFor:'queries'! |
0 | 235 |
|
130 | 236 |
preferredExtent |
237 |
"return my preferred extent - thats the minimum size |
|
125 | 238 |
I like to have, to make everything visible" |
0 | 239 |
|
371 | 240 |
|wWanted hWanted eH mm| |
241 |
||
242 |
mm := ViewSpacing. |
|
125 | 243 |
|
371 | 244 |
wWanted := mm + labelField width + mm. |
0 | 245 |
(wWanted > width) ifFalse:[ |
371 | 246 |
wWanted := width |
0 | 247 |
]. |
125 | 248 |
|
166 | 249 |
enterField notNil ifTrue:[ |
371 | 250 |
eH := enterField height + mm |
166 | 251 |
] ifFalse:[ |
371 | 252 |
eH := 0 |
166 | 253 |
]. |
371 | 254 |
hWanted := mm + labelField height + |
255 |
eH + |
|
256 |
mm + selectionList height + |
|
257 |
mm + buttonPanel preferredExtent y + |
|
258 |
mm - (mm * 2). |
|
0 | 259 |
|
260 |
(hWanted < height) ifTrue:[ |
|
371 | 261 |
hWanted := height |
0 | 262 |
]. |
59 | 263 |
^ (wWanted @ hWanted) |
166 | 264 |
|
371 | 265 |
"Modified: 21.2.1996 / 01:01:02 / cg" |
0 | 266 |
! ! |
267 |
||
132 | 268 |
!ListSelectionBox methodsFor:'user actions'! |
269 |
||
197 | 270 |
doubleClick |
271 |
"doubleClick on an entry is select & ok" |
|
272 |
||
273 |
enterField contents:(selectionList selectionValue). |
|
274 |
self okPressed |
|
275 |
! |
|
276 |
||
132 | 277 |
selectionChanged |
278 |
"selections in list get forwarded to enterfield" |
|
279 |
||
166 | 280 |
enterField notNil ifTrue:[ |
281 |
enterField contents:(selectionList selectionValue) |
|
282 |
] |
|
283 |
||
284 |
"Modified: 26.10.1995 / 17:20:06 / cg" |
|
285 |
! ! |
|
286 |
||
243 | 287 |
!ListSelectionBox class methodsFor:'documentation'! |
288 |
||
289 |
version |
|
371 | 290 |
^ '$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.23 1996-02-21 00:01:15 cg Exp $' |
243 | 291 |
! ! |