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