author | Claus Gittinger <cg@exept.de> |
Mon, 20 Jan 2020 21:02:47 +0100 | |
changeset 19422 | c6ca1c3e0fd7 |
parent 19266 | 9c289c27acf7 |
permissions | -rw-r--r-- |
5139 | 1 |
" |
2 |
COPYRIGHT (c) 2003 by eXept Software AG |
|
3 |
All Rights Reserved |
|
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 |
" |
|
4712 | 12 |
"{ Package: 'stx:libtool' }" |
13 |
||
16912 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
4712 | 16 |
AbstractFileBrowser subclass:#AbstractDirectoryBrowser |
17 |
instanceVariableNames:'inDropMode canDropItem browser updateToExternFileHolderLock' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Interface-Tools-File' |
|
21 |
! |
|
22 |
||
23 |
!AbstractDirectoryBrowser class methodsFor:'documentation'! |
|
24 |
||
5139 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 2003 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
4712 | 39 |
documentation |
40 |
" |
|
41 |
Abstract class containing the common code from DirectoryTreeBrowser and |
|
42 |
DirectoryContentsBrowser applications. |
|
5967 | 43 |
|
44 |
[Author:] |
|
45 |
Christian Penk |
|
4712 | 46 |
" |
47 |
! ! |
|
48 |
||
17289 | 49 |
!AbstractDirectoryBrowser class methodsFor:'queries'! |
50 |
||
51 |
isAbstract |
|
52 |
^ self == AbstractDirectoryBrowser |
|
53 |
! ! |
|
54 |
||
4712 | 55 |
!AbstractDirectoryBrowser methodsFor:'accessing'! |
56 |
||
18281 | 57 |
directory |
58 |
^ self subclassResponsibility |
|
59 |
||
60 |
"Created: / 23-07-2018 / 12:49:38 / Stefan Vogel" |
|
61 |
! |
|
62 |
||
19011 | 63 |
fileList |
64 |
self subclassResponsibility |
|
65 |
! |
|
66 |
||
4712 | 67 |
updateToExternFileHolderLock |
68 |
updateToExternFileHolderLock isNil ifTrue:[ |
|
69 |
updateToExternFileHolderLock := self class newLock. |
|
70 |
]. |
|
71 |
^ updateToExternFileHolderLock |
|
72 |
! ! |
|
73 |
||
18270 | 74 |
!AbstractDirectoryBrowser methodsFor:'actions'! |
75 |
||
76 |
findFilesMatching:aGLOBPattern |
|
18750 | 77 |
"search files which match aGLOBPattern. |
78 |
If a folder is selected, the search starts there; |
|
79 |
otherwise in the top folder" |
|
80 |
||
81 |
|selItem searchDir| |
|
82 |
||
83 |
(selItem := self theSingleSelectedItemOrNil) notNil ifTrue:[ |
|
84 |
selItem isDirectory ifTrue:[ |
|
85 |
searchDir := selItem pathName |
|
86 |
] ifFalse:[ |
|
87 |
searchDir := selItem pathName asFilename directory |
|
88 |
]. |
|
89 |
] ifFalse:[ |
|
90 |
searchDir := self directory |
|
91 |
]. |
|
92 |
^ self findFilesMatching:aGLOBPattern in:searchDir |
|
93 |
||
94 |
"Created: / 17-07-2018 / 12:53:32 / Claus Gittinger" |
|
95 |
"Modified: / 02-05-2019 / 20:41:57 / Claus Gittinger" |
|
96 |
! |
|
97 |
||
98 |
findFilesMatching:aGLOBPattern in:searchDir |
|
99 |
"search files which match aGLOBPattern." |
|
100 |
||
18270 | 101 |
|matching| |
102 |
||
103 |
matching := OrderedCollection new. |
|
18750 | 104 |
searchDir asFilename recursiveDirectoryContentsAsFilenamesDo:[:each | |
18270 | 105 |
(aGLOBPattern match:each baseName) ifTrue:[ |
106 |
matching add:each |
|
107 |
]. |
|
108 |
]. |
|
109 |
^ matching |
|
110 |
||
18750 | 111 |
"Created: / 02-05-2019 / 18:58:30 / Claus Gittinger" |
18270 | 112 |
! ! |
113 |
||
4712 | 114 |
!AbstractDirectoryBrowser methodsFor:'drag & drop'! |
115 |
||
7402 | 116 |
canDrop:aDropContext |
4712 | 117 |
^ inDropMode and:[canDropItem] |
7402 | 118 |
|
119 |
"Modified: / 13-10-2006 / 11:35:09 / cg" |
|
4712 | 120 |
! |
121 |
||
4745 | 122 |
doDrop:aContext |
123 |
|col destinationPath receiver didDrop| |
|
124 |
||
4754
e8ff80bb18ea
oops - dropLeave has a side effect.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
125 |
destinationPath := self dropDestinationPath. |
e8ff80bb18ea
oops - dropLeave has a side effect.
Claus Gittinger <cg@exept.de>
parents:
4745
diff
changeset
|
126 |
|
4745 | 127 |
self dropLeave:aContext. |
128 |
||
7586 | 129 |
destinationPath isNil ifTrue:[^ self]. |
4745 | 130 |
|
131 |
aContext dropSource argument == #archivApplication ifTrue:[ |
|
132 |
receiver := aContext dropSource receiver. |
|
133 |
receiver extractSelectedFilesTo:destinationPath askForExtractOptions:true. |
|
134 |
^ self |
|
135 |
]. |
|
136 |
||
9362 | 137 |
self withWaitCursorDo:[ |
17866 | 138 |
col := aContext dropObjects collect:#theObject. |
9362 | 139 |
didDrop := self copyOrMoveFiles:col to:destinationPath. |
140 |
didDrop ifFalse:[ |
|
141 |
aContext clearHasDroppedFlagToSuppressFeedBack |
|
142 |
]. |
|
143 |
] |
|
4745 | 144 |
! |
145 |
||
5335 | 146 |
dropDestinationPath |
147 |
self subclassResponsibility |
|
148 |
! |
|
149 |
||
4712 | 150 |
dropEnter:aContext |
6377 | 151 |
|dropObjects| |
4712 | 152 |
|
153 |
self dropTargetItemChangedTo:nil in:aContext. |
|
154 |
inDropMode := false. |
|
155 |
||
156 |
"/ self directory isNil ifTrue:[^ self]. |
|
6377 | 157 |
dropObjects := aContext dropObjects. |
4712 | 158 |
|
17754 | 159 |
dropObjects do:[:eachDropObject| |
15042
f002aba0f9c9
class: AbstractDirectoryBrowser
Claus Gittinger <cg@exept.de>
parents:
12873
diff
changeset
|
160 |
|checkObject| |
4712 | 161 |
|
17754 | 162 |
eachDropObject isFileObject ifFalse:[^ self]. |
4712 | 163 |
|
17754 | 164 |
checkObject := eachDropObject theObject. |
6250
5b0673ccff1c
refactored intention revealing code:
Claus Gittinger <cg@exept.de>
parents:
5967
diff
changeset
|
165 |
checkObject isFilename ifFalse:[^ self]. |
5b0673ccff1c
refactored intention revealing code:
Claus Gittinger <cg@exept.de>
parents:
5967
diff
changeset
|
166 |
(aContext dropSource argument == #archivApplication) ifFalse:[ |
4712 | 167 |
checkObject isSpecialFile ifTrue:[^ self]. |
168 |
checkObject isReadable ifFalse:[^ self]. |
|
169 |
]. |
|
170 |
]. |
|
171 |
inDropMode := true. |
|
17754 | 172 |
|
173 |
"Modified (format): / 15-11-2017 / 11:10:16 / cg" |
|
4712 | 174 |
! |
175 |
||
176 |
dropLeave:aDropContext |
|
9328 | 177 |
"called, when leaving the widget" |
178 |
||
4712 | 179 |
inDropMode ifFalse:[ ^ self ]. |
180 |
||
181 |
self dropTargetItemChangedTo:nil in:aDropContext. |
|
182 |
self removeExpandItemTimedBlock. |
|
183 |
inDropMode := false. |
|
184 |
! |
|
185 |
||
5330 | 186 |
dropTargetItemChangedTo:anItem in:aContext |
187 |
||
188 |
self subclassResponsibility |
|
189 |
! |
|
190 |
||
4712 | 191 |
getDropObjects:anArgument |
192 |
||
193 |
^ self selectedFiles collect:[:file| DropObject newFile:file]. |
|
194 |
! |
|
195 |
||
196 |
getLineNumberFor:aDropContext |
|
197 |
| yVisible| |
|
198 |
||
18214 | 199 |
yVisible := (aDropContext targetPointInDeviceCoordinates y). |
4712 | 200 |
^ browser yVisibleToRowNr:yVisible. |
18214 | 201 |
|
202 |
"Modified: / 15-06-2018 / 02:32:03 / Claus Gittinger" |
|
4712 | 203 |
! |
204 |
||
4802 | 205 |
pushUserEvent:selector withArgument:argument |
206 |
self window sensor |
|
207 |
pushUserEvent:selector |
|
208 |
for:self |
|
209 |
withArgument:argument |
|
5796 | 210 |
! |
211 |
||
212 |
removeExpandItemTimedBlock |
|
213 |
"left blank" |
|
4712 | 214 |
! ! |
215 |
||
216 |
!AbstractDirectoryBrowser methodsFor:'file actions'! |
|
217 |
||
218 |
doCopy |
|
6286 | 219 |
"copy the selected files/directories to the clipBoard" |
4712 | 220 |
|
221 |
self copyFilesToClipBoard:(self selectedFiles). |
|
222 |
! |
|
223 |
||
224 |
doCut |
|
6286 | 225 |
"cut the selected files/directories to the clipBoard" |
4712 | 226 |
|
227 |
self cutFilesToClipBoard:(self selectedFiles). |
|
228 |
! |
|
229 |
||
230 |
doDelete |
|
6286 | 231 |
"delete the selected files/directories" |
5967 | 232 |
|
4742
972a9d30ec47
enumerate copies of the selection in delete & rename
Claus Gittinger <cg@exept.de>
parents:
4712
diff
changeset
|
233 |
self deleteFiles:(self selectedFiles copy). |
6286 | 234 |
! |
235 |
||
236 |
doErase |
|
237 |
"erase the selected files" |
|
238 |
||
239 |
self eraseFiles:(self selectedFiles copy). |
|
18270 | 240 |
! |
241 |
||
242 |
findAndSelectFilesMatching:aGLOBPattern |
|
243 |
self selectFiles:(self findFilesMatching:aGLOBPattern). |
|
244 |
||
245 |
"Created: / 17-07-2018 / 12:48:23 / Claus Gittinger" |
|
18750 | 246 |
! |
247 |
||
248 |
findAndSelectNextFileMatching:aGLOBPattern |
|
19011 | 249 |
self |
250 |
findAndSelectNextFileMatching:aGLOBPattern |
|
251 |
under:(self theSingleSelectedItemOrNil ? self fileList root) |
|
252 |
searchInfoInto:nil |
|
253 |
! |
|
254 |
||
255 |
findAndSelectNextFileMatching:aGLOBPattern under:topDirectoryItem |
|
256 |
self findAndSelectNextFileMatching:aGLOBPattern under:topDirectoryItem searchInfoInto:nil |
|
257 |
! |
|
258 |
||
259 |
findAndSelectNextFileMatching:aGLOBPattern under:topDirectoryItem searchInfoInto:aBlockOrNil |
|
18750 | 260 |
|fileOrNil| |
261 |
||
19011 | 262 |
fileOrNil := self findNextFileMatching:aGLOBPattern startingAt:topDirectoryItem searchInfoInto:aBlockOrNil. |
18750 | 263 |
self selectFiles:(fileOrNil isNil |
264 |
ifTrue:[#()] |
|
265 |
ifFalse:[{ fileOrNil }]) |
|
266 |
||
267 |
"Created: / 02-05-2019 / 20:43:41 / Claus Gittinger" |
|
19011 | 268 |
! |
269 |
||
270 |
findNextFileMatching:aGLOBPattern startingAt:anItemOrNil |
|
271 |
"search files which match aGLOBPattern in the tree." |
|
272 |
||
273 |
^ self findNextFileMatching:aGLOBPattern startingAt:anItemOrNil searchInfoInto:nil |
|
274 |
||
275 |
"Created: / 02-05-2019 / 20:39:58 / Claus Gittinger" |
|
276 |
! |
|
277 |
||
278 |
findNextFileMatching:aGLOBPattern startingAt:anItemOrNil searchInfoInto:aBlockOrNil |
|
279 |
"search files which match aGLOBPattern in the tree. |
|
280 |
If not nil, aBlockOrNil is called whenever a new folder is searched (for visual feeedback)" |
|
281 |
||
282 |
|searchFolder searchIndex stack| |
|
283 |
||
284 |
stack := OrderedCollection new. |
|
285 |
anItemOrNil isRootItem ifFalse:[ |
|
286 |
|i| |
|
287 |
||
288 |
i := anItemOrNil. |
|
289 |
[i isRootItem] whileFalse:[ |
|
290 |
stack addFirst:(i parent -> (i parent children indexOf:i)). |
|
291 |
i := i parent. |
|
292 |
]. |
|
293 |
]. |
|
294 |
||
295 |
anItemOrNil isDirectory ifTrue:[ |
|
296 |
searchFolder := anItemOrNil. |
|
297 |
searchIndex := 0. |
|
298 |
] ifFalse:[ |
|
299 |
searchFolder := anItemOrNil parent. |
|
300 |
searchIndex := anItemOrNil parent children indexOf:anItemOrNil. |
|
301 |
]. |
|
302 |
||
303 |
stack add:(searchFolder -> searchIndex). |
|
304 |
||
305 |
[stack notEmpty] whileTrue:[ |
|
306 |
|work children| |
|
307 |
||
308 |
work := stack removeLast. |
|
309 |
searchFolder := work key. |
|
310 |
searchIndex := work value. |
|
311 |
||
19266 | 312 |
"/ (searchFolder pathName startsWith:'/Appl') ifTrue:[self halt]. |
19011 | 313 |
|
314 |
aBlockOrNil notNil ifTrue:[aBlockOrNil value:searchFolder pathName]. |
|
315 |
||
316 |
children := searchFolder children. |
|
317 |
searchIndex+1 to:(children size) doWithExit:[:childIndex :exit| |
|
318 |
|child fn| |
|
319 |
||
320 |
child := children at:childIndex. |
|
321 |
Transcript showCR:'search %1' with:child pathName. |
|
322 |
fn := child fileName. |
|
323 |
fn isSymbolicLink ifFalse:[ |
|
324 |
fn isDirectory ifFalse:[ |
|
325 |
(aGLOBPattern match:fn baseName) ifTrue:[ |
|
326 |
^ fn pathName asFilename |
|
327 |
]. |
|
328 |
] ifTrue:[ |
|
329 |
"/ deeper, but remember to proceed here |
|
330 |
stack add:(searchFolder -> childIndex). |
|
331 |
stack add:(child -> 0). |
|
332 |
exit value:nil. |
|
333 |
] |
|
334 |
] |
|
335 |
]. |
|
336 |
]. |
|
337 |
^ nil |
|
338 |
||
339 |
"Created: / 02-05-2019 / 20:39:58 / Claus Gittinger" |
|
4712 | 340 |
! ! |
341 |
||
342 |
!AbstractDirectoryBrowser methodsFor:'selection'! |
|
343 |
||
344 |
selectedFiles |
|
345 |
||
17866 | 346 |
^ self selectedItems collect:#fileName. |
4712 | 347 |
! ! |
348 |
||
349 |
!AbstractDirectoryBrowser methodsFor:'startup & release'! |
|
350 |
||
351 |
initialize |
|
352 |
||
353 |
inDropMode := false. |
|
354 |
^ super initialize. |
|
355 |
! |
|
356 |
||
12873
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
357 |
postOpenAsSubcanvasWith:aBuilder |
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
358 |
"this is sent after the applications window is opened inside another application. |
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
359 |
Can be redefined in subclasses for actions after showing the canvas view." |
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
360 |
|
18142 | 361 |
"/ cg: used to be unconditionally true here; |
12873
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
362 |
"/ but then, when a FileDialog (which is not an AbstractFileBrowser) is opened, |
16912 | 363 |
"/ the commonPostBuild will not properly update its enable channels; |
12873
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
364 |
"/ especially the enableDirectoryUp is false. |
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
365 |
"/ This whole FileBrowser is so complicated that it became almost unusable. |
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
366 |
"/ (too much inheritance and knowledge - DirTree and DirContents should each only do |
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
367 |
"/ what it should and not depend on shared functionality from their superclass) |
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
368 |
self postOpenFromMaster:(self masterApplication class includesBehavior:AbstractFileBrowser). |
18142 | 369 |
|
370 |
"Modified (comment): / 22-05-2018 / 18:48:22 / Claus Gittinger" |
|
12873
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
371 |
! |
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
372 |
|
5444 | 373 |
postOpenFromMaster:fromMaster |
5442 | 374 |
self subclassResponsibility |
4712 | 375 |
! |
376 |
||
12873
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
377 |
postOpenWith:aBuilder |
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
378 |
"this is sent after the applications main window is opened. |
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
379 |
Can be redefined in subclasses for actions after opening the view." |
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
380 |
|
17578 | 381 |
super postOpenWith:aBuilder. |
12873
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
382 |
self postOpenFromMaster:false. |
17578 | 383 |
|
384 |
"Modified: / 16-07-2017 / 12:19:48 / cg" |
|
12873
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
385 |
! |
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
386 |
|
4712 | 387 |
preBuildWith:aBuilder |
388 |
||
389 |
self masterApplication isNil ifTrue:[ |
|
390 |
self masterApplication:nil. |
|
391 |
]. |
|
392 |
^ super preBuildWith:aBuilder. |
|
393 |
! ! |
|
394 |
||
395 |
!AbstractDirectoryBrowser class methodsFor:'documentation'! |
|
396 |
||
397 |
version |
|
16912 | 398 |
^ '$Header$' |
9328 | 399 |
! |
400 |
||
401 |
version_CVS |
|
16912 | 402 |
^ '$Header$' |
4712 | 403 |
! ! |
12873
0bf1fc08cfd1
oops - startup did not enable directoryUp
Claus Gittinger <cg@exept.de>
parents:
9362
diff
changeset
|
404 |