author | Michael Beyl <mb@exept.de> |
Tue, 05 Nov 2002 12:02:59 +0100 | |
changeset 4182 | 99ed9aed9fa7 |
parent 4168 | 8b7555e00ee3 |
child 4336 | b4228ddf2183 |
permissions | -rw-r--r-- |
3892 | 1 |
"{ Package: 'stx:libtool' }" |
2 |
||
3 |
AbstractFileApplicationNoteBookComponent subclass:#FindFileApplication |
|
4 |
instanceVariableNames:'contentsPatternHolder ignoreCaseInName notSearchForSameContents |
|
5 |
namePatternHolder ignoreCaseInContents searchDirectoryHolder |
|
6 |
findFileView searchResultTable resultList enableStop enableSearch |
|
7 |
stopSignal accessLock searchTask expanded searchRecursively |
|
4101 | 8 |
selectionHolder hasListEntries targetApplication' |
3892 | 9 |
classVariableNames:'' |
10 |
poolDictionaries:'' |
|
11 |
category:'Interface-Tools-File' |
|
12 |
! |
|
13 |
||
14 |
||
15 |
!FindFileApplication class methodsFor:'instance creation'! |
|
16 |
||
17 |
open |
|
18 |
||
19 |
^ self openOnFileName:(Filename currentDirectory asAbsoluteFilename) |
|
20 |
! |
|
21 |
||
22 |
openOnFileName:aFileName |
|
23 |
||
24 |
| instance builder| |
|
25 |
||
26 |
builder := super open. |
|
27 |
instance := builder application. |
|
3983 | 28 |
instance item:(DirectoryContentsBrowser itemClass fileName:aFileName). |
3892 | 29 |
^ builder |
30 |
! |
|
31 |
||
32 |
openOnFileName:aFileName for:aTargetApplication |
|
33 |
||
34 |
| instance builder| |
|
35 |
||
36 |
builder := super open. |
|
37 |
instance := builder application. |
|
3983 | 38 |
instance item:(DirectoryContentsBrowser itemClass fileName:aFileName). |
4101 | 39 |
instance targetApplication:aTargetApplication. |
3892 | 40 |
^ builder |
41 |
! ! |
|
42 |
||
43 |
!FindFileApplication class methodsFor:'defaults'! |
|
44 |
||
45 |
tabStringFor:aApplicationType |
|
46 |
||
47 |
^ 'Find file in:' |
|
48 |
! ! |
|
49 |
||
50 |
!FindFileApplication class methodsFor:'interface specs'! |
|
51 |
||
52 |
windowSpec |
|
53 |
"This resource specification was automatically generated |
|
54 |
by the UIPainter of ST/X." |
|
55 |
||
56 |
"Do not manually edit this!! If it is corrupted, |
|
57 |
the UIPainter may not be able to read the specification." |
|
58 |
||
59 |
" |
|
60 |
UIPainter new openOnClass:FindFileApplication andSelector:#windowSpec |
|
61 |
FindFileApplication new openInterface:#windowSpec |
|
62 |
FindFileApplication open |
|
63 |
" |
|
64 |
||
65 |
<resource: #canvas> |
|
66 |
||
67 |
^ |
|
68 |
#(#FullSpec |
|
69 |
#name: #windowSpec |
|
70 |
#window: |
|
71 |
#(#WindowSpec |
|
72 |
#label: 'File Search' |
|
73 |
#name: 'File Search' |
|
74 |
#min: #(#Point 377 131) |
|
75 |
#max: #(#Point 1280 1024) |
|
76 |
#bounds: #(#Rectangle 16 42 681 374) |
|
77 |
) |
|
78 |
#component: |
|
79 |
#(#SpecCollection |
|
80 |
#collection: #( |
|
81 |
#(#MenuPanelSpec |
|
82 |
#name: 'ToolBar1' |
|
83 |
#layout: #(#LayoutFrame 0 0.0 0 0 0 1.0 32 0) |
|
84 |
#menu: #searchMenu |
|
85 |
#textDefault: true |
|
86 |
) |
|
87 |
#(#ViewSpec |
|
88 |
#name: 'Box1' |
|
89 |
#layout: #(#LayoutFrame 0 0.0 32 0 0 1.0 126 0) |
|
90 |
#component: |
|
91 |
#(#SpecCollection |
|
92 |
#collection: #( |
|
93 |
#(#LabelSpec |
|
94 |
#label: 'Search files named:' |
|
95 |
#name: 'Label1' |
|
96 |
#layout: #(#LayoutFrame 3 0 7 0 148 0 24 0) |
|
97 |
#translateLabel: true |
|
98 |
#adjust: #left |
|
99 |
) |
|
100 |
#(#InputFieldSpec |
|
101 |
#name: 'EntryField1' |
|
102 |
#layout: #(#LayoutFrame 140 0 4 0 -115 1 24 0) |
|
103 |
#tabable: true |
|
104 |
#model: #namePatternHolder |
|
105 |
#immediateAccept: true |
|
106 |
#acceptOnLeave: false |
|
107 |
#acceptOnPointerLeave: false |
|
108 |
) |
|
109 |
#(#CheckBoxSpec |
|
110 |
#label: 'Ignore case' |
|
111 |
#name: 'CheckBox1' |
|
112 |
#layout: #(#LayoutFrame -97 1 5 0 1 1 28 0) |
|
113 |
#tabable: true |
|
114 |
#model: #ignoreCaseInName |
|
115 |
#translateLabel: true |
|
116 |
) |
|
117 |
#(#LabelSpec |
|
118 |
#label: 'Containing the string:' |
|
119 |
#name: 'Label2' |
|
120 |
#layout: #(#LayoutFrame 4 0 31 0 136 0 48 0) |
|
121 |
#translateLabel: true |
|
122 |
#adjust: #left |
|
123 |
) |
|
124 |
#(#InputFieldSpec |
|
125 |
#name: 'EntryField2' |
|
126 |
#layout: #(#LayoutFrame 140 0 29 0 -115 1 49 0) |
|
127 |
#enableChannel: #notSearchForSameContents |
|
128 |
#tabable: true |
|
129 |
#model: #contentsPatternHolder |
|
130 |
#immediateAccept: true |
|
131 |
#acceptOnPointerLeave: false |
|
132 |
) |
|
133 |
#(#CheckBoxSpec |
|
134 |
#label: 'Ignore case' |
|
135 |
#name: 'CheckBox2' |
|
136 |
#layout: #(#LayoutFrame -97 1 30 0 4 1 50 0) |
|
137 |
#enableChannel: #notSearchForSameContents |
|
138 |
#tabable: true |
|
139 |
#model: #ignoreCaseInContents |
|
140 |
#translateLabel: true |
|
141 |
) |
|
142 |
#(#LabelSpec |
|
143 |
#label: 'Directory:' |
|
144 |
#name: 'Directory' |
|
145 |
#layout: #(#LayoutFrame 4 0 57 0 136 0 74 0) |
|
146 |
#translateLabel: true |
|
147 |
#adjust: #left |
|
148 |
) |
|
149 |
#(#FilenameInputFieldSpec |
|
150 |
#name: 'FilenameEntryField1' |
|
151 |
#layout: #(#LayoutFrame 140 0 54 0 -115 1 74 0) |
|
152 |
#model: #searchDirectoryHolder |
|
153 |
#immediateAccept: true |
|
154 |
#acceptOnPointerLeave: false |
|
155 |
) |
|
156 |
#(#CheckBoxSpec |
|
157 |
#label: 'Recursively' |
|
158 |
#name: 'CheckBox3' |
|
159 |
#layout: #(#LayoutFrame -97 1 54 0 1 1 77 0) |
|
160 |
#tabable: true |
|
161 |
#model: #searchRecursively |
|
162 |
#translateLabel: true |
|
163 |
) |
|
164 |
) |
|
165 |
||
166 |
) |
|
167 |
) |
|
168 |
#(#SequenceViewSpec |
|
169 |
#name: 'List1' |
|
170 |
#layout: #(#LayoutFrame 0 0.0 117 0 0 1.0 0 1) |
|
171 |
#model: #selectionHolder |
|
172 |
#menu: #menu |
|
173 |
#hasHorizontalScrollBar: true |
|
174 |
#hasVerticalScrollBar: true |
|
175 |
#isMultiSelect: true |
|
4101 | 176 |
#doubleClickSelector: #fileDoubleClick: |
3892 | 177 |
#useIndex: true |
178 |
#sequenceList: #resultList |
|
179 |
) |
|
4168 | 180 |
#(#ProgressIndicatorSpec |
181 |
#name: 'ProgressIndicator1' |
|
182 |
#layout: #(#LayoutFrame 125 0 11 0 231 0 21 0) |
|
183 |
#visibilityChannel: #enableStop |
|
184 |
#backgroundColor: #(#Color 0.0 66.9993 66.9993) |
|
185 |
#showPercentage: false |
|
186 |
#isActivityIndicator: true |
|
187 |
) |
|
3892 | 188 |
) |
189 |
||
190 |
) |
|
191 |
) |
|
192 |
! ! |
|
193 |
||
194 |
!FindFileApplication class methodsFor:'menu specs'! |
|
195 |
||
196 |
menu |
|
197 |
"This resource specification was automatically generated |
|
198 |
by the MenuEditor of ST/X." |
|
199 |
||
200 |
"Do not manually edit this!! If it is corrupted, |
|
201 |
the MenuEditor may not be able to read the specification." |
|
202 |
||
203 |
" |
|
204 |
MenuEditor new openOnClass:FindFileApplication andSelector:#menu |
|
205 |
(Menu new fromLiteralArrayEncoding:(FindFileApplication menu)) startUp |
|
206 |
" |
|
207 |
||
208 |
<resource: #menu> |
|
209 |
||
210 |
^ |
|
211 |
#(#Menu |
|
212 |
#( |
|
213 |
#(#MenuItem |
|
214 |
#label: 'Select in Browser' |
|
215 |
#translateLabel: true |
|
216 |
#isVisible: #isEmbeddedApplication |
|
217 |
#value: #selectInBrowser |
|
218 |
#enabled: #hasOneFileSelected |
|
219 |
) |
|
220 |
#(#MenuItem |
|
221 |
#label: 'Copy Selected Files' |
|
222 |
#translateLabel: true |
|
223 |
#value: #copySelectedFiles |
|
224 |
#enabled: #hasSelectionInResultList |
|
225 |
) |
|
226 |
#(#MenuItem |
|
227 |
#label: 'Open in New File Browser' |
|
228 |
#translateLabel: true |
|
229 |
#value: #openInNewBrowser |
|
230 |
#enabled: #hasOneFileSelected |
|
231 |
) |
|
232 |
#(#MenuItem |
|
233 |
#label: 'Remove selected Files' |
|
234 |
#translateLabel: true |
|
235 |
#value: #removeFromList |
|
236 |
#enabled: #hasSelection |
|
237 |
) |
|
238 |
#(#MenuItem |
|
239 |
#label: 'Remove all Files' |
|
240 |
#translateLabel: true |
|
241 |
#value: #removeAllFromList |
|
242 |
#enabled: #hasListEntries |
|
243 |
) |
|
244 |
) |
|
245 |
nil |
|
246 |
nil |
|
247 |
) |
|
248 |
! |
|
249 |
||
250 |
searchMenu |
|
251 |
"This resource specification was automatically generated |
|
252 |
by the MenuEditor of ST/X." |
|
253 |
||
254 |
"Do not manually edit this!! If it is corrupted, |
|
255 |
the MenuEditor may not be able to read the specification." |
|
256 |
||
257 |
" |
|
258 |
MenuEditor new openOnClass:FindFileApplication andSelector:#searchMenu |
|
259 |
(Menu new fromLiteralArrayEncoding:(FindFileApplication searchMenu)) startUp |
|
260 |
" |
|
261 |
||
262 |
<resource: #menu> |
|
263 |
||
264 |
^ |
|
265 |
#(#Menu |
|
266 |
#( |
|
267 |
#(#MenuItem |
|
268 |
#label: 'Search' |
|
269 |
#translateLabel: true |
|
270 |
#isButton: true |
|
271 |
#value: #doSearch |
|
272 |
#labelImage: #(#ResourceRetriever #ToolbarIconLibrary #search20x20Icon) |
|
273 |
) |
|
274 |
#(#MenuItem |
|
275 |
#label: 'Stop' |
|
276 |
#translateLabel: true |
|
277 |
#isButton: true |
|
278 |
#value: #stop |
|
279 |
#enabled: #enableStop |
|
280 |
#labelImage: #(#ResourceRetriever #ToolbarIconLibrary #stop22x22Icon) |
|
281 |
) |
|
282 |
#(#MenuItem |
|
283 |
#label: 'Clean Up' |
|
284 |
#translateLabel: true |
|
285 |
#isButton: true |
|
286 |
#value: #removeAllFromList |
|
287 |
#enabled: #hasListEntries |
|
288 |
#labelImage: #(#ResourceRetriever #Icon #deleteIcon) |
|
289 |
) |
|
290 |
#(#MenuItem |
|
291 |
#label: 'Close' |
|
292 |
#translateLabel: true |
|
293 |
#isButton: true |
|
294 |
#startGroup: #right |
|
295 |
#value: #doClose |
|
296 |
#labelImage: #(#ResourceRetriever #AbstractFileBrowser #closeIcon) |
|
297 |
) |
|
298 |
) |
|
299 |
nil |
|
300 |
nil |
|
301 |
) |
|
302 |
! ! |
|
303 |
||
304 |
!FindFileApplication class methodsFor:'tableColumns specs'! |
|
305 |
||
306 |
searchResultTable |
|
307 |
"This resource specification was automatically generated |
|
308 |
by the DataSetBuilder of ST/X." |
|
309 |
||
310 |
"Do not manually edit this!! If it is corrupted, |
|
311 |
the DataSetBuilder may not be able to read the specification." |
|
312 |
||
313 |
" |
|
314 |
DataSetBuilder new openOnClass:FindFileApplication andSelector:#searchResultTable |
|
315 |
" |
|
316 |
||
317 |
<resource: #tableColumns> |
|
318 |
||
319 |
^#( |
|
320 |
#(#DataSetColumnSpec |
|
321 |
#label: 'Filename' |
|
322 |
#id: 'FileName' |
|
323 |
#labelButtonType: #Button |
|
324 |
#model: #fileName |
|
325 |
#showRowSeparator: false |
|
326 |
#showColSeparator: false |
|
327 |
) |
|
328 |
) |
|
329 |
||
330 |
! ! |
|
331 |
||
332 |
!FindFileApplication methodsFor:'accessing'! |
|
333 |
||
334 |
accessLock |
|
335 |
"return the value of the instance variable 'accessLock' (automatically generated)" |
|
336 |
||
337 |
accessLock isNil ifTrue:[ |
|
338 |
accessLock := Semaphore forMutualExclusion name:'accessLock'. |
|
339 |
]. |
|
340 |
^ accessLock |
|
341 |
! |
|
342 |
||
343 |
stopSignal |
|
344 |
||
345 |
stopSignal isNil ifTrue:[ |
|
346 |
stopSignal := Signal new. |
|
347 |
]. |
|
348 |
^ stopSignal |
|
4101 | 349 |
! |
350 |
||
351 |
targetApplication:something |
|
352 |
"set the value of the instance variable 'targetApplication' (automatically generated)" |
|
353 |
||
354 |
targetApplication := something. |
|
3892 | 355 |
! ! |
356 |
||
357 |
!FindFileApplication methodsFor:'actions'! |
|
358 |
||
359 |
changeInformationTo:aString |
|
360 |
||
361 |
self changeInformationTo:aString toTab:false |
|
362 |
! |
|
363 |
||
364 |
changeInformationTo:aString toTab:aBoolean |
|
365 |
||
366 |
masterApplication isNil ifTrue:[ |
|
367 |
findFileView label:aString |
|
368 |
] ifFalse:[ |
|
369 |
aBoolean ifTrue:[ |
|
370 |
masterApplication tabStringChangeTo:aString for:self |
|
371 |
] |
|
372 |
]. |
|
373 |
! |
|
374 |
||
375 |
copySelectedFiles |
|
376 |
|sel list stream| |
|
377 |
||
378 |
sel := self selectionHolder value. |
|
379 |
list := self resultList. |
|
380 |
(sel notNil and:[sel notEmpty]) ifTrue:[ |
|
381 |
stream := WriteStream on:''. |
|
382 |
sel do:[: key | |
|
383 |
stream nextPutAll:(list at:key). |
|
384 |
stream cr. |
|
385 |
]. |
|
386 |
self window setTextSelection:stream contents. |
|
387 |
stream close. |
|
388 |
]. |
|
389 |
! |
|
390 |
||
391 |
doSearch |
|
392 |
||
393 |
| namePattern namePatterns contentsPattern dir| |
|
394 |
||
395 |
"/ self changeExtentToSeeSearchResult. |
|
396 |
||
397 |
dir := self searchDirectoryHolder value. |
|
398 |
dir isNil ifTrue:[ |
|
399 |
Dialog warn:'please type in a Directory first'. |
|
400 |
^ self. |
|
401 |
]. |
|
402 |
dir asFilename exists not ifTrue:[ |
|
403 |
Dialog warn:dir, 'not exists'. |
|
404 |
^ self. |
|
405 |
]. |
|
406 |
||
407 |
searchTask notNil ifTrue:[ |
|
408 |
(Dialog |
|
409 |
confirm:(resources string:'there is already a find file running !!') withCRs |
|
410 |
yesLabel:(resources at:'Stop and continue') |
|
411 |
noLabel:(resources at:'Cancel')) |
|
412 |
ifFalse:[^ self]. |
|
413 |
self stop. |
|
414 |
]. |
|
415 |
||
416 |
namePattern := self namePatternHolder value. |
|
417 |
namePattern size == 0 ifTrue:[ |
|
418 |
namePatterns := nil |
|
419 |
] ifFalse:[ |
|
420 |
ignoreCaseInName value ifTrue:[ |
|
421 |
namePattern := namePattern asLowercase |
|
422 |
]. |
|
423 |
namePatterns := namePattern asCollectionOfSubstringsSeparatedBy:$; |
|
424 |
]. |
|
425 |
contentsPattern := self contentsPatternHolder value. |
|
426 |
contentsPattern size == 0 ifTrue:[ |
|
427 |
contentsPattern := nil |
|
428 |
] ifFalse:[ |
|
429 |
self ignoreCaseInContents value ifTrue:[ |
|
430 |
contentsPattern := contentsPattern asLowercase |
|
431 |
] |
|
432 |
]. |
|
433 |
searchTask := Process for:[ |
|
4168 | 434 |
[ |
3892 | 435 |
(self stopSignal) catch:[ |
4168 | 436 |
self enableStop value:true. |
3892 | 437 |
self resultList removeAll. |
438 |
self changeInformationTo:'Find File ' , '- search started ' toTab:true. |
|
439 |
self |
|
440 |
doFindFileNamed:namePatterns |
|
441 |
ignoreCase:self ignoreCaseInName value |
|
442 |
containingString:contentsPattern |
|
443 |
ignoreCaseInContents:self ignoreCaseInContents value |
|
444 |
sameContentsAsFile:nil |
|
445 |
sameContentsAs:nil |
|
446 |
in:self searchDirectoryHolder value. |
|
447 |
self enableStop value:false. |
|
448 |
self enableSearch value:true. |
|
449 |
self changeInformationTo:'Find File ' , '- search finished' toTab:true. |
|
450 |
]. |
|
451 |
] valueNowOrOnUnwindDo:[ |
|
452 |
searchTask := nil. |
|
453 |
self enableStop value:false. |
|
454 |
] |
|
455 |
] priority:(Processor systemBackgroundPriority). |
|
456 |
||
457 |
searchTask name:('FindFile[', self searchDirectoryHolder value asFilename baseName, ']'). |
|
458 |
searchTask resume. |
|
459 |
! |
|
460 |
||
461 |
openInNewBrowser |
|
462 |
|sel| |
|
463 |
||
464 |
sel := self selectionHolder value. |
|
465 |
(sel notNil and:[sel notEmpty]) ifTrue:[ |
|
466 |
FileBrowserV2 openOn:(self resultList at:sel first) asFilename |
|
467 |
]. |
|
468 |
! |
|
469 |
||
470 |
removeAllFromList |
|
471 |
||
472 |
self resultList removeAll. |
|
473 |
! |
|
474 |
||
475 |
removeFromList |
|
476 |
|sel list| |
|
477 |
||
478 |
sel := self selectionHolder value. |
|
479 |
list := self resultList. |
|
480 |
(sel notNil and:[sel notEmpty]) ifTrue:[ |
|
481 |
sel reverseDo:[: key | |
|
482 |
list removeAtIndex:key |
|
483 |
] |
|
484 |
]. |
|
485 |
! |
|
486 |
||
487 |
selectInBrowser |
|
488 |
|sel entry application| |
|
489 |
||
490 |
sel := self selectionHolder value. |
|
491 |
(sel notNil and:[sel notEmpty]) ifTrue:[ |
|
492 |
entry := self resultList at:sel first. |
|
4182 | 493 |
entry asFilename exists not ifTrue:[ ^ self]. |
4101 | 494 |
application := targetApplication ? self masterApplication. |
4182 | 495 |
application notNil ifTrue:[ |
4101 | 496 |
application gotoFile:(entry asFilename). |
497 |
]. |
|
3892 | 498 |
]. |
499 |
! |
|
500 |
||
501 |
stop |
|
502 |
||
503 |
searchTask notNil ifTrue:[ |
|
504 |
self accessLock critical:[ |
|
505 |
searchTask interruptWith:[stopSignal raiseRequest]. |
|
506 |
] |
|
507 |
]. |
|
508 |
self enableStop value:false. |
|
509 |
self enableSearch value:true. |
|
510 |
self changeInformationTo:'Find File ' , '- search stopped' toTab:true. |
|
511 |
! |
|
512 |
||
513 |
stopSearchTask |
|
514 |
|task| |
|
515 |
||
516 |
(task := searchTask) notNil ifTrue:[ |
|
517 |
searchTask := nil. |
|
518 |
||
519 |
Object errorSignal handle:[:ex| |
|
520 |
Dialog warn:ex description. |
|
521 |
]do:[ |
|
522 |
task isDead ifFalse:[ |
|
3937
80d958725879
terminateWithAllSUbprocesses -> xxxInGroup
Claus Gittinger <cg@exept.de>
parents:
3892
diff
changeset
|
523 |
task terminateWithAllSubprocessesInGroup. |
3892 | 524 |
task waitUntilTerminated. |
525 |
] |
|
526 |
] |
|
527 |
]. |
|
528 |
! ! |
|
529 |
||
530 |
!FindFileApplication methodsFor:'aspects'! |
|
531 |
||
532 |
contentsPatternHolder |
|
533 |
||
534 |
contentsPatternHolder isNil ifTrue:[ |
|
535 |
contentsPatternHolder := nil asValue. |
|
536 |
]. |
|
537 |
^ contentsPatternHolder. |
|
538 |
! |
|
539 |
||
540 |
enableSearch |
|
541 |
||
542 |
enableSearch isNil ifTrue:[ |
|
543 |
enableSearch := true asValue. |
|
544 |
]. |
|
545 |
^ enableSearch. |
|
546 |
! |
|
547 |
||
548 |
enableStop |
|
549 |
||
550 |
enableStop isNil ifTrue:[ |
|
551 |
enableStop := true asValue. |
|
552 |
]. |
|
553 |
^ enableStop. |
|
554 |
! |
|
555 |
||
556 |
hasListEntries |
|
557 |
||
558 |
hasListEntries isNil ifTrue:[ |
|
559 |
hasListEntries := false asValue. |
|
560 |
]. |
|
561 |
^ hasListEntries. |
|
562 |
! |
|
563 |
||
564 |
ignoreCaseInContents |
|
565 |
ignoreCaseInContents isNil ifTrue:[ |
|
566 |
ignoreCaseInContents := false asValue. |
|
567 |
]. |
|
568 |
^ ignoreCaseInContents. |
|
569 |
! |
|
570 |
||
571 |
ignoreCaseInName |
|
572 |
||
573 |
ignoreCaseInName isNil ifTrue:[ |
|
574 |
ignoreCaseInName := false asValue. |
|
575 |
]. |
|
576 |
^ ignoreCaseInName. |
|
577 |
! |
|
578 |
||
579 |
namePatternHolder |
|
580 |
||
581 |
namePatternHolder isNil ifTrue:[ |
|
582 |
namePatternHolder := '*' asValue. |
|
583 |
]. |
|
584 |
^ namePatternHolder. |
|
585 |
! |
|
586 |
||
587 |
notSearchForSameContents |
|
588 |
||
589 |
notSearchForSameContents isNil ifTrue:[ |
|
590 |
notSearchForSameContents := true asValue. |
|
591 |
]. |
|
592 |
^ notSearchForSameContents. |
|
593 |
! |
|
594 |
||
595 |
resultList |
|
596 |
||
597 |
resultList isNil ifTrue:[ |
|
598 |
resultList := List new. |
|
599 |
resultList addDependent:self. |
|
600 |
]. |
|
601 |
^ resultList. |
|
602 |
! |
|
603 |
||
604 |
searchDirectoryHolder |
|
605 |
||
606 |
searchDirectoryHolder isNil ifTrue:[ |
|
607 |
searchDirectoryHolder := ValueHolder new. |
|
608 |
]. |
|
609 |
^ searchDirectoryHolder. |
|
610 |
! |
|
611 |
||
612 |
searchRecursively |
|
613 |
||
614 |
searchRecursively isNil ifTrue:[ |
|
615 |
searchRecursively := true asValue. |
|
616 |
]. |
|
617 |
^ searchRecursively. |
|
618 |
! |
|
619 |
||
620 |
searchResultTable |
|
621 |
||
622 |
searchResultTable isNil ifTrue:[ |
|
623 |
searchResultTable := self class searchResultTable asValue. |
|
624 |
]. |
|
625 |
^ searchResultTable. |
|
626 |
! |
|
627 |
||
628 |
selectionHolder |
|
629 |
||
630 |
selectionHolder isNil ifTrue:[ |
|
4101 | 631 |
selectionHolder := ValueHolder new. |
632 |
selectionHolder addDependent:self. |
|
3892 | 633 |
]. |
634 |
^ selectionHolder |
|
635 |
! ! |
|
636 |
||
637 |
!FindFileApplication methodsFor:'change & update'! |
|
638 |
||
639 |
update:something with:aParameter from:changedObject |
|
640 |
"Invoked when an object that I depend upon sends a change notification." |
|
641 |
||
642 |
"stub code automatically generated - please change as required" |
|
643 |
||
644 |
changedObject == self resultList ifTrue:[ |
|
645 |
self hasListEntries value:(self resultList notEmpty). |
|
646 |
^ self |
|
647 |
]. |
|
4101 | 648 |
changedObject == self selectionHolder ifTrue:[ |
649 |
self selectInBrowser. |
|
650 |
^ self |
|
651 |
]. |
|
3892 | 652 |
super update:something with:aParameter from:changedObject |
653 |
! ! |
|
654 |
||
655 |
!FindFileApplication methodsFor:'event handling'! |
|
656 |
||
4101 | 657 |
fileDoubleClick:entries |
4145
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
658 |
|file app openedAppl contentsPattern| |
4101 | 659 |
|
660 |
file := self resultList at:entries first. |
|
4182 | 661 |
file asFilename exists not ifTrue:[^ self]. |
4101 | 662 |
app := targetApplication ? self masterApplication. |
663 |
app notNil ifTrue:[ |
|
4145
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
664 |
openedAppl := app openApplForFile:file. |
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
665 |
openedAppl isTextEditor ifTrue:[ |
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
666 |
contentsPattern := self contentsPatternHolder value. |
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
667 |
(contentsPattern notNil and:[ contentsPattern notEmpty and:[contentsPattern ~= '*']]) ifTrue:[ |
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
668 |
openedAppl searchForPattern:contentsPattern ignoreCase:(self ignoreCaseInContents value). |
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
669 |
] |
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
670 |
]. |
4101 | 671 |
] ifFalse:[ |
672 |
self openInNewBrowser. |
|
673 |
] |
|
674 |
! |
|
675 |
||
3892 | 676 |
processEvent:anEvent |
677 |
"filter keyboard events. |
|
678 |
Return true, if I have eaten the event" |
|
679 |
||
680 |
|focusView key rawKey| |
|
681 |
||
682 |
anEvent isKeyPressEvent ifTrue:[ |
|
683 |
focusView := anEvent targetView. |
|
684 |
key := anEvent key. |
|
685 |
rawKey := anEvent rawKey. |
|
686 |
||
687 |
(focusView isSameOrComponentOf:self window) ifTrue:[ |
|
688 |
(key == #Return) ifTrue:[ |
|
689 |
(focusView name ~= 'selectionInListView') ifTrue:[ |
|
690 |
self doSearch. |
|
691 |
] ifFalse:[ |
|
692 |
self hasOneFileSelected ifTrue:[ |
|
4101 | 693 |
self fileDoubleClick:(self selectionHolder value) |
694 |
"/ self isEmbeddedApplication ifTrue:[ |
|
695 |
"/ self selectInBrowser. |
|
696 |
"/ ] ifFalse:[ |
|
697 |
"/ self openInNewBrowser. |
|
698 |
"/ ] |
|
3892 | 699 |
] |
700 |
]. |
|
701 |
^ true |
|
702 |
]. |
|
703 |
] |
|
704 |
]. |
|
705 |
^ false |
|
706 |
! ! |
|
707 |
||
708 |
!FindFileApplication methodsFor:'private'! |
|
709 |
||
710 |
changeExtentToSeeSearchResult |
|
711 |
||
712 |
| extent window| |
|
713 |
||
714 |
expanded isNil ifTrue:[ |
|
715 |
window := self builder window. |
|
716 |
window ifNotNil:[ |
|
717 |
window := window topView. |
|
718 |
extent := window extent. |
|
719 |
window extent:((extent x) @ (extent y + 300)). |
|
720 |
expanded := true. |
|
721 |
window containerChangedSize. |
|
722 |
]. |
|
723 |
]. |
|
724 |
! ! |
|
725 |
||
726 |
!FindFileApplication methodsFor:'private - file stuff'! |
|
727 |
||
728 |
doFindFileNamed:namePatterns ignoreCase:ignCaseInName containingString:contentsString ignoreCaseInContents:ignCaseInString sameContentsAsFile:filenameToCompareContentsOrNil sameContentsAs:bytesToCompareContentsOrNil in:aDirectory |
|
729 |
||
730 |
|dir subDirs nameMatches contentsMatches lines contentsToCompare list| |
|
731 |
||
732 |
list := self resultList. |
|
733 |
bytesToCompareContentsOrNil notNil ifTrue:[ |
|
734 |
contentsToCompare := bytesToCompareContentsOrNil |
|
735 |
]. |
|
736 |
||
737 |
subDirs := OrderedCollection new. |
|
738 |
||
739 |
dir := aDirectory asFilename. |
|
740 |
self changeInformationTo:'Find File ' , '- searching .' , ((dir name) copyFrom:(self searchDirectoryHolder value asString size + 1)) toTab:false. |
|
741 |
(dir directoryContents ? #()) sort do:[:fn | |
|
742 |
|f| |
|
743 |
||
744 |
f := dir construct:fn. |
|
745 |
f isDirectory ifTrue:[ |
|
746 |
f isSymbolicLink ifFalse:[ |
|
747 |
subDirs add:f |
|
748 |
] |
|
749 |
] ifFalse:[ |
|
750 |
(nameMatches := namePatterns isNil) ifFalse:[ |
|
751 |
ignCaseInName ifTrue:[ |
|
752 |
nameMatches := namePatterns contains:[:aPattern | aPattern match:(fn asLowercase)] |
|
753 |
] ifFalse:[ |
|
754 |
nameMatches := namePatterns contains:[:aPattern | aPattern match:fn] |
|
755 |
] |
|
756 |
]. |
|
757 |
nameMatches ifTrue:[ |
|
758 |
filenameToCompareContentsOrNil notNil ifTrue:[ |
|
759 |
"/ contents compare ... |
|
760 |
contentsMatches := false. |
|
761 |
f pathName ~= filenameToCompareContentsOrNil pathName ifTrue:[ |
|
762 |
f fileSize == filenameToCompareContentsOrNil fileSize ifTrue:[ |
|
763 |
contentsToCompare isNil ifTrue:[ |
|
764 |
filenameToCompareContentsOrNil fileSize < (512*1024) ifTrue:[ |
|
765 |
contentsToCompare := filenameToCompareContentsOrNil binaryContentsOfEntireFile |
|
766 |
] |
|
767 |
]. |
|
768 |
contentsToCompare isNil ifTrue:[ |
|
769 |
"/ too large - compare block-wise ... |
|
770 |
contentsMatches := (filenameToCompareContentsOrNil sameContentsAs:f). |
|
771 |
] ifFalse:[ |
|
772 |
contentsMatches := contentsToCompare = (f binaryContentsOfEntireFile). |
|
773 |
] |
|
774 |
]. |
|
775 |
] ifFalse:[ |
|
776 |
f isSymbolicLink ifTrue:[ |
|
777 |
list add: (f name , ' is a symbolic link to ' , f pathName). |
|
778 |
] |
|
779 |
] |
|
780 |
] ifFalse:[ |
|
781 |
"/ string search ... |
|
782 |
(contentsMatches := contentsString isNil) ifFalse:[ |
|
783 |
(f exists and:[f isReadable]) ifFalse:[ |
|
784 |
list add: (('*** ' , f pathName , ' skipped - unreadable or bad symbolic link ***') asText colorizeAllWith:(Color red darkened)). |
|
785 |
] ifTrue:[ |
|
786 |
f fileSize > (4024*1024) ifTrue:[ |
|
787 |
list add: (('*** ' , f pathName , ' skipped - too large ***') asText colorizeAllWith:(Color red darkened)). |
|
788 |
] ifFalse:[ |
|
789 |
Stream lineTooLongErrorSignal handle:[:ex | |
|
790 |
|cont| |
|
791 |
||
792 |
"/ this typically happens, when a binary file is read linewise ... |
|
793 |
cont := f readStream binary contentsOfEntireFile asString. |
|
794 |
ignCaseInString ifTrue:[ |
|
795 |
contentsMatches := cont asLowercase includesString:contentsString asLowercase |
|
796 |
] ifFalse:[ |
|
797 |
contentsMatches := cont includesString:contentsString |
|
798 |
]. |
|
799 |
] do:[ |
|
800 |
lines := f contents ? #(). |
|
801 |
ignCaseInString ifTrue:[ |
|
802 |
contentsMatches := (lines findFirst:[:l | l asLowercase includesString:contentsString asLowercase]) ~~ 0 |
|
803 |
] ifFalse:[ |
|
804 |
contentsMatches := (lines findFirst:[:l | l includesString:contentsString]) ~~ 0 |
|
805 |
]. |
|
806 |
]. |
|
807 |
]. |
|
808 |
]. |
|
809 |
]. |
|
810 |
]. |
|
811 |
contentsMatches ifTrue:[ |
|
812 |
list add: f asString. |
|
813 |
] |
|
814 |
] |
|
815 |
] |
|
816 |
]. |
|
817 |
||
818 |
self searchRecursively value ifTrue:[ |
|
819 |
subDirs do:[:dir | |
|
820 |
self |
|
821 |
doFindFileNamed:namePatterns |
|
822 |
ignoreCase:ignCaseInName |
|
823 |
containingString:contentsString |
|
824 |
ignoreCaseInContents:ignCaseInString |
|
825 |
sameContentsAsFile:filenameToCompareContentsOrNil |
|
826 |
sameContentsAs:contentsToCompare |
|
827 |
in:dir |
|
828 |
]. |
|
829 |
] |
|
830 |
! ! |
|
831 |
||
832 |
!FindFileApplication methodsFor:'queries'! |
|
833 |
||
834 |
getTabStringEnd |
|
835 |
||
836 |
" get the tab string from the application list on the class side " |
|
837 |
||
838 |
^ self fileName directory asString |
|
839 |
! |
|
840 |
||
841 |
hasOneFileSelected |
|
842 |
| sel | |
|
843 |
sel := self selectionHolder value. |
|
844 |
^ (sel notNil and:[sel notEmpty and:[sel size = 1]]) |
|
845 |
! |
|
846 |
||
847 |
hasSelectionInResultList |
|
848 |
| sel | |
|
849 |
sel := self selectionHolder value. |
|
850 |
^ (sel notNil and:[sel notEmpty]) |
|
851 |
! ! |
|
852 |
||
853 |
!FindFileApplication methodsFor:'startup & release'! |
|
854 |
||
855 |
item:aItem |
|
856 |
||
857 |
|file| |
|
858 |
||
859 |
super item:aItem. |
|
860 |
file := self fileName. |
|
861 |
self searchDirectoryHolder value:(self getDirWithoutFileName:file). |
|
862 |
file isDirectory ifTrue:[ |
|
863 |
self namePatternHolder value:'*'. |
|
864 |
] ifFalse:[ |
|
4145
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
865 |
self namePatternHolder value:'*.', aItem suffix. |
3892 | 866 |
]. |
867 |
self enableStop value:false. |
|
868 |
self enableSearch value:true. |
|
869 |
^ true. |
|
870 |
! |
|
871 |
||
872 |
postOpenWith:aBuilder |
|
873 |
||
874 |
self masterApplication isNil ifTrue:[ |
|
875 |
self masterApplication:nil. |
|
876 |
]. |
|
877 |
findFileView := aBuilder window. |
|
878 |
self windowGroup addPreEventHook:self. |
|
879 |
^ super postOpenWith:aBuilder. |
|
880 |
! |
|
881 |
||
882 |
release |
|
883 |
||
884 |
self stopSearchTask. |
|
885 |
^ super release |
|
886 |
! ! |
|
887 |
||
888 |
!FindFileApplication class methodsFor:'documentation'! |
|
889 |
||
890 |
version |
|
4182 | 891 |
^ '$Header: /cvs/stx/stx/libtool/FindFileApplication.st,v 1.7 2002-11-05 11:02:59 mb Exp $' |
3892 | 892 |
! ! |