author | penk |
Mon, 04 Nov 2002 11:58:03 +0100 | |
changeset 4145 | 08d6561f7639 |
parent 4101 | cc9cdc23b789 |
child 4168 | 8b7555e00ee3 |
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 |
) |
|
180 |
) |
|
181 |
||
182 |
) |
|
183 |
) |
|
184 |
! ! |
|
185 |
||
186 |
!FindFileApplication class methodsFor:'menu specs'! |
|
187 |
||
188 |
menu |
|
189 |
"This resource specification was automatically generated |
|
190 |
by the MenuEditor of ST/X." |
|
191 |
||
192 |
"Do not manually edit this!! If it is corrupted, |
|
193 |
the MenuEditor may not be able to read the specification." |
|
194 |
||
195 |
" |
|
196 |
MenuEditor new openOnClass:FindFileApplication andSelector:#menu |
|
197 |
(Menu new fromLiteralArrayEncoding:(FindFileApplication menu)) startUp |
|
198 |
" |
|
199 |
||
200 |
<resource: #menu> |
|
201 |
||
202 |
^ |
|
203 |
#(#Menu |
|
204 |
#( |
|
205 |
#(#MenuItem |
|
206 |
#label: 'Select in Browser' |
|
207 |
#translateLabel: true |
|
208 |
#isVisible: #isEmbeddedApplication |
|
209 |
#value: #selectInBrowser |
|
210 |
#enabled: #hasOneFileSelected |
|
211 |
) |
|
212 |
#(#MenuItem |
|
213 |
#label: 'Copy Selected Files' |
|
214 |
#translateLabel: true |
|
215 |
#value: #copySelectedFiles |
|
216 |
#enabled: #hasSelectionInResultList |
|
217 |
) |
|
218 |
#(#MenuItem |
|
219 |
#label: 'Open in New File Browser' |
|
220 |
#translateLabel: true |
|
221 |
#value: #openInNewBrowser |
|
222 |
#enabled: #hasOneFileSelected |
|
223 |
) |
|
224 |
#(#MenuItem |
|
225 |
#label: 'Remove selected Files' |
|
226 |
#translateLabel: true |
|
227 |
#value: #removeFromList |
|
228 |
#enabled: #hasSelection |
|
229 |
) |
|
230 |
#(#MenuItem |
|
231 |
#label: 'Remove all Files' |
|
232 |
#translateLabel: true |
|
233 |
#value: #removeAllFromList |
|
234 |
#enabled: #hasListEntries |
|
235 |
) |
|
236 |
) |
|
237 |
nil |
|
238 |
nil |
|
239 |
) |
|
240 |
! |
|
241 |
||
242 |
searchMenu |
|
243 |
"This resource specification was automatically generated |
|
244 |
by the MenuEditor of ST/X." |
|
245 |
||
246 |
"Do not manually edit this!! If it is corrupted, |
|
247 |
the MenuEditor may not be able to read the specification." |
|
248 |
||
249 |
" |
|
250 |
MenuEditor new openOnClass:FindFileApplication andSelector:#searchMenu |
|
251 |
(Menu new fromLiteralArrayEncoding:(FindFileApplication searchMenu)) startUp |
|
252 |
" |
|
253 |
||
254 |
<resource: #menu> |
|
255 |
||
256 |
^ |
|
257 |
#(#Menu |
|
258 |
#( |
|
259 |
#(#MenuItem |
|
260 |
#label: 'Search' |
|
261 |
#translateLabel: true |
|
262 |
#isButton: true |
|
263 |
#value: #doSearch |
|
264 |
#labelImage: #(#ResourceRetriever #ToolbarIconLibrary #search20x20Icon) |
|
265 |
) |
|
266 |
#(#MenuItem |
|
267 |
#label: 'Stop' |
|
268 |
#translateLabel: true |
|
269 |
#isButton: true |
|
270 |
#value: #stop |
|
271 |
#enabled: #enableStop |
|
272 |
#labelImage: #(#ResourceRetriever #ToolbarIconLibrary #stop22x22Icon) |
|
273 |
) |
|
274 |
#(#MenuItem |
|
275 |
#label: 'Clean Up' |
|
276 |
#translateLabel: true |
|
277 |
#isButton: true |
|
278 |
#value: #removeAllFromList |
|
279 |
#enabled: #hasListEntries |
|
280 |
#labelImage: #(#ResourceRetriever #Icon #deleteIcon) |
|
281 |
) |
|
282 |
#(#MenuItem |
|
283 |
#label: 'Close' |
|
284 |
#translateLabel: true |
|
285 |
#isButton: true |
|
286 |
#startGroup: #right |
|
287 |
#value: #doClose |
|
288 |
#labelImage: #(#ResourceRetriever #AbstractFileBrowser #closeIcon) |
|
289 |
) |
|
290 |
) |
|
291 |
nil |
|
292 |
nil |
|
293 |
) |
|
294 |
! ! |
|
295 |
||
296 |
!FindFileApplication class methodsFor:'tableColumns specs'! |
|
297 |
||
298 |
searchResultTable |
|
299 |
"This resource specification was automatically generated |
|
300 |
by the DataSetBuilder of ST/X." |
|
301 |
||
302 |
"Do not manually edit this!! If it is corrupted, |
|
303 |
the DataSetBuilder may not be able to read the specification." |
|
304 |
||
305 |
" |
|
306 |
DataSetBuilder new openOnClass:FindFileApplication andSelector:#searchResultTable |
|
307 |
" |
|
308 |
||
309 |
<resource: #tableColumns> |
|
310 |
||
311 |
^#( |
|
312 |
#(#DataSetColumnSpec |
|
313 |
#label: 'Filename' |
|
314 |
#id: 'FileName' |
|
315 |
#labelButtonType: #Button |
|
316 |
#model: #fileName |
|
317 |
#showRowSeparator: false |
|
318 |
#showColSeparator: false |
|
319 |
) |
|
320 |
) |
|
321 |
||
322 |
! ! |
|
323 |
||
324 |
!FindFileApplication methodsFor:'accessing'! |
|
325 |
||
326 |
accessLock |
|
327 |
"return the value of the instance variable 'accessLock' (automatically generated)" |
|
328 |
||
329 |
accessLock isNil ifTrue:[ |
|
330 |
accessLock := Semaphore forMutualExclusion name:'accessLock'. |
|
331 |
]. |
|
332 |
^ accessLock |
|
333 |
! |
|
334 |
||
335 |
stopSignal |
|
336 |
||
337 |
stopSignal isNil ifTrue:[ |
|
338 |
stopSignal := Signal new. |
|
339 |
]. |
|
340 |
^ stopSignal |
|
4101 | 341 |
! |
342 |
||
343 |
targetApplication:something |
|
344 |
"set the value of the instance variable 'targetApplication' (automatically generated)" |
|
345 |
||
346 |
targetApplication := something. |
|
3892 | 347 |
! ! |
348 |
||
349 |
!FindFileApplication methodsFor:'actions'! |
|
350 |
||
351 |
changeInformationTo:aString |
|
352 |
||
353 |
self changeInformationTo:aString toTab:false |
|
354 |
! |
|
355 |
||
356 |
changeInformationTo:aString toTab:aBoolean |
|
357 |
||
358 |
masterApplication isNil ifTrue:[ |
|
359 |
findFileView label:aString |
|
360 |
] ifFalse:[ |
|
361 |
aBoolean ifTrue:[ |
|
362 |
masterApplication tabStringChangeTo:aString for:self |
|
363 |
] |
|
364 |
]. |
|
365 |
! |
|
366 |
||
367 |
copySelectedFiles |
|
368 |
|sel list stream| |
|
369 |
||
370 |
sel := self selectionHolder value. |
|
371 |
list := self resultList. |
|
372 |
(sel notNil and:[sel notEmpty]) ifTrue:[ |
|
373 |
stream := WriteStream on:''. |
|
374 |
sel do:[: key | |
|
375 |
stream nextPutAll:(list at:key). |
|
376 |
stream cr. |
|
377 |
]. |
|
378 |
self window setTextSelection:stream contents. |
|
379 |
stream close. |
|
380 |
]. |
|
381 |
! |
|
382 |
||
383 |
doSearch |
|
384 |
||
385 |
| namePattern namePatterns contentsPattern dir| |
|
386 |
||
387 |
"/ self changeExtentToSeeSearchResult. |
|
388 |
||
389 |
dir := self searchDirectoryHolder value. |
|
390 |
dir isNil ifTrue:[ |
|
391 |
Dialog warn:'please type in a Directory first'. |
|
392 |
^ self. |
|
393 |
]. |
|
394 |
dir asFilename exists not ifTrue:[ |
|
395 |
Dialog warn:dir, 'not exists'. |
|
396 |
^ self. |
|
397 |
]. |
|
398 |
||
399 |
searchTask notNil ifTrue:[ |
|
400 |
(Dialog |
|
401 |
confirm:(resources string:'there is already a find file running !!') withCRs |
|
402 |
yesLabel:(resources at:'Stop and continue') |
|
403 |
noLabel:(resources at:'Cancel')) |
|
404 |
ifFalse:[^ self]. |
|
405 |
self stop. |
|
406 |
]. |
|
407 |
self enableStop value:true. |
|
408 |
||
409 |
namePattern := self namePatternHolder value. |
|
410 |
namePattern size == 0 ifTrue:[ |
|
411 |
namePatterns := nil |
|
412 |
] ifFalse:[ |
|
413 |
ignoreCaseInName value ifTrue:[ |
|
414 |
namePattern := namePattern asLowercase |
|
415 |
]. |
|
416 |
namePatterns := namePattern asCollectionOfSubstringsSeparatedBy:$; |
|
417 |
]. |
|
418 |
contentsPattern := self contentsPatternHolder value. |
|
419 |
contentsPattern size == 0 ifTrue:[ |
|
420 |
contentsPattern := nil |
|
421 |
] ifFalse:[ |
|
422 |
self ignoreCaseInContents value ifTrue:[ |
|
423 |
contentsPattern := contentsPattern asLowercase |
|
424 |
] |
|
425 |
]. |
|
426 |
searchTask := Process for:[ |
|
427 |
[ |
|
428 |
(self stopSignal) catch:[ |
|
429 |
self resultList removeAll. |
|
430 |
self changeInformationTo:'Find File ' , '- search started ' toTab:true. |
|
431 |
self |
|
432 |
doFindFileNamed:namePatterns |
|
433 |
ignoreCase:self ignoreCaseInName value |
|
434 |
containingString:contentsPattern |
|
435 |
ignoreCaseInContents:self ignoreCaseInContents value |
|
436 |
sameContentsAsFile:nil |
|
437 |
sameContentsAs:nil |
|
438 |
in:self searchDirectoryHolder value. |
|
439 |
self enableStop value:false. |
|
440 |
self enableSearch value:true. |
|
441 |
self changeInformationTo:'Find File ' , '- search finished' toTab:true. |
|
442 |
]. |
|
443 |
] valueNowOrOnUnwindDo:[ |
|
444 |
searchTask := nil. |
|
445 |
self enableStop value:false. |
|
446 |
] |
|
447 |
] priority:(Processor systemBackgroundPriority). |
|
448 |
||
449 |
searchTask name:('FindFile[', self searchDirectoryHolder value asFilename baseName, ']'). |
|
450 |
searchTask resume. |
|
451 |
! |
|
452 |
||
453 |
openInNewBrowser |
|
454 |
|sel| |
|
455 |
||
456 |
sel := self selectionHolder value. |
|
457 |
(sel notNil and:[sel notEmpty]) ifTrue:[ |
|
458 |
FileBrowserV2 openOn:(self resultList at:sel first) asFilename |
|
459 |
]. |
|
460 |
! |
|
461 |
||
462 |
removeAllFromList |
|
463 |
||
464 |
self resultList removeAll. |
|
465 |
! |
|
466 |
||
467 |
removeFromList |
|
468 |
|sel list| |
|
469 |
||
470 |
sel := self selectionHolder value. |
|
471 |
list := self resultList. |
|
472 |
(sel notNil and:[sel notEmpty]) ifTrue:[ |
|
473 |
sel reverseDo:[: key | |
|
474 |
list removeAtIndex:key |
|
475 |
] |
|
476 |
]. |
|
477 |
! |
|
478 |
||
479 |
selectInBrowser |
|
480 |
|sel entry application| |
|
481 |
||
482 |
sel := self selectionHolder value. |
|
483 |
(sel notNil and:[sel notEmpty]) ifTrue:[ |
|
484 |
entry := self resultList at:sel first. |
|
4101 | 485 |
application := targetApplication ? self masterApplication. |
486 |
application notNil ifTrue:[ |
|
487 |
application gotoFile:(entry asFilename). |
|
488 |
]. |
|
3892 | 489 |
]. |
490 |
! |
|
491 |
||
492 |
stop |
|
493 |
||
494 |
searchTask notNil ifTrue:[ |
|
495 |
self accessLock critical:[ |
|
496 |
searchTask interruptWith:[stopSignal raiseRequest]. |
|
497 |
] |
|
498 |
]. |
|
499 |
self enableStop value:false. |
|
500 |
self enableSearch value:true. |
|
501 |
self changeInformationTo:'Find File ' , '- search stopped' toTab:true. |
|
502 |
! |
|
503 |
||
504 |
stopSearchTask |
|
505 |
|task| |
|
506 |
||
507 |
(task := searchTask) notNil ifTrue:[ |
|
508 |
searchTask := nil. |
|
509 |
||
510 |
Object errorSignal handle:[:ex| |
|
511 |
Dialog warn:ex description. |
|
512 |
]do:[ |
|
513 |
task isDead ifFalse:[ |
|
3937
80d958725879
terminateWithAllSUbprocesses -> xxxInGroup
Claus Gittinger <cg@exept.de>
parents:
3892
diff
changeset
|
514 |
task terminateWithAllSubprocessesInGroup. |
3892 | 515 |
task waitUntilTerminated. |
516 |
] |
|
517 |
] |
|
518 |
]. |
|
519 |
! ! |
|
520 |
||
521 |
!FindFileApplication methodsFor:'aspects'! |
|
522 |
||
523 |
contentsPatternHolder |
|
524 |
||
525 |
contentsPatternHolder isNil ifTrue:[ |
|
526 |
contentsPatternHolder := nil asValue. |
|
527 |
]. |
|
528 |
^ contentsPatternHolder. |
|
529 |
! |
|
530 |
||
531 |
enableSearch |
|
532 |
||
533 |
enableSearch isNil ifTrue:[ |
|
534 |
enableSearch := true asValue. |
|
535 |
]. |
|
536 |
^ enableSearch. |
|
537 |
! |
|
538 |
||
539 |
enableStop |
|
540 |
||
541 |
enableStop isNil ifTrue:[ |
|
542 |
enableStop := true asValue. |
|
543 |
]. |
|
544 |
^ enableStop. |
|
545 |
! |
|
546 |
||
547 |
hasListEntries |
|
548 |
||
549 |
hasListEntries isNil ifTrue:[ |
|
550 |
hasListEntries := false asValue. |
|
551 |
]. |
|
552 |
^ hasListEntries. |
|
553 |
! |
|
554 |
||
555 |
ignoreCaseInContents |
|
556 |
ignoreCaseInContents isNil ifTrue:[ |
|
557 |
ignoreCaseInContents := false asValue. |
|
558 |
]. |
|
559 |
^ ignoreCaseInContents. |
|
560 |
! |
|
561 |
||
562 |
ignoreCaseInName |
|
563 |
||
564 |
ignoreCaseInName isNil ifTrue:[ |
|
565 |
ignoreCaseInName := false asValue. |
|
566 |
]. |
|
567 |
^ ignoreCaseInName. |
|
568 |
! |
|
569 |
||
570 |
namePatternHolder |
|
571 |
||
572 |
namePatternHolder isNil ifTrue:[ |
|
573 |
namePatternHolder := '*' asValue. |
|
574 |
]. |
|
575 |
^ namePatternHolder. |
|
576 |
! |
|
577 |
||
578 |
notSearchForSameContents |
|
579 |
||
580 |
notSearchForSameContents isNil ifTrue:[ |
|
581 |
notSearchForSameContents := true asValue. |
|
582 |
]. |
|
583 |
^ notSearchForSameContents. |
|
584 |
! |
|
585 |
||
586 |
resultList |
|
587 |
||
588 |
resultList isNil ifTrue:[ |
|
589 |
resultList := List new. |
|
590 |
resultList addDependent:self. |
|
591 |
]. |
|
592 |
^ resultList. |
|
593 |
! |
|
594 |
||
595 |
searchDirectoryHolder |
|
596 |
||
597 |
searchDirectoryHolder isNil ifTrue:[ |
|
598 |
searchDirectoryHolder := ValueHolder new. |
|
599 |
]. |
|
600 |
^ searchDirectoryHolder. |
|
601 |
! |
|
602 |
||
603 |
searchRecursively |
|
604 |
||
605 |
searchRecursively isNil ifTrue:[ |
|
606 |
searchRecursively := true asValue. |
|
607 |
]. |
|
608 |
^ searchRecursively. |
|
609 |
! |
|
610 |
||
611 |
searchResultTable |
|
612 |
||
613 |
searchResultTable isNil ifTrue:[ |
|
614 |
searchResultTable := self class searchResultTable asValue. |
|
615 |
]. |
|
616 |
^ searchResultTable. |
|
617 |
! |
|
618 |
||
619 |
selectionHolder |
|
620 |
||
621 |
selectionHolder isNil ifTrue:[ |
|
4101 | 622 |
selectionHolder := ValueHolder new. |
623 |
selectionHolder addDependent:self. |
|
3892 | 624 |
]. |
625 |
^ selectionHolder |
|
626 |
! ! |
|
627 |
||
628 |
!FindFileApplication methodsFor:'change & update'! |
|
629 |
||
630 |
update:something with:aParameter from:changedObject |
|
631 |
"Invoked when an object that I depend upon sends a change notification." |
|
632 |
||
633 |
"stub code automatically generated - please change as required" |
|
634 |
||
635 |
changedObject == self resultList ifTrue:[ |
|
636 |
self hasListEntries value:(self resultList notEmpty). |
|
637 |
^ self |
|
638 |
]. |
|
4101 | 639 |
changedObject == self selectionHolder ifTrue:[ |
640 |
self selectInBrowser. |
|
641 |
^ self |
|
642 |
]. |
|
3892 | 643 |
super update:something with:aParameter from:changedObject |
644 |
! ! |
|
645 |
||
646 |
!FindFileApplication methodsFor:'event handling'! |
|
647 |
||
4101 | 648 |
fileDoubleClick:entries |
4145
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
649 |
|file app openedAppl contentsPattern| |
4101 | 650 |
|
651 |
file := self resultList at:entries first. |
|
652 |
app := targetApplication ? self masterApplication. |
|
653 |
app notNil ifTrue:[ |
|
4145
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
654 |
openedAppl := app openApplForFile:file. |
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
655 |
openedAppl isTextEditor ifTrue:[ |
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
656 |
contentsPattern := self contentsPatternHolder value. |
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
657 |
(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
|
658 |
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
|
659 |
] |
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
660 |
]. |
4101 | 661 |
] ifFalse:[ |
662 |
self openInNewBrowser. |
|
663 |
] |
|
664 |
! |
|
665 |
||
3892 | 666 |
processEvent:anEvent |
667 |
"filter keyboard events. |
|
668 |
Return true, if I have eaten the event" |
|
669 |
||
670 |
|focusView key rawKey| |
|
671 |
||
672 |
anEvent isKeyPressEvent ifTrue:[ |
|
673 |
focusView := anEvent targetView. |
|
674 |
key := anEvent key. |
|
675 |
rawKey := anEvent rawKey. |
|
676 |
||
677 |
(focusView isSameOrComponentOf:self window) ifTrue:[ |
|
678 |
(key == #Return) ifTrue:[ |
|
679 |
(focusView name ~= 'selectionInListView') ifTrue:[ |
|
680 |
self doSearch. |
|
681 |
] ifFalse:[ |
|
682 |
self hasOneFileSelected ifTrue:[ |
|
4101 | 683 |
self fileDoubleClick:(self selectionHolder value) |
684 |
"/ self isEmbeddedApplication ifTrue:[ |
|
685 |
"/ self selectInBrowser. |
|
686 |
"/ ] ifFalse:[ |
|
687 |
"/ self openInNewBrowser. |
|
688 |
"/ ] |
|
3892 | 689 |
] |
690 |
]. |
|
691 |
^ true |
|
692 |
]. |
|
693 |
] |
|
694 |
]. |
|
695 |
^ false |
|
696 |
! ! |
|
697 |
||
698 |
!FindFileApplication methodsFor:'private'! |
|
699 |
||
700 |
changeExtentToSeeSearchResult |
|
701 |
||
702 |
| extent window| |
|
703 |
||
704 |
expanded isNil ifTrue:[ |
|
705 |
window := self builder window. |
|
706 |
window ifNotNil:[ |
|
707 |
window := window topView. |
|
708 |
extent := window extent. |
|
709 |
window extent:((extent x) @ (extent y + 300)). |
|
710 |
expanded := true. |
|
711 |
window containerChangedSize. |
|
712 |
]. |
|
713 |
]. |
|
714 |
! ! |
|
715 |
||
716 |
!FindFileApplication methodsFor:'private - file stuff'! |
|
717 |
||
718 |
doFindFileNamed:namePatterns ignoreCase:ignCaseInName containingString:contentsString ignoreCaseInContents:ignCaseInString sameContentsAsFile:filenameToCompareContentsOrNil sameContentsAs:bytesToCompareContentsOrNil in:aDirectory |
|
719 |
||
720 |
|dir subDirs nameMatches contentsMatches lines contentsToCompare list| |
|
721 |
||
722 |
list := self resultList. |
|
723 |
bytesToCompareContentsOrNil notNil ifTrue:[ |
|
724 |
contentsToCompare := bytesToCompareContentsOrNil |
|
725 |
]. |
|
726 |
||
727 |
subDirs := OrderedCollection new. |
|
728 |
||
729 |
dir := aDirectory asFilename. |
|
730 |
self changeInformationTo:'Find File ' , '- searching .' , ((dir name) copyFrom:(self searchDirectoryHolder value asString size + 1)) toTab:false. |
|
731 |
(dir directoryContents ? #()) sort do:[:fn | |
|
732 |
|f| |
|
733 |
||
734 |
f := dir construct:fn. |
|
735 |
f isDirectory ifTrue:[ |
|
736 |
f isSymbolicLink ifFalse:[ |
|
737 |
subDirs add:f |
|
738 |
] |
|
739 |
] ifFalse:[ |
|
740 |
(nameMatches := namePatterns isNil) ifFalse:[ |
|
741 |
ignCaseInName ifTrue:[ |
|
742 |
nameMatches := namePatterns contains:[:aPattern | aPattern match:(fn asLowercase)] |
|
743 |
] ifFalse:[ |
|
744 |
nameMatches := namePatterns contains:[:aPattern | aPattern match:fn] |
|
745 |
] |
|
746 |
]. |
|
747 |
nameMatches ifTrue:[ |
|
748 |
filenameToCompareContentsOrNil notNil ifTrue:[ |
|
749 |
"/ contents compare ... |
|
750 |
contentsMatches := false. |
|
751 |
f pathName ~= filenameToCompareContentsOrNil pathName ifTrue:[ |
|
752 |
f fileSize == filenameToCompareContentsOrNil fileSize ifTrue:[ |
|
753 |
contentsToCompare isNil ifTrue:[ |
|
754 |
filenameToCompareContentsOrNil fileSize < (512*1024) ifTrue:[ |
|
755 |
contentsToCompare := filenameToCompareContentsOrNil binaryContentsOfEntireFile |
|
756 |
] |
|
757 |
]. |
|
758 |
contentsToCompare isNil ifTrue:[ |
|
759 |
"/ too large - compare block-wise ... |
|
760 |
contentsMatches := (filenameToCompareContentsOrNil sameContentsAs:f). |
|
761 |
] ifFalse:[ |
|
762 |
contentsMatches := contentsToCompare = (f binaryContentsOfEntireFile). |
|
763 |
] |
|
764 |
]. |
|
765 |
] ifFalse:[ |
|
766 |
f isSymbolicLink ifTrue:[ |
|
767 |
list add: (f name , ' is a symbolic link to ' , f pathName). |
|
768 |
] |
|
769 |
] |
|
770 |
] ifFalse:[ |
|
771 |
"/ string search ... |
|
772 |
(contentsMatches := contentsString isNil) ifFalse:[ |
|
773 |
(f exists and:[f isReadable]) ifFalse:[ |
|
774 |
list add: (('*** ' , f pathName , ' skipped - unreadable or bad symbolic link ***') asText colorizeAllWith:(Color red darkened)). |
|
775 |
] ifTrue:[ |
|
776 |
f fileSize > (4024*1024) ifTrue:[ |
|
777 |
list add: (('*** ' , f pathName , ' skipped - too large ***') asText colorizeAllWith:(Color red darkened)). |
|
778 |
] ifFalse:[ |
|
779 |
Stream lineTooLongErrorSignal handle:[:ex | |
|
780 |
|cont| |
|
781 |
||
782 |
"/ this typically happens, when a binary file is read linewise ... |
|
783 |
cont := f readStream binary contentsOfEntireFile asString. |
|
784 |
ignCaseInString ifTrue:[ |
|
785 |
contentsMatches := cont asLowercase includesString:contentsString asLowercase |
|
786 |
] ifFalse:[ |
|
787 |
contentsMatches := cont includesString:contentsString |
|
788 |
]. |
|
789 |
] do:[ |
|
790 |
lines := f contents ? #(). |
|
791 |
ignCaseInString ifTrue:[ |
|
792 |
contentsMatches := (lines findFirst:[:l | l asLowercase includesString:contentsString asLowercase]) ~~ 0 |
|
793 |
] ifFalse:[ |
|
794 |
contentsMatches := (lines findFirst:[:l | l includesString:contentsString]) ~~ 0 |
|
795 |
]. |
|
796 |
]. |
|
797 |
]. |
|
798 |
]. |
|
799 |
]. |
|
800 |
]. |
|
801 |
contentsMatches ifTrue:[ |
|
802 |
list add: f asString. |
|
803 |
] |
|
804 |
] |
|
805 |
] |
|
806 |
]. |
|
807 |
||
808 |
self searchRecursively value ifTrue:[ |
|
809 |
subDirs do:[:dir | |
|
810 |
self |
|
811 |
doFindFileNamed:namePatterns |
|
812 |
ignoreCase:ignCaseInName |
|
813 |
containingString:contentsString |
|
814 |
ignoreCaseInContents:ignCaseInString |
|
815 |
sameContentsAsFile:filenameToCompareContentsOrNil |
|
816 |
sameContentsAs:contentsToCompare |
|
817 |
in:dir |
|
818 |
]. |
|
819 |
] |
|
820 |
! ! |
|
821 |
||
822 |
!FindFileApplication methodsFor:'queries'! |
|
823 |
||
824 |
getTabStringEnd |
|
825 |
||
826 |
" get the tab string from the application list on the class side " |
|
827 |
||
828 |
^ self fileName directory asString |
|
829 |
! |
|
830 |
||
831 |
hasOneFileSelected |
|
832 |
| sel | |
|
833 |
sel := self selectionHolder value. |
|
834 |
^ (sel notNil and:[sel notEmpty and:[sel size = 1]]) |
|
835 |
! |
|
836 |
||
837 |
hasSelectionInResultList |
|
838 |
| sel | |
|
839 |
sel := self selectionHolder value. |
|
840 |
^ (sel notNil and:[sel notEmpty]) |
|
841 |
! ! |
|
842 |
||
843 |
!FindFileApplication methodsFor:'startup & release'! |
|
844 |
||
845 |
item:aItem |
|
846 |
||
847 |
|file| |
|
848 |
||
849 |
super item:aItem. |
|
850 |
file := self fileName. |
|
851 |
self searchDirectoryHolder value:(self getDirWithoutFileName:file). |
|
852 |
file isDirectory ifTrue:[ |
|
853 |
self namePatternHolder value:'*'. |
|
854 |
] ifFalse:[ |
|
4145
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
855 |
self namePatternHolder value:'*.', aItem suffix. |
3892 | 856 |
]. |
857 |
self enableStop value:false. |
|
858 |
self enableSearch value:true. |
|
859 |
^ true. |
|
860 |
! |
|
861 |
||
862 |
postOpenWith:aBuilder |
|
863 |
||
864 |
self masterApplication isNil ifTrue:[ |
|
865 |
self masterApplication:nil. |
|
866 |
]. |
|
867 |
findFileView := aBuilder window. |
|
868 |
self windowGroup addPreEventHook:self. |
|
869 |
^ super postOpenWith:aBuilder. |
|
870 |
! |
|
871 |
||
872 |
release |
|
873 |
||
874 |
self stopSearchTask. |
|
875 |
^ super release |
|
876 |
! ! |
|
877 |
||
878 |
!FindFileApplication class methodsFor:'documentation'! |
|
879 |
||
880 |
version |
|
4145
08d6561f7639
on doubleclick after search the file is opened and searchPatternStrin is selected
penk
parents:
4101
diff
changeset
|
881 |
^ '$Header: /cvs/stx/stx/libtool/FindFileApplication.st,v 1.5 2002-11-04 10:58:03 penk Exp $' |
3892 | 882 |
! ! |