author | ca |
Tue, 28 Jan 1997 12:50:40 +0100 | |
changeset 289 | 032b49184de6 |
parent 163 | c9235372f589 |
child 473 | b219215b326b |
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 |
||
136 | 13 |
EditField subclass:#FilenameEditField |
14 |
instanceVariableNames:'directoriesOnly filesOnly directory' |
|
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Views-Text' |
|
12 | 18 |
! |
19 |
||
20 |
!FilenameEditField class methodsFor:'documentation'! |
|
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
25 | 25 |
All Rights Reserved |
12 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
24 | 38 |
like a normal editField, but does filename-completion on the last word of |
39 |
the contents, when TAB is pressed. |
|
43 | 40 |
Filename completion ignores regular files if directoriesOnly is true, |
41 |
and ignores directories, if filesOnly is true. Both default to false. |
|
158 | 42 |
|
43 |
[author:] |
|
44 |
Claus Gittinger |
|
12 | 45 |
" |
46 |
! ! |
|
47 |
||
136 | 48 |
!FilenameEditField methodsFor:'accessing'! |
49 |
||
50 |
directoriesOnly |
|
51 |
"set to expand names for directories only" |
|
52 |
||
53 |
directoriesOnly := true. |
|
54 |
! |
|
55 |
||
56 |
directory |
|
57 |
^ directory |
|
58 |
||
59 |
"Modified: 7.9.1995 / 10:12:40 / claus" |
|
60 |
! |
|
61 |
||
62 |
directory:aFilename |
|
152 | 63 |
aFilename isNil ifTrue:[ |
64 |
directory := Filename currentDirectory |
|
65 |
] ifFalse:[ |
|
66 |
directory := aFilename asFilename |
|
67 |
] |
|
136 | 68 |
"Modified: 7.9.1995 / 10:12:55 / claus" |
69 |
! |
|
70 |
||
71 |
filesOnly |
|
72 |
"set to expand names for files only" |
|
73 |
||
74 |
filesOnly := true. |
|
75 |
! |
|
76 |
||
77 |
initialText:aString selected:aBoolean |
|
78 |
"move the cursor to the end - thats the most interesting part of |
|
79 |
a filename |
|
80 |
" |
|
81 |
||
82 |
super initialText:aString selected:aBoolean. |
|
83 |
self cursorToEndOfLine. |
|
84 |
! |
|
85 |
||
86 |
showsDirectoriesOnly |
|
87 |
"return if expanding names for directories only" |
|
88 |
||
89 |
^ directoriesOnly |
|
90 |
||
91 |
"Modified: 6.9.1995 / 20:35:30 / claus" |
|
92 |
! |
|
93 |
||
94 |
showsFilesOnly |
|
95 |
"return if expanding names for files only" |
|
96 |
||
97 |
^ filesOnly |
|
98 |
||
99 |
"Modified: 6.9.1995 / 20:34:57 / claus" |
|
100 |
! ! |
|
101 |
||
102 |
!FilenameEditField methodsFor:'event handling'! |
|
103 |
||
104 |
keyPress:key x:x y:y |
|
105 |
"handle tab for filename completion. |
|
106 |
Bug: it completes the last word; it should complete the |
|
107 |
word before the cursor." |
|
108 |
||
109 |
<resource: #keyboard ( #Tab #FilenameCompletion ) > |
|
110 |
||
289 | 111 |
|oldContents newContents| |
136 | 112 |
|
113 |
enabled ifTrue:[ |
|
289 | 114 |
((key == entryCompletionCharacter) |
136 | 115 |
or:[key == #FilenameCompletion]) ifTrue:[ |
289 | 116 |
oldContents := self contents. |
117 |
oldContents isNil ifTrue:[ |
|
118 |
oldContents := '' |
|
136 | 119 |
] ifFalse:[ |
289 | 120 |
oldContents := oldContents asString |
136 | 121 |
]. |
289 | 122 |
|
123 |
entryCompletionBlock value:oldContents. |
|
124 |
||
125 |
newContents := self contents. |
|
126 |
newContents isNil ifTrue:[ |
|
127 |
newContents := '' |
|
128 |
] ifFalse:[ |
|
129 |
newContents := newContents asString |
|
130 |
]. |
|
131 |
newContents ~= oldContents ifTrue:[ |
|
132 |
self textChanged |
|
133 |
]. |
|
136 | 134 |
^ self |
135 |
] |
|
136 |
]. |
|
137 |
^ super keyPress:key x:x y:y. |
|
138 |
||
139 |
"Modified: 7.3.1996 / 13:16:49 / cg" |
|
140 |
! ! |
|
141 |
||
72 | 142 |
!FilenameEditField methodsFor:'initialization'! |
143 |
||
144 |
initialize |
|
145 |
super initialize. |
|
146 |
directoriesOnly := filesOnly := false. |
|
147 |
directory := '.' asFilename. |
|
148 |
||
78 | 149 |
entryCompletionBlock := [:contents | |
163
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
150 |
|newString| |
78 | 151 |
|
163
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
152 |
newString := Filename |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
153 |
filenameCompletionFor:contents |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
154 |
directory:directory |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
155 |
directoriesOnly:directoriesOnly |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
156 |
filesOnly:filesOnly |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
157 |
ifMultiple:[:dir | |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
158 |
dir asFilename isDirectory ifTrue:[ |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
159 |
self changed:#directory with:dir. |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
160 |
]. |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
161 |
self flash. |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
162 |
]. |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
163 |
self contents:newString. |
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
164 |
self cursorToEndOfLine. |
72 | 165 |
]. |
166 |
||
167 |
"Modified: 7.9.1995 / 10:20:46 / claus" |
|
163
c9235372f589
oops - directoryChange was send even if not a directory
Claus Gittinger <cg@exept.de>
parents:
158
diff
changeset
|
168 |
"Modified: 30.4.1996 / 10:45:38 / cg" |
43 | 169 |
! |
170 |
||
34 | 171 |
realize |
113
984d84d796c8
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
172 |
"move the cursor to the end - thats the most interesting part of |
34 | 173 |
a filename |
174 |
" |
|
175 |
super realize. |
|
176 |
self cursorToEndOfLine. |
|
177 |
! ! |
|
178 |
||
136 | 179 |
!FilenameEditField class methodsFor:'documentation'! |
43 | 180 |
|
136 | 181 |
version |
289 | 182 |
^ '$Header: /cvs/stx/stx/libwidg2/FilenameEditField.st,v 1.23 1997-01-28 11:50:40 ca Exp $' |
34 | 183 |
! ! |