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