author | Claus Gittinger <cg@exept.de> |
Fri, 15 Jun 2018 10:54:35 +0200 | |
changeset 5816 | 7876c07931a7 |
parent 5255 | 9874f11a4ae3 |
child 5831 | d4ddd3b421ac |
child 5970 | 53fd42d2c814 |
permissions | -rw-r--r-- |
5255 | 1 |
"{ Encoding: utf8 }" |
2 |
||
12 | 3 |
" |
4 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
25 | 5 |
All Rights Reserved |
12 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
2103
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
14 |
"{ Package: 'stx:libwidg2' }" |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
15 |
|
5255 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
136 | 18 |
EditField subclass:#FilenameEditField |
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
19 |
instanceVariableNames:'directoriesOnly filesOnly directory acceptOnExpand' |
136 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
22 |
category:'Views-Text' |
|
12 | 23 |
! |
24 |
||
25 |
!FilenameEditField class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
25 | 30 |
All Rights Reserved |
12 | 31 |
|
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
24 | 43 |
like a normal editField, but does filename-completion on the last word of |
44 |
the contents, when TAB is pressed. |
|
43 | 45 |
Filename completion ignores regular files if directoriesOnly is true, |
46 |
and ignores directories, if filesOnly is true. Both default to false. |
|
158 | 47 |
|
48 |
[author:] |
|
49 |
Claus Gittinger |
|
12 | 50 |
" |
3587 | 51 |
! |
52 |
||
53 |
examples |
|
54 |
" |
|
55 |
|t f b v| |
|
56 |
||
57 |
v := ValueHolder with:'c:\'. |
|
58 |
||
59 |
t := StandardSystemView new. |
|
60 |
f := FilenameEditField in:t. |
|
61 |
f origin:10@10 corner:1.0@30. |
|
62 |
f model:v. |
|
63 |
||
64 |
b := Button in:t. |
|
65 |
b label:'Check'. |
|
66 |
b action:[ |
|
67 |
Transcript show:'field: '; showCR: f contents. |
|
68 |
Transcript show:'model: '; showCR: v value. |
|
69 |
]. |
|
70 |
b origin:10@40. |
|
71 |
t open. |
|
72 |
||
73 |
" |
|
12 | 74 |
! ! |
75 |
||
136 | 76 |
!FilenameEditField methodsFor:'accessing'! |
77 |
||
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
78 |
acceptOnExpand |
3951 | 79 |
"return the autoAccept on filename expansion (pressing tab key) flag. |
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
80 |
The default is true, which means that an expand accepts" |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
81 |
|
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
82 |
^ acceptOnExpand |
3951 | 83 |
|
84 |
"Modified: / 20-10-2010 / 17:49:23 / cg" |
|
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
85 |
! |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
86 |
|
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
87 |
acceptOnExpand:aBoolean |
3951 | 88 |
"set/clear autoAccept on filename expansion (pressing tab key). |
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
89 |
The default is true, which means that an expand accepts" |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
90 |
|
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
91 |
acceptOnExpand := aBoolean |
3951 | 92 |
|
93 |
"Modified: / 20-10-2010 / 17:49:11 / cg" |
|
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
94 |
! |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
95 |
|
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
96 |
contents:someText |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
97 |
"redefined to add a trailing file-separator if the displayed |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
98 |
filename is a directory" |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
99 |
|
2103
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
100 |
^ self |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
101 |
contents:someText |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
102 |
addSeparatorToDirectories:true |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
103 |
! |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
104 |
|
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
105 |
contents:someText addSeparatorToDirectories:doAddSeparator |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
106 |
"optionally add a trailing file-separator if the displayed |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
107 |
filename is a directory." |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
108 |
|
2584 | 109 |
|newText f nm| |
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
110 |
|
2584 | 111 |
newText := someText. |
2103
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
112 |
doAddSeparator ifTrue:[ |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
113 |
directoriesOnly ifFalse:[ |
3270
4cc2bba35a69
care for empty filename (do not add a slash)
Claus Gittinger <cg@exept.de>
parents:
3195
diff
changeset
|
114 |
someText notEmptyOrNil ifTrue:[ |
2103
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
115 |
f := someText asFilename. |
2584 | 116 |
(f exists and:[f "asAbsoluteFilename" isDirectory]) ifTrue:[ |
117 |
nm := f name. |
|
118 |
(nm endsWith:f separator) ifFalse:[ |
|
119 |
newText := nm copyWith:f separator |
|
2103
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
120 |
] |
1428 | 121 |
] |
2103
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
122 |
]. |
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
123 |
]. |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
124 |
]. |
2584 | 125 |
super contents:newText. |
126 |
self cursorToEndOfLine. |
|
3270
4cc2bba35a69
care for empty filename (do not add a slash)
Claus Gittinger <cg@exept.de>
parents:
3195
diff
changeset
|
127 |
|
4cc2bba35a69
care for empty filename (do not add a slash)
Claus Gittinger <cg@exept.de>
parents:
3195
diff
changeset
|
128 |
"Modified: / 08-11-2007 / 11:54:05 / cg" |
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
129 |
! |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
130 |
|
136 | 131 |
directoriesOnly |
3647 | 132 |
<resource: #obsolete> |
136 | 133 |
"set to expand names for directories only" |
134 |
||
3591
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
135 |
self obsoleteMethodWarning. |
136 | 136 |
directoriesOnly := true. |
137 |
! |
|
138 |
||
3591
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
139 |
directoriesOnly:aBoolean |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
140 |
"control if only directories can be choosen" |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
141 |
|
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
142 |
directoriesOnly := aBoolean. |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
143 |
directoriesOnly ifTrue:[ |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
144 |
filesOnly := false. |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
145 |
]. |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
146 |
! |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
147 |
|
136 | 148 |
directory |
149 |
^ directory |
|
150 |
||
151 |
"Modified: 7.9.1995 / 10:12:40 / claus" |
|
152 |
! |
|
153 |
||
154 |
directory:aFilename |
|
152 | 155 |
aFilename isNil ifTrue:[ |
156 |
directory := Filename currentDirectory |
|
157 |
] ifFalse:[ |
|
158 |
directory := aFilename asFilename |
|
159 |
] |
|
136 | 160 |
"Modified: 7.9.1995 / 10:12:55 / claus" |
161 |
! |
|
162 |
||
163 |
filesOnly |
|
3647 | 164 |
<resource: #obsolete> |
136 | 165 |
"set to expand names for files only" |
166 |
||
3591
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
167 |
self obsoleteMethodWarning. |
136 | 168 |
filesOnly := true. |
169 |
! |
|
170 |
||
3591
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
171 |
filesOnly:aBoolean |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
172 |
"control if only files can be choosen" |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
173 |
|
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
174 |
filesOnly := aBoolean. |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
175 |
filesOnly ifTrue:[ |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
176 |
directoriesOnly := false. |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
177 |
]. |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
178 |
! |
49dcfd92398a
fixes (thanx to bretts info)
Claus Gittinger <cg@exept.de>
parents:
3587
diff
changeset
|
179 |
|
136 | 180 |
initialText:aString selected:aBoolean |
5255 | 181 |
"redefined to move the cursor to the end |
182 |
- that's the most interesting part of a filename |
|
136 | 183 |
" |
184 |
||
185 |
super initialText:aString selected:aBoolean. |
|
186 |
self cursorToEndOfLine. |
|
187 |
! |
|
188 |
||
189 |
showsDirectoriesOnly |
|
190 |
"return if expanding names for directories only" |
|
191 |
||
192 |
^ directoriesOnly |
|
193 |
||
194 |
"Modified: 6.9.1995 / 20:35:30 / claus" |
|
195 |
! |
|
196 |
||
197 |
showsFilesOnly |
|
198 |
"return if expanding names for files only" |
|
199 |
||
200 |
^ filesOnly |
|
201 |
||
202 |
"Modified: 6.9.1995 / 20:34:57 / claus" |
|
203 |
! ! |
|
204 |
||
3595 | 205 |
!FilenameEditField methodsFor:'actions'! |
206 |
||
207 |
doFilenameCompletionFor:aString |
|
208 |
|newString isMultiMatch canonContents| |
|
209 |
||
210 |
isMultiMatch := false. |
|
211 |
canonContents := Filename canonicalize:aString. |
|
212 |
||
213 |
newString := Filename |
|
214 |
filenameCompletionFor:canonContents |
|
215 |
directory:directory |
|
216 |
directoriesOnly:directoriesOnly |
|
217 |
filesOnly:filesOnly |
|
218 |
ifMultiple:[:dir | |
|
219 |
"/ dir asFilename isDirectory ifTrue:[ |
|
220 |
"/ self changed:#directory with:dir. |
|
221 |
"/ ]. |
|
222 |
isMultiMatch := true. |
|
223 |
self flash. |
|
224 |
]. |
|
4103
41321b521425
comment/format in: #doFilenameCompletionFor:
Claus Gittinger <cg@exept.de>
parents:
4102
diff
changeset
|
225 |
|
41321b521425
comment/format in: #doFilenameCompletionFor:
Claus Gittinger <cg@exept.de>
parents:
4102
diff
changeset
|
226 |
"/ chose the one, if there is only one |
3595 | 227 |
newString asFilename pathName = canonContents ifTrue:[ |
4102
7dc70f1ff7aa
changed: #doFilenameCompletionFor:
Claus Gittinger <cg@exept.de>
parents:
3951
diff
changeset
|
228 |
directory := canonContents asFilename. |
7dc70f1ff7aa
changed: #doFilenameCompletionFor:
Claus Gittinger <cg@exept.de>
parents:
3951
diff
changeset
|
229 |
(directory exists |
7dc70f1ff7aa
changed: #doFilenameCompletionFor:
Claus Gittinger <cg@exept.de>
parents:
3951
diff
changeset
|
230 |
and:[directory isDirectory |
7dc70f1ff7aa
changed: #doFilenameCompletionFor:
Claus Gittinger <cg@exept.de>
parents:
3951
diff
changeset
|
231 |
and:[directory directoryContents size = 1 ]]) ifTrue:[ |
7dc70f1ff7aa
changed: #doFilenameCompletionFor:
Claus Gittinger <cg@exept.de>
parents:
3951
diff
changeset
|
232 |
newString := (directory construct:(directory directoryContents first)) pathName. |
7dc70f1ff7aa
changed: #doFilenameCompletionFor:
Claus Gittinger <cg@exept.de>
parents:
3951
diff
changeset
|
233 |
] ifFalse:[ |
7dc70f1ff7aa
changed: #doFilenameCompletionFor:
Claus Gittinger <cg@exept.de>
parents:
3951
diff
changeset
|
234 |
self flash. |
7dc70f1ff7aa
changed: #doFilenameCompletionFor:
Claus Gittinger <cg@exept.de>
parents:
3951
diff
changeset
|
235 |
] |
3595 | 236 |
]. |
237 |
||
238 |
self contents:newString addSeparatorToDirectories:isMultiMatch not. |
|
4102
7dc70f1ff7aa
changed: #doFilenameCompletionFor:
Claus Gittinger <cg@exept.de>
parents:
3951
diff
changeset
|
239 |
|
4103
41321b521425
comment/format in: #doFilenameCompletionFor:
Claus Gittinger <cg@exept.de>
parents:
4102
diff
changeset
|
240 |
"Modified (comment): / 23-01-2012 / 18:24:34 / cg" |
3595 | 241 |
! ! |
242 |
||
136 | 243 |
!FilenameEditField methodsFor:'event handling'! |
244 |
||
245 |
keyPress:key x:x y:y |
|
246 |
"handle tab for filename completion. |
|
247 |
Bug: it completes the last word; it should complete the |
|
248 |
word before the cursor." |
|
249 |
||
250 |
<resource: #keyboard ( #Tab #FilenameCompletion ) > |
|
251 |
||
289 | 252 |
|oldContents newContents| |
136 | 253 |
|
254 |
enabled ifTrue:[ |
|
3195 | 255 |
((key == entryCompletionCharacter) or:[key == #FilenameCompletion]) ifTrue:[ |
289 | 256 |
oldContents := self contents. |
257 |
oldContents isNil ifTrue:[ |
|
258 |
oldContents := '' |
|
136 | 259 |
] ifFalse:[ |
289 | 260 |
oldContents := oldContents asString |
136 | 261 |
]. |
289 | 262 |
|
2717 | 263 |
self entryCompletionBlock value:oldContents. |
289 | 264 |
|
265 |
newContents := self contents. |
|
266 |
newContents isNil ifTrue:[ |
|
267 |
newContents := '' |
|
268 |
] ifFalse:[ |
|
269 |
newContents := newContents asString |
|
270 |
]. |
|
271 |
newContents ~= oldContents ifTrue:[ |
|
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
272 |
self textChanged. |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
273 |
acceptOnExpand ifTrue:[ |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
274 |
self accept |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
275 |
] |
289 | 276 |
]. |
136 | 277 |
^ self |
278 |
] |
|
279 |
]. |
|
3606 | 280 |
super keyPress:key x:x y:y. |
136 | 281 |
|
3195 | 282 |
"Modified: / 06-03-2007 / 21:40:52 / cg" |
136 | 283 |
! ! |
284 |
||
72 | 285 |
!FilenameEditField methodsFor:'initialization'! |
286 |
||
287 |
initialize |
|
288 |
super initialize. |
|
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
289 |
|
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
290 |
acceptOnExpand := true. |
72 | 291 |
directoriesOnly := filesOnly := false. |
523 | 292 |
directory := Filename currentDirectory. |
72 | 293 |
|
2717 | 294 |
self |
295 |
entryCompletionBlock:[:contents | |
|
3592
697de605902f
completion moved out of the block (to allow for easier editing)
Claus Gittinger <cg@exept.de>
parents:
3591
diff
changeset
|
296 |
self doFilenameCompletionFor:contents. |
2299 | 297 |
]. |
298 |
||
72 | 299 |
"Modified: 7.9.1995 / 10:20:46 / claus" |
523 | 300 |
"Modified: 7.9.1997 / 23:51:47 / cg" |
43 | 301 |
! |
302 |
||
2584 | 303 |
mapped |
5255 | 304 |
"redefined to move the cursor to the end |
305 |
- that's the most interesting part of a filename |
|
34 | 306 |
" |
2584 | 307 |
super mapped. |
308 |
"/ self cursorToEndOfLine. |
|
309 |
self makeCursorVisible. |
|
34 | 310 |
! ! |
311 |
||
136 | 312 |
!FilenameEditField class methodsFor:'documentation'! |
43 | 313 |
|
136 | 314 |
version |
5255 | 315 |
^ '$Header$' |
3951 | 316 |
! |
317 |
||
318 |
version_CVS |
|
5255 | 319 |
^ '$Header$' |
34 | 320 |
! ! |
5255 | 321 |