11
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
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 |
SelectionInListView subclass:#FileSelectionList
|
|
14 |
instanceVariableNames:'pattern directory timeStamp directoryId
|
|
15 |
directoryContents directoryFileTypes
|
21
|
16 |
realAction fileTypes'
|
11
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Views-Text'
|
|
20 |
!
|
|
21 |
|
|
22 |
FileSelectionList comment:'
|
|
23 |
|
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
25 |
All Rights Reserved
|
|
26 |
|
24
|
27 |
$Header: /cvs/stx/stx/libwidg/FileSelectionList.st,v 1.3 1994-01-13 00:15:25 claus Exp $
|
11
|
28 |
written Dec 93 by claus
|
|
29 |
'!
|
|
30 |
|
|
31 |
!FileSelectionList class methodsFor:'documentation'!
|
|
32 |
|
|
33 |
documentation
|
|
34 |
"
|
|
35 |
this class implements file selection lists - its basically a
|
|
36 |
selection in list, but remembers the previous position when
|
|
37 |
changing directories.
|
|
38 |
Only files matching a pattern (plus directories) are shown.
|
21
|
39 |
|
|
40 |
Instance variables:
|
|
41 |
directoryContents contents of current directory
|
|
42 |
directoryFileTypes file types (symbols) of current directory
|
|
43 |
fileTypes file types as shown in list
|
|
44 |
(i.e only matching ones)
|
11
|
45 |
"
|
|
46 |
! !
|
|
47 |
|
|
48 |
!FileSelectionList methodsFor:'initialization'!
|
|
49 |
|
|
50 |
initialize
|
|
51 |
directory := FileDirectory currentDirectory.
|
|
52 |
super initialize.
|
|
53 |
|
|
54 |
pattern := '*'.
|
|
55 |
|
|
56 |
"selections in list get forwarded to enterfield if not a directory;
|
|
57 |
otherwise directory is changed"
|
|
58 |
|
|
59 |
actionBlock := [:lineNr |
|
|
60 |
|entry|
|
|
61 |
|
|
62 |
(self selection isKindOf:Collection) ifFalse:[
|
|
63 |
entry := self selectionValue.
|
|
64 |
(entry endsWith:' ...') ifTrue:[
|
|
65 |
entry := entry copyTo:(entry size - 4).
|
|
66 |
].
|
|
67 |
((directory typeOf:entry) == #directory) ifTrue:[
|
|
68 |
(directory isReadable:entry) ifFalse:[
|
|
69 |
self warn:(resources string:'not allowed to read directory %1' with:entry)
|
|
70 |
] ifTrue:[
|
|
71 |
(directory isExecutable:entry) ifFalse:[
|
|
72 |
self warn:(resources string:'not allowed to change to directory %1' with:entry)
|
|
73 |
] ifTrue:[
|
|
74 |
self directory:(directory pathName , Filename separator asString , entry)
|
|
75 |
]
|
|
76 |
].
|
|
77 |
] ifFalse:[
|
|
78 |
realAction notNil ifTrue:[
|
|
79 |
realAction value:lineNr
|
|
80 |
]
|
|
81 |
]
|
|
82 |
]
|
|
83 |
]
|
|
84 |
|
|
85 |
"FileSelectionList new realize"
|
|
86 |
!
|
|
87 |
|
|
88 |
reinitialize
|
|
89 |
directory := FileDirectory currentDirectory.
|
|
90 |
super reinitialize
|
|
91 |
! !
|
|
92 |
|
|
93 |
!FileSelectionList methodsFor:'accessing'!
|
|
94 |
|
|
95 |
action:aBlock
|
|
96 |
"set the action to be performed on a selection"
|
|
97 |
|
|
98 |
realAction := aBlock
|
|
99 |
!
|
|
100 |
|
|
101 |
directory
|
|
102 |
"return the shown directory"
|
|
103 |
|
|
104 |
^ directory
|
|
105 |
!
|
|
106 |
|
|
107 |
directory:nameOrDirectory
|
|
108 |
"set the lists contents to the filenames in the directory"
|
|
109 |
|
|
110 |
|oldPath name|
|
|
111 |
|
|
112 |
(nameOrDirectory isKindOf:String) ifTrue:[
|
|
113 |
name := nameOrDirectory
|
|
114 |
] ifFalse:[
|
|
115 |
name := nameOrDirectory pathName
|
|
116 |
].
|
|
117 |
oldPath := directory pathName.
|
|
118 |
directory pathName:name.
|
|
119 |
(directory pathName = oldPath) ifFalse:[
|
|
120 |
self updateList
|
|
121 |
]
|
|
122 |
!
|
|
123 |
|
|
124 |
pattern:aPattern
|
|
125 |
"set the pattern - if it changes, update the list."
|
|
126 |
|
|
127 |
pattern ~= aPattern ifTrue:[
|
|
128 |
pattern := aPattern.
|
|
129 |
realized ifTrue:[
|
|
130 |
self updateList
|
|
131 |
].
|
|
132 |
].
|
|
133 |
! !
|
|
134 |
|
21
|
135 |
!FileSelectionList methodsFor:'drawing'!
|
|
136 |
|
|
137 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr
|
|
138 |
"redefined to look for directory in every line"
|
|
139 |
|
24
|
140 |
|l|
|
|
141 |
|
|
142 |
"first, draw chunk of lines"
|
|
143 |
super redrawFromVisibleLine:startVisLineNr to:endVisLineNr.
|
|
144 |
|
|
145 |
"then draw marks"
|
|
146 |
startVisLineNr to:endVisLineNr do:[:visLineNr |
|
|
147 |
l := self visibleLineToListLine:visLineNr.
|
|
148 |
l notNil ifTrue:[
|
|
149 |
(fileTypes at:l) == #directory ifTrue:[
|
|
150 |
self drawRightArrowInVisibleLine:visLineNr
|
|
151 |
]
|
|
152 |
]
|
21
|
153 |
]
|
|
154 |
!
|
|
155 |
|
|
156 |
redrawVisibleLine:visLineNr
|
|
157 |
"if the line is one for a directory, draw a right arrow"
|
|
158 |
|
|
159 |
|l|
|
|
160 |
|
|
161 |
super redrawVisibleLine:visLineNr.
|
|
162 |
l := self visibleLineToListLine:visLineNr.
|
|
163 |
l notNil ifTrue:[
|
|
164 |
(fileTypes at:l) == #directory ifTrue:[
|
|
165 |
self drawRightArrowInVisibleLine:visLineNr
|
|
166 |
]
|
|
167 |
]
|
|
168 |
! !
|
|
169 |
|
11
|
170 |
!FileSelectionList methodsFor:'private'!
|
|
171 |
|
21
|
172 |
visibleLineNeedsSpecialCare:visLineNr
|
|
173 |
|l|
|
|
174 |
|
|
175 |
l := self visibleLineToListLine:visLineNr.
|
|
176 |
l notNil ifTrue:[
|
|
177 |
(fileTypes at:l) == #directory ifTrue:[^ true].
|
|
178 |
^ super visibleLineNeedsSpecialCare:visLineNr
|
|
179 |
].
|
|
180 |
^ false
|
|
181 |
!
|
|
182 |
|
|
183 |
widthForScrollBetween:firstLine and:lastLine
|
|
184 |
"return the width in pixels for a scroll between firstLine and lastLine
|
|
185 |
- return full width here since there might be directory marks"
|
|
186 |
|
|
187 |
^ (width - margin - margin)
|
|
188 |
!
|
|
189 |
|
11
|
190 |
updateList
|
|
191 |
"set the lists contents to the filenames in the directory"
|
|
192 |
|
|
193 |
|oldCursor files newList index|
|
|
194 |
|
|
195 |
oldCursor := cursor.
|
|
196 |
self cursor:(Cursor read).
|
|
197 |
|
|
198 |
directoryId == directory id ifFalse:[
|
|
199 |
timeStamp := directory timeOfLastChange.
|
|
200 |
directoryId := directory id.
|
|
201 |
directoryContents := directory asText sort.
|
|
202 |
directoryFileTypes := OrderedCollection new.
|
|
203 |
directoryContents do:[:name | directoryFileTypes add:(directory typeOf:name)].
|
|
204 |
].
|
|
205 |
|
|
206 |
files := directoryContents.
|
|
207 |
newList := OrderedCollection new.
|
21
|
208 |
fileTypes := OrderedCollection new.
|
11
|
209 |
index := 1.
|
|
210 |
files do:[:name |
|
|
211 |
(directoryFileTypes at:index) == #directory ifTrue:[
|
|
212 |
name = '..' ifTrue:[
|
21
|
213 |
newList add:name.
|
|
214 |
fileTypes add:(directoryFileTypes at:index)
|
11
|
215 |
] ifFalse:[
|
|
216 |
name = '.' ifTrue:[
|
21
|
217 |
"ignore"
|
11
|
218 |
] ifFalse:[
|
21
|
219 |
newList add:(name ", ' ...'").
|
|
220 |
fileTypes add:(directoryFileTypes at:index)
|
11
|
221 |
]
|
|
222 |
]
|
|
223 |
] ifFalse:[
|
|
224 |
(pattern isEmpty or:[pattern = '*' or:[pattern match:name]]) ifTrue:[
|
21
|
225 |
newList add:name.
|
|
226 |
fileTypes add:(directoryFileTypes at:index)
|
11
|
227 |
]
|
|
228 |
].
|
|
229 |
index := index + 1
|
|
230 |
].
|
|
231 |
super list:newList.
|
|
232 |
self cursor:oldCursor.
|
|
233 |
! !
|
|
234 |
|
|
235 |
!FileSelectionList methodsFor:'realization'!
|
|
236 |
|
|
237 |
realize
|
|
238 |
"make the view visible; redefined to check if directory is still
|
|
239 |
valid (using timestamp and inode numbers) - reread if not"
|
|
240 |
|
|
241 |
(timeStamp isNil
|
|
242 |
or:[(directory timeOfLastChange > timeStamp)
|
|
243 |
or:[(directoryId isNil)
|
|
244 |
or:[directoryId ~~ directory id]]]) ifTrue:[
|
|
245 |
directoryId := nil.
|
|
246 |
self updateList
|
|
247 |
].
|
|
248 |
super realize
|
|
249 |
! !
|