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
|
|
14 |
instanceVariableNames:'selectionList'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
38
|
17 |
category:'Views-DialogBoxes'
|
0
|
18 |
!
|
|
19 |
|
|
20 |
ListSelectionBox comment:'
|
5
|
21 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
59
|
22 |
All Rights Reserved
|
0
|
23 |
|
122
|
24 |
$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.11 1995-05-07 00:16:17 claus Exp $
|
38
|
25 |
'!
|
|
26 |
|
|
27 |
!ListSelectionBox class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
59
|
32 |
All Rights Reserved
|
38
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
0
|
42 |
|
38
|
43 |
version
|
|
44 |
"
|
122
|
45 |
$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.11 1995-05-07 00:16:17 claus Exp $
|
38
|
46 |
"
|
|
47 |
!
|
0
|
48 |
|
38
|
49 |
documentation
|
|
50 |
"
|
|
51 |
this class implements boxes for selection from a list. It offers
|
|
52 |
both an ok- and abort-buttons. The ok-button, if pressed will
|
|
53 |
evaluate the okAction (see EnterBox>>action).
|
77
|
54 |
see examples for typical uses.
|
|
55 |
|
|
56 |
Notice, for file selections there is a specialized FileSelectionBox,
|
|
57 |
which supports matchPatterns, changing directory etc.
|
|
58 |
"
|
|
59 |
!
|
|
60 |
|
|
61 |
examples
|
|
62 |
"
|
|
63 |
simple:
|
38
|
64 |
|
59
|
65 |
|box|
|
38
|
66 |
|
59
|
67 |
box := ListSelectionBox new.
|
|
68 |
box title:'select something:'.
|
|
69 |
box list:#('foo' 'bar' 'baz').
|
|
70 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel].
|
|
71 |
box showAtPointer
|
77
|
72 |
|
|
73 |
with a default:
|
|
74 |
|
|
75 |
|box|
|
|
76 |
|
|
77 |
box := ListSelectionBox new.
|
|
78 |
box title:'select something:'.
|
|
79 |
box list:#('foo' 'bar' 'baz').
|
|
80 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel].
|
|
81 |
box initialText:'foo'.
|
|
82 |
box showAtPointer
|
38
|
83 |
"
|
|
84 |
! !
|
0
|
85 |
|
|
86 |
!ListSelectionBox class methodsFor:'defaults'!
|
|
87 |
|
|
88 |
defaultExtent
|
|
89 |
^ (Display pixelPerMillimeter * (80 @ 100)) rounded
|
12
|
90 |
!
|
|
91 |
|
|
92 |
listViewType
|
|
93 |
"return the type of listView
|
|
94 |
- for easier redefinition in subclasses"
|
|
95 |
|
|
96 |
^ SelectionInListView
|
0
|
97 |
! !
|
|
98 |
|
|
99 |
!ListSelectionBox class methodsFor:'instance creation'!
|
|
100 |
|
|
101 |
title:titleString okText:okText abortText:abortText list:aList action:aBlock
|
|
102 |
"create and return a new listSelectionBox with list already defined"
|
|
103 |
|
|
104 |
|newBox|
|
|
105 |
|
|
106 |
newBox := super title:titleString okText:okText abortText:abortText
|
59
|
107 |
action:aBlock.
|
0
|
108 |
^ newBox list:aList
|
|
109 |
! !
|
|
110 |
|
|
111 |
!ListSelectionBox methodsFor:'initialization'!
|
|
112 |
|
|
113 |
initialize
|
|
114 |
|space2 v|
|
|
115 |
|
|
116 |
super initialize.
|
|
117 |
|
77
|
118 |
label := 'Select or enter'.
|
|
119 |
|
0
|
120 |
"need more space than an enterBox"
|
|
121 |
|
|
122 |
"self height:(height + (font height * 5)). "
|
|
123 |
|
|
124 |
space2 := 2 * ViewSpacing.
|
|
125 |
|
12
|
126 |
v := ScrollableView for:(self class listViewType) in:self.
|
0
|
127 |
|
|
128 |
"kludge: see note in EnterBox"
|
110
|
129 |
v origin:(0.0
|
59
|
130 |
@
|
|
131 |
(enterField origin y + enterField height + ViewSpacing)).
|
110
|
132 |
v extent:(1.0
|
59
|
133 |
@
|
|
134 |
(height
|
|
135 |
- ViewSpacing - labelField heightIncludingBorder
|
|
136 |
- ViewSpacing - enterField heightIncludingBorder
|
|
137 |
- buttonPanel heightIncludingBorder - ViewSpacing
|
|
138 |
- space2)
|
|
139 |
).
|
110
|
140 |
v origin:[0.0
|
59
|
141 |
@
|
|
142 |
(enterField origin y + enterField height + ViewSpacing)]
|
110
|
143 |
extent:[1.0
|
59
|
144 |
@
|
|
145 |
(height
|
|
146 |
- ViewSpacing - labelField heightIncludingBorder
|
|
147 |
- ViewSpacing - enterField heightIncludingBorder
|
|
148 |
- buttonPanel heightIncludingBorder - ViewSpacing
|
|
149 |
- space2)
|
|
150 |
].
|
110
|
151 |
v leftInset:ViewSpacing//2; rightInset:ViewSpacing//2.
|
|
152 |
|
0
|
153 |
selectionList := v scrolledView.
|
|
154 |
|
|
155 |
"self updateList."
|
|
156 |
|
|
157 |
"selections in list get forwarded to enterfield"
|
|
158 |
selectionList action:[:lineNr |
|
59
|
159 |
enterField contents:(selectionList selectionValue)
|
0
|
160 |
].
|
38
|
161 |
selectionList doubleClickAction:[:lineNr |
|
59
|
162 |
enterField contents:(selectionList selectionValue).
|
|
163 |
self okPressed
|
38
|
164 |
].
|
|
165 |
"
|
|
166 |
mhm: the lists keyboard functions are disabled,
|
|
167 |
and input passed to the enterfield
|
|
168 |
"
|
122
|
169 |
selectionList delegate:(KeyboardForwarder toView:enterField condition:#noFocus)
|
0
|
170 |
!
|
|
171 |
|
|
172 |
updateList
|
|
173 |
"setup contents of list; nothing done here but redefined in subclasses"
|
|
174 |
|
|
175 |
^ self
|
|
176 |
!
|
|
177 |
|
|
178 |
realize
|
|
179 |
self updateList.
|
|
180 |
super realize
|
77
|
181 |
!
|
|
182 |
|
|
183 |
focusSequence
|
118
|
184 |
^ Array with:enterField with:selectionList with:abortButton with:okButton
|
0
|
185 |
! !
|
|
186 |
|
59
|
187 |
!ListSelectionBox methodsFor:'queries'!
|
0
|
188 |
|
59
|
189 |
preferedExtent
|
|
190 |
"return my prefered extent - thats the minimum size
|
|
191 |
to make everything visible"
|
0
|
192 |
|
|
193 |
|wWanted hWanted|
|
|
194 |
|
|
195 |
wWanted := labelField width + ViewSpacing + ViewSpacing.
|
|
196 |
(wWanted > width) ifFalse:[
|
59
|
197 |
wWanted := width
|
0
|
198 |
].
|
|
199 |
hWanted := ViewSpacing + labelField height +
|
59
|
200 |
ViewSpacing + enterField height +
|
|
201 |
ViewSpacing + selectionList height +
|
77
|
202 |
ViewSpacing + buttonPanel preferedExtent y +
|
59
|
203 |
ViewSpacing.
|
0
|
204 |
|
|
205 |
(hWanted < height) ifTrue:[
|
59
|
206 |
hWanted := height
|
0
|
207 |
].
|
59
|
208 |
^ (wWanted @ hWanted)
|
0
|
209 |
! !
|
|
210 |
|
|
211 |
!ListSelectionBox methodsFor:'accessing'!
|
|
212 |
|
|
213 |
list:aList
|
|
214 |
"set the list to be displayed in selection list"
|
|
215 |
|
|
216 |
selectionList list:aList
|
|
217 |
! !
|