0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
0
|
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 |
ListSelectionBox subclass:#FileSelectionBox
|
3
|
14 |
instanceVariableNames:'patternField directory timeStamp directoryId
|
|
15 |
directoryContents directoryFileTypes'
|
0
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Interactors'
|
|
19 |
!
|
|
20 |
|
|
21 |
FileSelectionBox comment:'
|
|
22 |
|
5
|
23 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
0
|
24 |
All Rights Reserved
|
|
25 |
|
|
26 |
this class implements file selection boxes. They show a list of
|
|
27 |
files, and perform an action block with the selected pathname as
|
|
28 |
argument when ok is clicked.
|
|
29 |
|
5
|
30 |
$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.3 1993-10-13 02:47:44 claus Exp $
|
0
|
31 |
written Jan 90 by claus
|
|
32 |
'!
|
|
33 |
|
|
34 |
!FileSelectionBox methodsFor:'initialization'!
|
|
35 |
|
|
36 |
initialize
|
|
37 |
directory := FileDirectory currentDirectory.
|
|
38 |
super initialize.
|
|
39 |
|
3
|
40 |
labelField extent:(0.7 @ labelField height).
|
|
41 |
labelField label:(resources string:'select a file:').
|
|
42 |
labelField adjust:#left.
|
|
43 |
|
|
44 |
patternField := EditField
|
|
45 |
origin:(0.7 @ labelField origin y)
|
|
46 |
corner:(1.0 @ labelField corner y)
|
|
47 |
in:self.
|
|
48 |
patternField initialText:'*'.
|
|
49 |
patternField leaveAction:[:p | self updateList].
|
|
50 |
patternField hidden:true.
|
|
51 |
|
0
|
52 |
"selections in list get forwarded to enterfield if not a directory;
|
|
53 |
otherwise directory is changed"
|
|
54 |
|
|
55 |
selectionList action:[:lineNr |
|
|
56 |
|entry|
|
|
57 |
|
|
58 |
entry := selectionList selectionValue.
|
3
|
59 |
(entry endsWith:' ...') ifTrue:[
|
|
60 |
entry := entry copyTo:(entry size - 4).
|
|
61 |
].
|
0
|
62 |
((directory typeOf:entry) == #directory) ifTrue:[
|
|
63 |
self directory:(directory pathName , '/' , entry)
|
|
64 |
] ifFalse:[
|
|
65 |
enterField contents:entry
|
|
66 |
]
|
|
67 |
]
|
|
68 |
|
|
69 |
"FileSelectionBox new show"
|
|
70 |
!
|
|
71 |
|
|
72 |
reinitialize
|
|
73 |
directory := FileDirectory currentDirectory.
|
|
74 |
super reinitialize
|
|
75 |
! !
|
|
76 |
|
|
77 |
!FileSelectionBox methodsFor:'accessing'!
|
|
78 |
|
|
79 |
directory:nameOrDirectory
|
|
80 |
"set the lists contents to the filenames in the directory name"
|
|
81 |
|
|
82 |
|oldPath name|
|
|
83 |
|
|
84 |
(nameOrDirectory isKindOf:String) ifTrue:[
|
|
85 |
name := nameOrDirectory
|
|
86 |
] ifFalse:[
|
|
87 |
name := nameOrDirectory pathName
|
|
88 |
].
|
|
89 |
oldPath := directory pathName.
|
|
90 |
directory pathName:name.
|
|
91 |
(directory pathName = oldPath) ifFalse:[
|
|
92 |
self updateList
|
|
93 |
]
|
3
|
94 |
!
|
|
95 |
|
|
96 |
pattern:aPattern
|
|
97 |
patternField initialText:aPattern.
|
|
98 |
patternField hidden:false.
|
|
99 |
realized ifTrue:[
|
|
100 |
patternField realize.
|
|
101 |
self updateList
|
|
102 |
].
|
0
|
103 |
! !
|
|
104 |
|
|
105 |
!FileSelectionBox methodsFor:'private'!
|
|
106 |
|
|
107 |
updateList
|
|
108 |
"set the lists contents to the filenames in the directory"
|
|
109 |
|
3
|
110 |
|oldCursor oldListCursor files pattern newList index|
|
0
|
111 |
|
|
112 |
oldCursor := cursor.
|
|
113 |
oldListCursor := selectionList cursor.
|
|
114 |
self cursor:(Cursor read).
|
|
115 |
selectionList cursor:(Cursor read).
|
3
|
116 |
directoryId == directory id ifFalse:[
|
|
117 |
timeStamp := directory timeOfLastChange.
|
|
118 |
directoryId := directory id.
|
|
119 |
directoryContents := directory asText sort.
|
|
120 |
((directoryContents at:1) = '.') ifTrue:[
|
|
121 |
directoryContents removeIndex:1
|
|
122 |
].
|
|
123 |
directoryFileTypes := OrderedCollection new.
|
|
124 |
directoryContents do:[:name | directoryFileTypes add:(directory typeOf:name)].
|
0
|
125 |
].
|
3
|
126 |
files := directoryContents.
|
|
127 |
pattern := patternField contents.
|
|
128 |
newList := OrderedCollection new.
|
|
129 |
index := 1.
|
|
130 |
files do:[:name |
|
|
131 |
(directoryFileTypes at:index) == #directory ifTrue:[
|
|
132 |
name = '..' ifTrue:[
|
|
133 |
newList add:name
|
|
134 |
] ifFalse:[
|
|
135 |
newList add:(name , ' ...')
|
|
136 |
]
|
|
137 |
] ifFalse:[
|
|
138 |
(pattern isEmpty or:[pattern match:name]) ifTrue:[
|
|
139 |
newList add:name
|
|
140 |
]
|
|
141 |
].
|
|
142 |
index := index + 1
|
|
143 |
].
|
|
144 |
self list:newList.
|
0
|
145 |
self cursor:oldCursor.
|
|
146 |
selectionList cursor:oldListCursor
|
|
147 |
! !
|
|
148 |
|
|
149 |
!FileSelectionBox methodsFor:'events'!
|
|
150 |
|
|
151 |
show
|
|
152 |
"make the box visible; redefined to check if directory is still
|
|
153 |
valid (using timestamp and inode numbers) - reread if not"
|
|
154 |
|
|
155 |
(timeStamp isNil
|
|
156 |
or:[(directory timeOfLastChange > timeStamp)
|
|
157 |
or:[(directoryId isNil)
|
|
158 |
or:[directoryId ~~ directory id]]]) ifTrue:[
|
3
|
159 |
directoryId := nil.
|
0
|
160 |
self updateList
|
|
161 |
].
|
|
162 |
super show
|
|
163 |
! !
|
|
164 |
|
|
165 |
!FileSelectionBox methodsFor:'user interaction'!
|
|
166 |
|
|
167 |
okPressed
|
|
168 |
"redefined, since action will be evaluated with full path as argument
|
|
169 |
(instead of enterfields contents only as inherited by EnterBox"
|
|
170 |
|
|
171 |
self hideAndEvaluate:[:string |
|
|
172 |
okAction notNil ifTrue:[
|
|
173 |
okAction value:(directory pathName , '/' , string)
|
|
174 |
]
|
|
175 |
]
|
|
176 |
! !
|