14 |
14 |
15 AbstractFileApplicationNoteBookComponent subclass:#FindFileApplication |
15 AbstractFileApplicationNoteBookComponent subclass:#FindFileApplication |
16 instanceVariableNames:'searchDirectories searchDirectoryHolder notSearchForSameContents |
16 instanceVariableNames:'searchDirectories searchDirectoryHolder notSearchForSameContents |
17 namePatternHolder ignoreCaseInName contentsPatternHolder |
17 namePatternHolder ignoreCaseInName contentsPatternHolder |
18 ignoreCaseInContents notContentsPatternHolder |
18 ignoreCaseInContents notContentsPatternHolder |
19 ignoreCaseInNotContents findFileView searchResultTable resultList |
19 ignoreCaseInNotContents sameContentsAsHolder findFileView |
20 enableStop enableSearch stopSignal accessLock searchTask expanded |
20 searchResultTable resultList enableStop enableSearch stopSignal |
21 searchRecursively selectionHolder hasListEntries |
21 accessLock searchTask expanded searchRecursively selectionHolder |
22 targetApplication useLocate useGrep' |
22 hasListEntries targetApplication useLocate useGrep |
23 classVariableNames:'' |
23 rememberInCache' |
|
24 classVariableNames:'ContentsInfoCache' |
24 poolDictionaries:'' |
25 poolDictionaries:'' |
25 category:'Interface-Tools-File' |
26 category:'Interface-Tools-File' |
26 ! |
27 ! |
27 |
28 |
28 !FindFileApplication class methodsFor:'documentation'! |
29 !FindFileApplication class methodsFor:'documentation'! |
42 ! ! |
43 ! ! |
43 |
44 |
44 !FindFileApplication class methodsFor:'instance creation'! |
45 !FindFileApplication class methodsFor:'instance creation'! |
45 |
46 |
46 open |
47 open |
47 |
48 ^ self openInDirectory:(Filename currentDirectory) |
48 ^ self openOnFileName:(Filename currentDirectory asAbsoluteFilename) |
49 |
|
50 " |
|
51 self open |
|
52 " |
|
53 ! |
|
54 |
|
55 openInDirectory:aFilename |
|
56 ^ self openOnFileName:(aFilename asFilename asAbsoluteFilename) |
|
57 |
|
58 " |
|
59 self openInDirectory:'/etc' |
|
60 " |
49 ! |
61 ! |
50 |
62 |
51 openOnFileName:aFileName |
63 openOnFileName:aFileName |
|
64 ^ self openOnFileName:aFileName for:nil |
|
65 ! |
|
66 |
|
67 openOnFileName:aFileName for:aTargetApplicationOrNil |
52 |
68 |
53 | instance builder| |
69 | instance builder| |
54 |
70 |
55 builder := super open. |
71 builder := super open. |
56 instance := builder application. |
72 instance := builder application. |
57 instance item:(DirectoryContentsBrowser itemClass fileName:aFileName). |
73 instance item:(DirectoryContentsBrowser itemClass fileName:aFileName). |
58 ^ builder |
74 aTargetApplicationOrNil notNil ifTrue:[ |
59 ! |
75 instance targetApplication:aTargetApplicationOrNil. |
60 |
76 ]. |
61 openOnFileName:aFileName for:aTargetApplication |
|
62 |
|
63 | instance builder| |
|
64 |
|
65 builder := super open. |
|
66 instance := builder application. |
|
67 instance item:(DirectoryContentsBrowser itemClass fileName:aFileName). |
|
68 instance targetApplication:aTargetApplication. |
|
69 ^ builder |
77 ^ builder |
70 ! ! |
78 ! ! |
71 |
79 |
72 !FindFileApplication class methodsFor:'defaults'! |
80 !FindFileApplication class methodsFor:'defaults'! |
73 |
81 |
201 acceptOnPointerLeave: false |
209 acceptOnPointerLeave: false |
202 ) |
210 ) |
203 (CheckBoxSpec |
211 (CheckBoxSpec |
204 label: 'Use ''grep'' Cmd' |
212 label: 'Use ''grep'' Cmd' |
205 name: 'UseGrepCheckBox' |
213 name: 'UseGrepCheckBox' |
206 layout: (LayoutFrame -300 1 52 0 -158 1 75 0) |
214 layout: (LayoutFrame -300 1 53 0 -158 1 76 0) |
207 visibilityChannel: canUseGrep |
215 visibilityChannel: canUseGrep |
208 tabable: true |
216 tabable: true |
209 model: useGrep |
217 model: useGrep |
210 translateLabel: true |
218 translateLabel: true |
211 ) |
219 ) |
212 (CheckBoxSpec |
220 (CheckBoxSpec |
213 label: 'Ignore Case' |
221 label: 'Ignore Case' |
214 name: 'IgnoreCaseInContentsCheckBox' |
222 name: 'IgnoreCaseInContentsCheckBox' |
215 layout: (LayoutFrame -160 1 52 0 -4 1 75 0) |
223 layout: (LayoutFrame -160 1 53 0 -4 1 76 0) |
216 enableChannel: notSearchForSameContents |
224 enableChannel: notSearchForSameContents |
217 tabable: true |
225 tabable: true |
218 model: ignoreCaseInContents |
226 model: ignoreCaseInContents |
219 translateLabel: true |
227 translateLabel: true |
220 ) |
228 ) |
235 acceptOnPointerLeave: false |
243 acceptOnPointerLeave: false |
236 ) |
244 ) |
237 (CheckBoxSpec |
245 (CheckBoxSpec |
238 label: 'Ignore Case' |
246 label: 'Ignore Case' |
239 name: 'IgnoreCaseInNotContentsCheckBox' |
247 name: 'IgnoreCaseInNotContentsCheckBox' |
240 layout: (LayoutFrame -160 1 76 0 -4 1 99 0) |
248 layout: (LayoutFrame -160 1 77 0 -4 1 100 0) |
241 enableChannel: notSearchForSameContents |
249 enableChannel: notSearchForSameContents |
242 tabable: true |
250 tabable: true |
243 model: ignoreCaseInNotContents |
251 model: ignoreCaseInNotContents |
|
252 translateLabel: true |
|
253 ) |
|
254 (LabelSpec |
|
255 label: 'Same Contents As:' |
|
256 name: 'SameContentsAsLabel' |
|
257 layout: (LayoutFrame 2 0 103 0 154 0 120 0) |
|
258 translateLabel: true |
|
259 adjust: right |
|
260 ) |
|
261 (InputFieldSpec |
|
262 name: 'SameContentsAsEntryField' |
|
263 layout: (LayoutFrame 156 0 100 0 -315 1 120 0) |
|
264 enableChannel: notSearchForSameContents |
|
265 tabable: true |
|
266 model: sameContentsAsHolder |
|
267 formatString: '' |
|
268 immediateAccept: true |
|
269 acceptOnPointerLeave: false |
|
270 ) |
|
271 (CheckBoxSpec |
|
272 label: 'Cache Info' |
|
273 name: 'RememberInCacheCheckBox' |
|
274 layout: (LayoutFrame -300 1 101 0 -158 1 124 0) |
|
275 visibilityChannel: canUseGrep |
|
276 tabable: true |
|
277 model: rememberInCache |
244 translateLabel: true |
278 translateLabel: true |
245 ) |
279 ) |
246 ) |
280 ) |
247 |
281 |
248 ) |
282 ) |
249 ) |
283 ) |
250 (SequenceViewSpec |
284 (SequenceViewSpec |
251 name: 'List1' |
285 name: 'List1' |
252 layout: (LayoutFrame 0 0.0 132 0 0 1.0 0 1) |
286 layout: (LayoutFrame 0 0.0 156 0 0 1.0 0 1) |
253 model: selectionHolder |
287 model: selectionHolder |
254 menu: menu |
288 menu: menu |
255 hasHorizontalScrollBar: true |
289 hasHorizontalScrollBar: true |
256 hasVerticalScrollBar: true |
290 hasVerticalScrollBar: true |
257 isMultiSelect: true |
291 isMultiSelect: true |
535 ignoreCase:(self ignoreCaseInName value) |
576 ignoreCase:(self ignoreCaseInName value) |
536 containingString:contentsPattern |
577 containingString:contentsPattern |
537 ignoreCaseInContents:(self ignoreCaseInContents value) |
578 ignoreCaseInContents:(self ignoreCaseInContents value) |
538 notContainingString:notContentsPattern |
579 notContainingString:notContentsPattern |
539 ignoreCaseInNotContents:(self ignoreCaseInNotContents value) |
580 ignoreCaseInNotContents:(self ignoreCaseInNotContents value) |
540 sameContentsAsFile:nil |
581 sameContentsAsFile:fileToCompareAgainst |
541 sameContentsAs:nil |
582 sameContentsAs:nil |
542 in:(self searchDirectoryHolder value). |
583 in:(self searchDirectoryHolder value). |
543 ]. |
584 ]. |
544 t > 100 ifTrue:[ |
585 t > 100 ifTrue:[ |
545 t := ((t / 1000) asFixedPoint:2) printString , ' s' |
586 t := ((t / 1000) asFixedPoint:2) printString , ' s' |
727 notSearchForSameContents := true asValue. |
768 notSearchForSameContents := true asValue. |
728 ]. |
769 ]. |
729 ^ notSearchForSameContents. |
770 ^ notSearchForSameContents. |
730 ! |
771 ! |
731 |
772 |
|
773 rememberInCache |
|
774 rememberInCache isNil ifTrue:[ |
|
775 rememberInCache := false asValue. |
|
776 ]. |
|
777 ^ rememberInCache. |
|
778 ! |
|
779 |
732 resultList |
780 resultList |
733 |
781 |
734 resultList isNil ifTrue:[ |
782 resultList isNil ifTrue:[ |
735 resultList := List new. |
783 resultList := List new. |
736 resultList addDependent:self. |
784 resultList addDependent:self. |
737 ]. |
785 ]. |
738 ^ resultList. |
786 ^ resultList. |
|
787 ! |
|
788 |
|
789 sameContentsAsHolder |
|
790 |sel| |
|
791 |
|
792 sameContentsAsHolder isNil ifTrue:[ |
|
793 sameContentsAsHolder := ValueHolder new. |
|
794 masterApplication notNil ifTrue:[ |
|
795 sel := masterApplication currentSelectedFiles. |
|
796 sel size > 0 ifTrue:[ |
|
797 sameContentsAsHolder value:(sel first asFilename pathName). |
|
798 ]. |
|
799 ]. |
|
800 ]. |
|
801 ^ sameContentsAsHolder. |
739 ! |
802 ! |
740 |
803 |
741 searchDirectories |
804 searchDirectories |
742 searchDirectories isNil ifTrue:[ |
805 searchDirectories isNil ifTrue:[ |
743 searchDirectories := false asValue. |
806 searchDirectories := false asValue. |
893 notContainingString:notContentsStringArg ignoreCaseInNotContents:ignCaseInNotContents |
956 notContainingString:notContentsStringArg ignoreCaseInNotContents:ignCaseInNotContents |
894 sameContentsAsFile:filenameToCompareContentsOrNil sameContentsAs:bytesToCompareContentsOrNil in:aDirectory |
957 sameContentsAsFile:filenameToCompareContentsOrNil sameContentsAs:bytesToCompareContentsOrNil in:aDirectory |
895 |
958 |
896 |dir nameMatches lines contentsToCompare list inStream |
959 |dir nameMatches lines contentsToCompare list inStream |
897 doesFileMatch contentsString notContentsString check checkNot |
960 doesFileMatch contentsString notContentsString check checkNot |
898 grepCommand nameMatch| |
961 grepCommand nameMatch fileSizeSearchFor fileSearchedFor fileMD5SearchedFor remember |
|
962 cache| |
899 |
963 |
900 contentsString := contentsStringArg. |
964 contentsString := contentsStringArg. |
901 ignCaseInContents ifTrue:[ contentsString := contentsString asLowercase ]. |
965 ignCaseInContents ifTrue:[ contentsString := contentsString asLowercase ]. |
902 notContentsString := notContentsStringArg. |
966 notContentsString := notContentsStringArg. |
903 ignCaseInNotContents ifTrue:[ notContentsString := notContentsString asLowercase ]. |
967 ignCaseInNotContents ifTrue:[ notContentsString := notContentsString asLowercase ]. |
904 |
968 |
|
969 filenameToCompareContentsOrNil notNil ifTrue:[ |
|
970 fileSizeSearchFor := filenameToCompareContentsOrNil fileSize. |
|
971 fileSearchedFor := filenameToCompareContentsOrNil pathName. |
|
972 fileMD5SearchedFor := MD5Stream hashValueOfFile:filenameToCompareContentsOrNil. |
|
973 remember := self rememberInCache value. |
|
974 remember ifTrue:[ |
|
975 ContentsInfoCache isNil ifTrue:[ |
|
976 ContentsInfoCache := Dictionary new. |
|
977 ] |
|
978 ]. |
|
979 ]. |
|
980 cache := ContentsInfoCache. |
|
981 |
905 dir := aDirectory asFilename. |
982 dir := aDirectory asFilename. |
906 self changeInformationTo:'Find File ' , '- searching .' , ((dir name) copyFrom:(self searchDirectoryHolder value asString size + 1)) toTab:false. |
983 self changeInformationTo:'Find File ' , '- searching .' , ((dir name) copyFrom:(self searchDirectoryHolder value asString size + 1)) toTab:false. |
907 |
984 |
908 list := self resultList. |
985 list := self resultList. |
909 |
986 |
910 filenameToCompareContentsOrNil notNil ifTrue:[ |
987 filenameToCompareContentsOrNil notNil ifTrue:[ |
911 doesFileMatch := |
988 doesFileMatch := |
912 [:f | |
989 [:f | |
913 |contentsMatches| |
990 |contentsMatches fileMD5 fileName fileSize cacheLine| |
914 |
991 |
915 "/ contents compare ... |
992 "/ contents compare ... |
916 contentsMatches := false. |
993 contentsMatches := false. |
917 f pathName ~= filenameToCompareContentsOrNil pathName ifTrue:[ |
994 fileName := f pathName. |
918 f fileSize == filenameToCompareContentsOrNil fileSize ifTrue:[ |
995 fileName ~= fileSearchedFor ifTrue:[ |
919 contentsToCompare isNil ifTrue:[ |
996 cacheLine := cache at:fileName ifAbsent:nil. |
920 filenameToCompareContentsOrNil fileSize < (512*1024) ifTrue:[ |
997 cacheLine notNil ifTrue:[ |
921 contentsToCompare := filenameToCompareContentsOrNil binaryContentsOfEntireFile |
998 fileSize := cacheLine at:1. |
922 ] |
999 fileMD5 := cacheLine at:2. |
|
1000 ]. |
|
1001 fileSize isNil ifTrue:[ |
|
1002 fileSize := f fileSize. |
|
1003 ]. |
|
1004 remember ifTrue:[ |
|
1005 cacheLine := cache at:fileName ifAbsentPut:[Array new:2]. |
|
1006 cacheLine at:1 put:fileSize. |
|
1007 ]. |
|
1008 fileSize == fileSizeSearchFor ifTrue:[ |
|
1009 fileMD5 isNil ifTrue:[ |
|
1010 fileMD5 := MD5Stream hashValueOfFile:f. |
|
1011 remember ifTrue:[ |
|
1012 cacheLine at:2 put:fileMD5 |
|
1013 ]. |
923 ]. |
1014 ]. |
924 contentsToCompare isNil ifTrue:[ |
1015 contentsMatches := (fileMD5 = fileMD5SearchedFor). |
925 "/ too large - compare block-wise ... |
1016 "/ contentsToCompare isNil ifTrue:[ |
926 contentsMatches := (filenameToCompareContentsOrNil sameContentsAs:f). |
1017 "/ filenameToCompareContentsOrNil fileSize < (512*1024) ifTrue:[ |
927 ] ifFalse:[ |
1018 "/ contentsToCompare := filenameToCompareContentsOrNil binaryContentsOfEntireFile |
928 contentsMatches := contentsToCompare = (f binaryContentsOfEntireFile). |
1019 "/ ] |
929 ] |
1020 "/ ]. |
|
1021 "/ contentsToCompare isNil ifTrue:[ |
|
1022 "/ "/ too large - compare block-wise ... |
|
1023 "/ contentsMatches := (filenameToCompareContentsOrNil sameContentsAs:f). |
|
1024 "/ ] ifFalse:[ |
|
1025 "/ contentsMatches := contentsToCompare = (f binaryContentsOfEntireFile). |
|
1026 "/ ] |
930 ]. |
1027 ]. |
931 ] ifFalse:[ |
1028 ] ifFalse:[ |
932 f isSymbolicLink ifTrue:[ |
1029 f isSymbolicLink ifTrue:[ |
933 list add: (f name , ' is a symbolic link to ' , f pathName). |
1030 list add: (f name , ' is a symbolic link to ' , f pathName). |
934 ] |
1031 ] |