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