author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 30 Jan 2013 11:15:09 +0000 | |
branch | jv |
changeset 12401 | 4714b9640528 |
parent 12128 | a7ff7d66ee85 |
parent 12117 | d12665ccf213 |
child 12431 | 9f0c59c742d5 |
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 |
||
14 |
ComboBoxView subclass:#FilenameEditFieldV2 |
|
15 |
instanceVariableNames:'directoriesOnly filesOnly directory acceptOnExpand activeMenu |
|
16 |
completitionList' |
|
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Interface-Tools-File' |
|
20 |
! |
|
21 |
||
22 |
!FilenameEditFieldV2 class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
5140 | 26 |
COPYRIGHT (c) 2002 by eXept Software AG |
27 |
All Rights Reserved |
|
4363 | 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 |
" |
|
40 |
like a normal editField, but does filename-completion on the last word of |
|
41 |
the contents, when TAB is pressed. |
|
42 |
Filename completion ignores regular files if directoriesOnly is true, |
|
43 |
and ignores directories, if filesOnly is true. Both default to false. |
|
44 |
||
45 |
[author:] |
|
46 |
Claus Gittinger |
|
47 |
" |
|
48 |
! ! |
|
49 |
||
12401
4714b9640528
Merged 235b77901045 and 8332590c5a41 (branch default)
Jan Vrany <jan.vrany@fit.cvut.cz>
diff
changeset
|
50 |
|
4363 | 51 |
!FilenameEditFieldV2 methodsFor:'accessing'! |
52 |
||
53 |
acceptOnExpand |
|
54 |
"return the autoAccept on filename expansion flag. |
|
55 |
The default is true, which means that an expand accepts" |
|
56 |
||
57 |
^ acceptOnExpand |
|
58 |
! |
|
59 |
||
60 |
acceptOnExpand:aBoolean |
|
61 |
"set/clear autoAccept on filename expansion. |
|
62 |
The default is true, which means that an expand accepts" |
|
63 |
||
64 |
acceptOnExpand := aBoolean |
|
65 |
! |
|
66 |
||
67 |
contents:someText |
|
68 |
"redefined to add a trailing file-separator if the displayed |
|
69 |
filename is a directory" |
|
70 |
||
71 |
^ self |
|
72 |
contents:someText |
|
73 |
addSeparatorToDirectories:true |
|
74 |
! |
|
75 |
||
76 |
contents:someText addSeparatorToDirectories:doAddSeparator |
|
77 |
"optionally add a trailing file-separator if the displayed |
|
78 |
filename is a directory." |
|
79 |
||
80 |
|f n| |
|
81 |
||
82 |
n := someText. |
|
83 |
doAddSeparator ifTrue:[ |
|
84 |
directoriesOnly ifFalse:[ |
|
85 |
someText notNil ifTrue:[ |
|
86 |
f := someText asFilename. |
|
87 |
(f exists and:[f isDirectory]) ifTrue:[ |
|
88 |
(f name endsWith:f separator) ifFalse:[ |
|
89 |
n := f name copyWith:f separator |
|
90 |
] |
|
91 |
] |
|
92 |
]. |
|
93 |
]. |
|
94 |
]. |
|
95 |
super contents:n |
|
96 |
! |
|
97 |
||
98 |
directoriesOnly |
|
99 |
"set to expand names for directories only" |
|
100 |
||
101 |
directoriesOnly := true. |
|
102 |
! |
|
103 |
||
104 |
directory |
|
105 |
^ directory |
|
106 |
||
107 |
"Modified: 7.9.1995 / 10:12:40 / claus" |
|
108 |
! |
|
109 |
||
110 |
directory:aFilename |
|
111 |
aFilename isNil ifTrue:[ |
|
112 |
directory := Filename currentDirectory |
|
113 |
] ifFalse:[ |
|
114 |
directory := aFilename asFilename |
|
115 |
] |
|
116 |
"Modified: 7.9.1995 / 10:12:55 / claus" |
|
117 |
! |
|
118 |
||
119 |
filesOnly |
|
120 |
"set to expand names for files only" |
|
121 |
||
122 |
filesOnly := true. |
|
123 |
! |
|
124 |
||
125 |
initialText:aString selected:aBoolean |
|
126 |
"move the cursor to the end - thats the most interesting part of |
|
127 |
a filename |
|
128 |
" |
|
129 |
||
130 |
super initialText:aString selected:aBoolean. |
|
131 |
self cursorToEndOfLine. |
|
132 |
! |
|
133 |
||
134 |
showsDirectoriesOnly |
|
135 |
"return if expanding names for directories only" |
|
136 |
||
137 |
^ directoriesOnly |
|
138 |
||
139 |
"Modified: 6.9.1995 / 20:35:30 / claus" |
|
140 |
! |
|
141 |
||
142 |
showsFilesOnly |
|
143 |
"return if expanding names for files only" |
|
144 |
||
145 |
^ filesOnly |
|
146 |
||
147 |
"Modified: 6.9.1995 / 20:34:57 / claus" |
|
148 |
! ! |
|
149 |
||
12401
4714b9640528
Merged 235b77901045 and 8332590c5a41 (branch default)
Jan Vrany <jan.vrany@fit.cvut.cz>
diff
changeset
|
150 |
|
4363 | 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 |
|
6446 | 209 |
"move the cursor to the end - thats the most interesting part of a filename |
4363 | 210 |
" |
211 |
super realize. |
|
6446 | 212 |
self editor cursorToEndOfLine. |
4363 | 213 |
|
214 |
"Created: 24.7.1997 / 18:21:51 / cg" |
|
215 |
! ! |
|
216 |
||
12401
4714b9640528
Merged 235b77901045 and 8332590c5a41 (branch default)
Jan Vrany <jan.vrany@fit.cvut.cz>
diff
changeset
|
217 |
|
4363 | 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 |
||
257 |
origin := device translatePoint:(0 @ self height) fromView:self toView:nil. |
|
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 |
||
12401
4714b9640528
Merged 235b77901045 and 8332590c5a41 (branch default)
Jan Vrany <jan.vrany@fit.cvut.cz>
diff
changeset
|
280 |
|
4363 | 281 |
!FilenameEditFieldV2 class methodsFor:'documentation'! |
282 |
||
283 |
version |
|
12117 | 284 |
^ '$Header: /cvs/stx/stx/libtool/FilenameEditFieldV2.st,v 1.14 2013-01-17 11:18:19 cg Exp $' |
12128
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
285 |
! |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
286 |
|
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
287 |
version_SVN |
a7ff7d66ee85
Improvements in LintHighlighter, few fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
12125
diff
changeset
|
288 |
^ '$Id: FilenameEditFieldV2.st 7854 2012-01-30 17:49:41Z vranyj1 $' |
4363 | 289 |
! ! |
12117 | 290 |