author | Jan Vrany <jan.vrany@labware.com> |
Thu, 06 May 2021 09:04:23 +0100 | |
branch | jv |
changeset 19599 | b49de95fc5a5 |
parent 18532 | cccb41254edf |
permissions | -rw-r--r-- |
4363 | 1 |
" |
5140 | 2 |
COPYRIGHT (c) 2002 by eXept Software AG |
3 |
All Rights Reserved |
|
4363 | 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 |
"{ Package: 'stx:libtool' }" |
|
13 |
||
16862 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
4363 | 16 |
ComboBoxView subclass:#FilenameEditFieldV2 |
17 |
instanceVariableNames:'directoriesOnly filesOnly directory acceptOnExpand activeMenu |
|
18 |
completitionList' |
|
19 |
classVariableNames:'' |
|
20 |
poolDictionaries:'' |
|
21 |
category:'Interface-Tools-File' |
|
22 |
! |
|
23 |
||
24 |
!FilenameEditFieldV2 class methodsFor:'documentation'! |
|
25 |
||
26 |
copyright |
|
27 |
" |
|
5140 | 28 |
COPYRIGHT (c) 2002 by eXept Software AG |
29 |
All Rights Reserved |
|
4363 | 30 |
|
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
like a normal editField, but does filename-completion on the last word of |
|
43 |
the contents, when TAB is pressed. |
|
44 |
Filename completion ignores regular files if directoriesOnly is true, |
|
45 |
and ignores directories, if filesOnly is true. Both default to false. |
|
46 |
||
47 |
[author:] |
|
48 |
Claus Gittinger |
|
49 |
" |
|
50 |
! ! |
|
51 |
||
52 |
!FilenameEditFieldV2 methodsFor:'accessing'! |
|
53 |
||
54 |
acceptOnExpand |
|
55 |
"return the autoAccept on filename expansion flag. |
|
56 |
The default is true, which means that an expand accepts" |
|
57 |
||
58 |
^ acceptOnExpand |
|
59 |
! |
|
60 |
||
61 |
acceptOnExpand:aBoolean |
|
62 |
"set/clear autoAccept on filename expansion. |
|
63 |
The default is true, which means that an expand accepts" |
|
64 |
||
65 |
acceptOnExpand := aBoolean |
|
66 |
! |
|
67 |
||
68 |
contents:someText |
|
69 |
"redefined to add a trailing file-separator if the displayed |
|
70 |
filename is a directory" |
|
71 |
||
72 |
^ self |
|
73 |
contents:someText |
|
74 |
addSeparatorToDirectories:true |
|
75 |
! |
|
76 |
||
77 |
contents:someText addSeparatorToDirectories:doAddSeparator |
|
78 |
"optionally add a trailing file-separator if the displayed |
|
79 |
filename is a directory." |
|
80 |
||
81 |
|f n| |
|
82 |
||
83 |
n := someText. |
|
84 |
doAddSeparator ifTrue:[ |
|
85 |
directoriesOnly ifFalse:[ |
|
86 |
someText notNil ifTrue:[ |
|
87 |
f := someText asFilename. |
|
88 |
(f exists and:[f isDirectory]) ifTrue:[ |
|
89 |
(f name endsWith:f separator) ifFalse:[ |
|
90 |
n := f name copyWith:f separator |
|
91 |
] |
|
92 |
] |
|
93 |
]. |
|
94 |
]. |
|
95 |
]. |
|
96 |
super contents:n |
|
97 |
! |
|
98 |
||
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 |
|
112 |
aFilename isNil ifTrue:[ |
|
113 |
directory := Filename currentDirectory |
|
114 |
] ifFalse:[ |
|
115 |
directory := aFilename asFilename |
|
116 |
] |
|
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 |
|
16862 | 127 |
"redefined to move the cursor to the end |
128 |
- that's the most interesting part of a filename |
|
4363 | 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 |
!FilenameEditFieldV2 methodsFor:'initialization'! |
|
152 |
||
153 |
initialize |
|
4743 | 154 |
|myEditor| |
155 |
||
4363 | 156 |
super initialize. |
157 |
||
158 |
acceptOnExpand := true. |
|
159 |
directoriesOnly := filesOnly := false. |
|
160 |
directory := Filename currentDirectory. |
|
161 |
"/ self menuButton visibilityChannel:(false asValue). |
|
4743 | 162 |
myEditor := self editor. |
163 |
||
164 |
myEditor entryCompletionBlock: [:contents | |
|
4363 | 165 |
|newString isMultiMatch canonContents| |
166 |
||
167 |
isMultiMatch := false. |
|
168 |
canonContents := Filename canonicalize:contents. |
|
169 |
newString := Filename |
|
170 |
filenameCompletionFor:canonContents |
|
171 |
directory:directory |
|
172 |
directoriesOnly:directoriesOnly |
|
173 |
filesOnly:filesOnly |
|
174 |
ifMultiple:[:dir | ] |
|
4373 | 175 |
forMultipleDo:[:dir :matchSet | |
176 |
matchSet notEmpty ifTrue:[ |
|
4743 | 177 |
myEditor contents:dir name. |
4373 | 178 |
completitionList := matchSet asList. |
179 |
self action:[: string | | newFile | |
|
4530
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
180 |
string isString ifTrue:[ |
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
181 |
newFile := string asFilename. |
5012
47e675b8c9fe
removed unused keyPress method
Claus Gittinger <cg@exept.de>
parents:
4743
diff
changeset
|
182 |
(newFile exists and:[newFile isDirectory]) ifTrue:[ |
47e675b8c9fe
removed unused keyPress method
Claus Gittinger <cg@exept.de>
parents:
4743
diff
changeset
|
183 |
(newFile name endsWith:newFile separator) ifFalse:[ |
47e675b8c9fe
removed unused keyPress method
Claus Gittinger <cg@exept.de>
parents:
4743
diff
changeset
|
184 |
myEditor contents:(newFile name copyWith:newFile separator) |
47e675b8c9fe
removed unused keyPress method
Claus Gittinger <cg@exept.de>
parents:
4743
diff
changeset
|
185 |
]. |
4530
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
186 |
]. |
d44a82caf67e
error on enter in ComboBoxList gets the items from the upper menues
penk
parents:
4373
diff
changeset
|
187 |
] |
4363 | 188 |
]. |
4373 | 189 |
self pullMenu. |
190 |
completitionList := nil. |
|
191 |
isMultiMatch := true. |
|
4363 | 192 |
]. |
193 |
]. |
|
6250
5b0673ccff1c
refactored intention revealing code:
Claus Gittinger <cg@exept.de>
parents:
6128
diff
changeset
|
194 |
isMultiMatch ifFalse:[ |
4363 | 195 |
newString asFilename pathName = canonContents ifTrue:[ |
196 |
[self flash] fork. |
|
197 |
]. |
|
198 |
||
199 |
self contents:newString addSeparatorToDirectories:isMultiMatch not. |
|
6446 | 200 |
myEditor cursorToEndOfLine. |
4363 | 201 |
] |
202 |
]. |
|
203 |
||
204 |
"Modified: 7.9.1995 / 10:20:46 / claus" |
|
205 |
"Modified: 7.9.1997 / 23:51:47 / cg" |
|
206 |
! |
|
207 |
||
208 |
realize |
|
16862 | 209 |
"redefined to move the cursor to the end |
210 |
- that's the most interesting part of a filename |
|
4363 | 211 |
" |
212 |
super realize. |
|
6446 | 213 |
self editor cursorToEndOfLine. |
4363 | 214 |
|
215 |
"Created: 24.7.1997 / 18:21:51 / cg" |
|
216 |
! ! |
|
217 |
||
218 |
!FilenameEditFieldV2 methodsFor:'menu'! |
|
219 |
||
220 |
processEvent:anEvent |
|
6128 | 221 |
"catch keyEvents in pulled menu (see redefined pullMenu-method). |
222 |
Return true, if I have eaten the event" |
|
223 |
||
12117 | 224 |
<resource: #keyboard (#BackSpace )> |
225 |
||
4363 | 226 |
activeMenu notNil ifTrue:[ |
227 |
anEvent isKeyPressEvent ifTrue:[ |
|
8798
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
228 |
"/ typing into the pulled menu behaves like typing into the field |
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
229 |
"/ followed by a TAB (to reopen the menu) |
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
230 |
(anEvent key isCharacter |
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
231 |
or:[ anEvent key == #BackSpace]) ifTrue:[ |
4363 | 232 |
"/ activeMenu windowGroup removePreEventHook:self. |
8798
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
233 |
field dispatchEvent:anEvent. |
4363 | 234 |
|
235 |
WindowGroup leaveSignal raiseRequest. |
|
236 |
self error:'should not be reached'. |
|
8798
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
237 |
]. |
4363 | 238 |
]. |
239 |
]. |
|
240 |
^ false. |
|
241 |
! |
|
242 |
||
243 |
pullMenu |
|
244 |
"pull the menu - triggered from the button" |
|
245 |
||
6104
8159f0753b92
no acceptOnLostFocus for editfield while menue is open
penk
parents:
5140
diff
changeset
|
246 |
|menu origin plug acceptOnLostFocus| |
4363 | 247 |
|
248 |
completitionList notNil ifTrue:[ |
|
249 |
self list:completitionList |
|
250 |
] ifFalse:[ |
|
251 |
self list:(listHolder value collect:[:el| el path]). |
|
252 |
]. |
|
253 |
menu := self createPullDownMenuForList:list. |
|
254 |
||
255 |
menu backgroundColor:self editor backgroundColor. |
|
256 |
||
13956 | 257 |
origin := self graphicsDevice translatePoint:(0 @ self height) fromView:self toView:nil. |
4363 | 258 |
|
259 |
"/ need a callBack when the menu becomes visible, to add an eventHook to |
|
260 |
"/ its windowGroup. |
|
261 |
"/ cannot do this here, since the windowgroup is created later and there is no other |
|
262 |
"/ callback or hook from modal views. |
|
263 |
||
264 |
menu addDependent:(plug := Plug new |
|
265 |
respondTo:#'update:with:from:' |
|
266 |
with:[:a :b :c | menu windowGroup notNil |
|
267 |
ifTrue:[menu windowGroup addPreEventHook:self]. |
|
268 |
menu removeDependent:plug]). |
|
269 |
activeMenu := menu. |
|
6104
8159f0753b92
no acceptOnLostFocus for editfield while menue is open
penk
parents:
5140
diff
changeset
|
270 |
"prevent editfield from acceptOnLostFocus events so no accept happen while menue is open" |
8159f0753b92
no acceptOnLostFocus for editfield while menue is open
penk
parents:
5140
diff
changeset
|
271 |
acceptOnLostFocus := field acceptOnLostFocus. |
8159f0753b92
no acceptOnLostFocus for editfield while menue is open
penk
parents:
5140
diff
changeset
|
272 |
field acceptOnLostFocus:false. |
8798
7c48ce02da90
added: #handlesKeyPress:inView:
Claus Gittinger <cg@exept.de>
parents:
6446
diff
changeset
|
273 |
menu sensor addEventListener:self. |
4363 | 274 |
menu showAt:origin. |
6104
8159f0753b92
no acceptOnLostFocus for editfield while menue is open
penk
parents:
5140
diff
changeset
|
275 |
field acceptOnLostFocus:acceptOnLostFocus. |
4363 | 276 |
activeMenu := nil. |
277 |
pullDownButton turnOff. |
|
278 |
! ! |
|
279 |
||
280 |
!FilenameEditFieldV2 class methodsFor:'documentation'! |
|
281 |
||
282 |
version |
|
16862 | 283 |
^ '$Header$' |
4363 | 284 |
! ! |
12117 | 285 |