author | Claus Gittinger <cg@exept.de> |
Tue, 11 May 2004 14:50:21 +0200 | |
changeset 2704 | 0a09fd78eb54 |
parent 2584 | 5b3da940cb71 |
child 2717 | f5738b80c8ca |
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 |
" |
|
12 |
||
2103
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
13 |
"{ Package: 'stx:libwidg2' }" |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
14 |
|
136 | 15 |
EditField subclass:#FilenameEditField |
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
16 |
instanceVariableNames:'directoriesOnly filesOnly directory acceptOnExpand' |
136 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'Views-Text' |
|
12 | 20 |
! |
21 |
||
22 |
!FilenameEditField class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
25 | 27 |
All Rights Reserved |
12 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
24 | 40 |
like a normal editField, but does filename-completion on the last word of |
41 |
the contents, when TAB is pressed. |
|
43 | 42 |
Filename completion ignores regular files if directoriesOnly is true, |
43 |
and ignores directories, if filesOnly is true. Both default to false. |
|
158 | 44 |
|
45 |
[author:] |
|
46 |
Claus Gittinger |
|
12 | 47 |
" |
48 |
! ! |
|
49 |
||
136 | 50 |
!FilenameEditField methodsFor:'accessing'! |
51 |
||
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
52 |
acceptOnExpand |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
53 |
"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
|
54 |
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
|
55 |
|
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
56 |
^ acceptOnExpand |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
57 |
! |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
58 |
|
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
59 |
acceptOnExpand:aBoolean |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
60 |
"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
|
61 |
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
|
62 |
|
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
63 |
acceptOnExpand := aBoolean |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
64 |
! |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
65 |
|
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
66 |
contents:someText |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
67 |
"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
|
68 |
filename is a directory" |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
69 |
|
2103
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
70 |
^ self |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
71 |
contents:someText |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
72 |
addSeparatorToDirectories:true |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
73 |
! |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
74 |
|
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
75 |
contents:someText addSeparatorToDirectories:doAddSeparator |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
76 |
"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
|
77 |
filename is a directory." |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
78 |
|
2584 | 79 |
|newText f nm| |
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
80 |
|
2584 | 81 |
newText := someText. |
2103
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
82 |
doAddSeparator ifTrue:[ |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
83 |
directoriesOnly ifFalse:[ |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
84 |
someText notNil ifTrue:[ |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
85 |
f := someText asFilename. |
2584 | 86 |
(f exists and:[f "asAbsoluteFilename" isDirectory]) ifTrue:[ |
87 |
nm := f name. |
|
88 |
(nm endsWith:f separator) ifFalse:[ |
|
89 |
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
|
90 |
] |
1428 | 91 |
] |
2103
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
92 |
]. |
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
93 |
]. |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
94 |
]. |
2584 | 95 |
super contents:newText. |
96 |
self cursorToEndOfLine. |
|
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
97 |
! |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
98 |
|
136 | 99 |
directoriesOnly |
100 |
"set to expand names for directories only" |
|
101 |
||
102 |
directoriesOnly := true. |
|
103 |
! |
|
104 |
||
105 |
directory |
|
106 |
^ directory |
|
107 |
||
108 |
"Modified: 7.9.1995 / 10:12:40 / claus" |
|
109 |
! |
|
110 |
||
111 |
directory:aFilename |
|
152 | 112 |
aFilename isNil ifTrue:[ |
113 |
directory := Filename currentDirectory |
|
114 |
] ifFalse:[ |
|
115 |
directory := aFilename asFilename |
|
116 |
] |
|
136 | 117 |
"Modified: 7.9.1995 / 10:12:55 / claus" |
118 |
! |
|
119 |
||
120 |
filesOnly |
|
121 |
"set to expand names for files only" |
|
122 |
||
123 |
filesOnly := true. |
|
124 |
! |
|
125 |
||
126 |
initialText:aString selected:aBoolean |
|
127 |
"move the cursor to the end - thats the most interesting part of |
|
128 |
a filename |
|
129 |
" |
|
130 |
||
131 |
super initialText:aString selected:aBoolean. |
|
132 |
self cursorToEndOfLine. |
|
133 |
! |
|
134 |
||
135 |
showsDirectoriesOnly |
|
136 |
"return if expanding names for directories only" |
|
137 |
||
138 |
^ directoriesOnly |
|
139 |
||
140 |
"Modified: 6.9.1995 / 20:35:30 / claus" |
|
141 |
! |
|
142 |
||
143 |
showsFilesOnly |
|
144 |
"return if expanding names for files only" |
|
145 |
||
146 |
^ filesOnly |
|
147 |
||
148 |
"Modified: 6.9.1995 / 20:34:57 / claus" |
|
149 |
! ! |
|
150 |
||
151 |
!FilenameEditField methodsFor:'event handling'! |
|
152 |
||
153 |
keyPress:key x:x y:y |
|
154 |
"handle tab for filename completion. |
|
155 |
Bug: it completes the last word; it should complete the |
|
156 |
word before the cursor." |
|
157 |
||
158 |
<resource: #keyboard ( #Tab #FilenameCompletion ) > |
|
159 |
||
289 | 160 |
|oldContents newContents| |
136 | 161 |
|
162 |
enabled ifTrue:[ |
|
289 | 163 |
((key == entryCompletionCharacter) |
136 | 164 |
or:[key == #FilenameCompletion]) ifTrue:[ |
289 | 165 |
oldContents := self contents. |
166 |
oldContents isNil ifTrue:[ |
|
167 |
oldContents := '' |
|
136 | 168 |
] ifFalse:[ |
289 | 169 |
oldContents := oldContents asString |
136 | 170 |
]. |
289 | 171 |
|
172 |
entryCompletionBlock value:oldContents. |
|
173 |
||
174 |
newContents := self contents. |
|
175 |
newContents isNil ifTrue:[ |
|
176 |
newContents := '' |
|
177 |
] ifFalse:[ |
|
178 |
newContents := newContents asString |
|
179 |
]. |
|
180 |
newContents ~= oldContents ifTrue:[ |
|
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
181 |
self textChanged. |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
182 |
acceptOnExpand ifTrue:[ |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
183 |
self accept |
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
184 |
] |
289 | 185 |
]. |
136 | 186 |
^ self |
187 |
] |
|
188 |
]. |
|
189 |
^ super keyPress:key x:x y:y. |
|
190 |
||
191 |
"Modified: 7.3.1996 / 13:16:49 / cg" |
|
192 |
! ! |
|
193 |
||
72 | 194 |
!FilenameEditField methodsFor:'initialization'! |
195 |
||
196 |
initialize |
|
197 |
super initialize. |
|
1424
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
198 |
|
2ddadf10a7d7
show a trailing fileSep, if displayed name is a directory
Claus Gittinger <cg@exept.de>
parents:
523
diff
changeset
|
199 |
acceptOnExpand := true. |
72 | 200 |
directoriesOnly := filesOnly := false. |
523 | 201 |
directory := Filename currentDirectory. |
72 | 202 |
|
78 | 203 |
entryCompletionBlock := [:contents | |
2299 | 204 |
|newString isMultiMatch canonContents| |
78 | 205 |
|
2103
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
206 |
isMultiMatch := false. |
2299 | 207 |
canonContents := Filename canonicalize:contents. |
163
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
208 |
newString := Filename |
2299 | 209 |
filenameCompletionFor:canonContents |
163
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
210 |
directory:directory |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
211 |
directoriesOnly:directoriesOnly |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
212 |
filesOnly:filesOnly |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
213 |
ifMultiple:[:dir | |
2103
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
214 |
"/ dir asFilename isDirectory ifTrue:[ |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
215 |
"/ self changed:#directory with:dir. |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
216 |
"/ ]. |
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
217 |
isMultiMatch := true. |
163
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
218 |
self flash. |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
219 |
]. |
2299 | 220 |
newString asFilename pathName = canonContents ifTrue:[ |
221 |
self flash. |
|
222 |
]. |
|
223 |
||
2103
0f562666d71a
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
224 |
self contents:newString addSeparatorToDirectories:isMultiMatch not. |
163
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
225 |
self cursorToEndOfLine. |
72 | 226 |
]. |
227 |
||
228 |
"Modified: 7.9.1995 / 10:20:46 / claus" |
|
523 | 229 |
"Modified: 7.9.1997 / 23:51:47 / cg" |
43 | 230 |
! |
231 |
||
2584 | 232 |
mapped |
113
984d84d796c8
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
233 |
"move the cursor to the end - thats the most interesting part of |
34 | 234 |
a filename |
235 |
" |
|
2584 | 236 |
super mapped. |
237 |
"/ self cursorToEndOfLine. |
|
238 |
self makeCursorVisible. |
|
34 | 239 |
! ! |
240 |
||
136 | 241 |
!FilenameEditField class methodsFor:'documentation'! |
43 | 242 |
|
136 | 243 |
version |
2584 | 244 |
^ '$Header: /cvs/stx/stx/libwidg2/FilenameEditField.st,v 1.31 2003-11-19 12:13:56 cg Exp $' |
34 | 245 |
! ! |