FindFileApplication.st
changeset 4518 85b13890d7b1
parent 4336 b4228ddf2183
child 4638 79734f7bdfc4
--- a/FindFileApplication.st	Sat Feb 01 00:25:38 2003 +0100
+++ b/FindFileApplication.st	Sun Feb 02 16:51:29 2003 +0100
@@ -1,11 +1,12 @@
 "{ Package: 'stx:libtool' }"
 
 AbstractFileApplicationNoteBookComponent subclass:#FindFileApplication
-	instanceVariableNames:'contentsPatternHolder ignoreCaseInName notSearchForSameContents
-		namePatternHolder ignoreCaseInContents searchDirectoryHolder
-		findFileView searchResultTable resultList enableStop enableSearch
-		stopSignal accessLock searchTask expanded searchRecursively
-		selectionHolder hasListEntries targetApplication'
+	instanceVariableNames:'contentsPatternHolder searchDirectories ignoreCaseInName
+		notSearchForSameContents namePatternHolder ignoreCaseInContents
+		searchDirectoryHolder findFileView searchResultTable resultList
+		enableStop enableSearch stopSignal accessLock searchTask expanded
+		searchRecursively selectionHolder hasListEntries
+		targetApplication'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Interface-Tools-File'
@@ -73,7 +74,7 @@
           #name: 'File Search'
           #min: #(#Point 377 131)
           #max: #(#Point 1280 1024)
-          #bounds: #(#Rectangle 16 42 681 374)
+          #bounds: #(#Rectangle 16 46 681 378)
         )
         #component: 
        #(#SpecCollection
@@ -92,15 +93,37 @@
              #(#SpecCollection
                 #collection: #(
                  #(#LabelSpec
+                    #label: 'Directory:'
+                    #name: 'DirectoryLabel'
+                    #layout: #(#LayoutFrame 4 0 7 0 136 0 24 0)
+                    #translateLabel: true
+                    #adjust: #left
+                  )
+                 #(#FilenameInputFieldSpec
+                    #name: 'DirectoryEntryField'
+                    #layout: #(#LayoutFrame 140 0 4 0 -115 1 24 0)
+                    #model: #searchDirectoryHolder
+                    #immediateAccept: true
+                    #acceptOnPointerLeave: false
+                  )
+                 #(#CheckBoxSpec
+                    #label: 'Recursively'
+                    #name: 'RecursiveSearchCheckBox'
+                    #layout: #(#LayoutFrame -97 1 5 0 0 1 28 0)
+                    #tabable: true
+                    #model: #searchRecursively
+                    #translateLabel: true
+                  )
+                 #(#LabelSpec
                     #label: 'Search files named:'
-                    #name: 'Label1'
-                    #layout: #(#LayoutFrame 3 0 7 0 148 0 24 0)
+                    #name: 'FileNameLabel'
+                    #layout: #(#LayoutFrame 4 0 31 0 136 0 48 0)
                     #translateLabel: true
                     #adjust: #left
                   )
                  #(#InputFieldSpec
-                    #name: 'EntryField1'
-                    #layout: #(#LayoutFrame 140 0 4 0 -115 1 24 0)
+                    #name: 'FileNameEntryField'
+                    #layout: #(#LayoutFrame 140 0 29 0 -228 1 49 0)
                     #tabable: true
                     #model: #namePatternHolder
                     #immediateAccept: true
@@ -108,23 +131,31 @@
                     #acceptOnPointerLeave: false
                   )
                  #(#CheckBoxSpec
+                    #label: 'Directories'
+                    #name: 'SearchDirectoriesCheckBox'
+                    #layout: #(#LayoutFrame -211 1 30 0 -114 1 50 0)
+                    #tabable: true
+                    #model: #searchDirectories
+                    #translateLabel: true
+                  )
+                 #(#CheckBoxSpec
                     #label: 'Ignore case'
-                    #name: 'CheckBox1'
-                    #layout: #(#LayoutFrame -97 1 5 0 1 1 28 0)
+                    #name: 'IgnoreCaseInNameCheckBox'
+                    #layout: #(#LayoutFrame -97 1 30 0 0 1 50 0)
                     #tabable: true
                     #model: #ignoreCaseInName
                     #translateLabel: true
                   )
                  #(#LabelSpec
                     #label: 'Containing the string:'
-                    #name: 'Label2'
-                    #layout: #(#LayoutFrame 4 0 31 0 136 0 48 0)
+                    #name: 'ContentsLabel'
+                    #layout: #(#LayoutFrame 4 0 57 0 136 0 74 0)
                     #translateLabel: true
                     #adjust: #left
                   )
                  #(#InputFieldSpec
-                    #name: 'EntryField2'
-                    #layout: #(#LayoutFrame 140 0 29 0 -115 1 49 0)
+                    #name: 'ContentsEntryField'
+                    #layout: #(#LayoutFrame 140 0 54 0 -115 1 74 0)
                     #enableChannel: #notSearchForSameContents
                     #tabable: true
                     #model: #contentsPatternHolder
@@ -133,35 +164,13 @@
                   )
                  #(#CheckBoxSpec
                     #label: 'Ignore case'
-                    #name: 'CheckBox2'
-                    #layout: #(#LayoutFrame -97 1 30 0 4 1 50 0)
+                    #name: 'IgnoreCaseInContentsCheckBox'
+                    #layout: #(#LayoutFrame -97 1 54 0 0 1 77 0)
                     #enableChannel: #notSearchForSameContents
                     #tabable: true
                     #model: #ignoreCaseInContents
                     #translateLabel: true
                   )
-                 #(#LabelSpec
-                    #label: 'Directory:'
-                    #name: 'Directory'
-                    #layout: #(#LayoutFrame 4 0 57 0 136 0 74 0)
-                    #translateLabel: true
-                    #adjust: #left
-                  )
-                 #(#FilenameInputFieldSpec
-                    #name: 'FilenameEntryField1'
-                    #layout: #(#LayoutFrame 140 0 54 0 -115 1 74 0)
-                    #model: #searchDirectoryHolder
-                    #immediateAccept: true
-                    #acceptOnPointerLeave: false
-                  )
-                 #(#CheckBoxSpec
-                    #label: 'Recursively'
-                    #name: 'CheckBox3'
-                    #layout: #(#LayoutFrame -97 1 54 0 1 1 77 0)
-                    #tabable: true
-                    #model: #searchRecursively
-                    #translateLabel: true
-                  )
                  )
                
               )
@@ -397,18 +406,18 @@
 
     dir := self searchDirectoryHolder value.
     dir isNil ifTrue:[
-        Dialog warn:'please type in a Directory first'.
+        Dialog warn:'Missing directory name'.
         ^ self.
     ].
     dir asFilename exists not ifTrue:[
-        Dialog warn:dir, 'not exists'.
+        Dialog warn:('No such directory: %1' bindWith:dir asString allBold).
         ^ self.
     ].
     
     searchTask notNil ifTrue:[
         (Dialog 
-            confirm:(resources string:'there is already a find file running !!') withCRs
-            yesLabel:(resources at:'Stop and continue')
+            confirm:(resources string:'There is already another find-file task running !!') withCRs
+            yesLabel:(resources at:'Stop other Task and Proceed')
             noLabel:(resources at:'Cancel'))
         ifFalse:[^ self].
         self stop.
@@ -439,12 +448,14 @@
                 self changeInformationTo:'Find File ' , '- search started ' toTab:true.
                 self 
                     doFindFileNamed:namePatterns
-                    ignoreCase:self ignoreCaseInName value
+                    directories:(self searchDirectories value)
+                    ignoreCase:(self ignoreCaseInName value)
                     containingString:contentsPattern
-                    ignoreCaseInContents:self ignoreCaseInContents value
+                    ignoreCaseInContents:(self ignoreCaseInContents value)
                     sameContentsAsFile:nil 
                     sameContentsAs:nil 
-                    in:self searchDirectoryHolder value.
+                    in:(self searchDirectoryHolder value).
+
                 self enableStop value:false.
                 self enableSearch value:true.
                 self changeInformationTo:'Find File ' , '- search finished' toTab:true.
@@ -602,6 +613,13 @@
     ^ resultList.
 !
 
+searchDirectories
+    searchDirectories isNil ifTrue:[
+        searchDirectories := false asValue.
+    ].
+    ^ searchDirectories.
+!
+
 searchDirectoryHolder
 
     searchDirectoryHolder isNil ifTrue:[
@@ -726,7 +744,7 @@
 
 !FindFileApplication methodsFor:'private - file stuff'!
 
-doFindFileNamed:namePatterns ignoreCase:ignCaseInName containingString:contentsString ignoreCaseInContents:ignCaseInString sameContentsAsFile:filenameToCompareContentsOrNil sameContentsAs:bytesToCompareContentsOrNil in:aDirectory
+doFindFileNamed:namePatterns directories:searchDirectories ignoreCase:ignCaseInName containingString:contentsString ignoreCaseInContents:ignCaseInString sameContentsAsFile:filenameToCompareContentsOrNil sameContentsAs:bytesToCompareContentsOrNil in:aDirectory
 
     |dir subDirs nameMatches contentsMatches lines contentsToCompare list|
 
@@ -740,69 +758,75 @@
     dir := aDirectory asFilename.
     self changeInformationTo:'Find File ' , '- searching .' , ((dir name) copyFrom:(self searchDirectoryHolder value asString size + 1)) toTab:false.
     (dir directoryContents ? #()) sort do:[:fn |
-        |f|
+        |f isDirectory|
 
         f := dir construct:fn.
-        f isDirectory ifTrue:[
+        isDirectory := f isDirectory.
+        isDirectory ifTrue:[
             f isSymbolicLink ifFalse:[
                 subDirs add:f
             ]
-        ] ifFalse:[
+        ].
+        (searchDirectories or:[isDirectory not]) ifTrue:[
             (nameMatches := namePatterns isNil) ifFalse:[
                 ignCaseInName ifTrue:[
                     nameMatches := namePatterns contains:[:aPattern | aPattern match:(fn asLowercase)]
                 ] ifFalse:[
-                    nameMatches := namePatterns contains:[:aPattern | aPattern  match:fn]
+                    nameMatches := namePatterns contains:[:aPattern | aPattern match:fn]
                 ]
             ].
             nameMatches ifTrue:[
-                filenameToCompareContentsOrNil notNil ifTrue:[
-                    "/ contents compare ...
-                    contentsMatches := false.
-                    f pathName ~= filenameToCompareContentsOrNil pathName ifTrue:[
-                        f fileSize == filenameToCompareContentsOrNil fileSize ifTrue:[
-                            contentsToCompare isNil ifTrue:[
-                                filenameToCompareContentsOrNil fileSize < (512*1024) ifTrue:[
-                                    contentsToCompare := filenameToCompareContentsOrNil binaryContentsOfEntireFile
+                isDirectory ifTrue:[
+                    contentsMatches := true.
+                ] ifFalse:[
+                    filenameToCompareContentsOrNil notNil ifTrue:[
+                        "/ contents compare ...
+                        contentsMatches := false.
+                        f pathName ~= filenameToCompareContentsOrNil pathName ifTrue:[
+                            f fileSize == filenameToCompareContentsOrNil fileSize ifTrue:[
+                                contentsToCompare isNil ifTrue:[
+                                    filenameToCompareContentsOrNil fileSize < (512*1024) ifTrue:[
+                                        contentsToCompare := filenameToCompareContentsOrNil binaryContentsOfEntireFile
+                                    ]
+                                ].
+                                contentsToCompare isNil ifTrue:[
+                                    "/ too large - compare block-wise ...
+                                    contentsMatches := (filenameToCompareContentsOrNil sameContentsAs:f).
+                                ] ifFalse:[
+                                    contentsMatches := contentsToCompare = (f binaryContentsOfEntireFile).
                                 ]
                             ].
-                            contentsToCompare isNil ifTrue:[
-                                "/ too large - compare block-wise ...
-                                contentsMatches := (filenameToCompareContentsOrNil sameContentsAs:f).
-                            ] ifFalse:[
-                                contentsMatches := contentsToCompare = (f binaryContentsOfEntireFile).
+                        ] ifFalse:[
+                            f isSymbolicLink ifTrue:[
+                                list add: (f name , ' is a symbolic link to ' , f pathName).
                             ]
-                        ].
-                    ] ifFalse:[
-                        f isSymbolicLink ifTrue:[
-                            list add: (f name , ' is a symbolic link to ' , f pathName).
                         ]
-                    ]
-                ] ifFalse:[
-                    "/ string search ...
-                    (contentsMatches := contentsString isNil) ifFalse:[
-                        (f exists and:[f isReadable]) ifFalse:[
-                            list add: (('*** ' , f pathName , ' skipped - unreadable or bad symbolic link ***') asText colorizeAllWith:(Color red darkened)).
-                        ] ifTrue:[
-                            f fileSize > (4024*1024) ifTrue:[
-                                list add: (('*** ' , f pathName , ' skipped - too large ***') asText colorizeAllWith:(Color red darkened)).
-                            ] ifFalse:[
-                                Stream lineTooLongErrorSignal handle:[:ex |
-                                    |cont|
+                    ] ifFalse:[
+                        "/ string search ...
+                        (contentsMatches := contentsString isNil) ifFalse:[
+                            (f exists and:[f isReadable]) ifFalse:[
+                                list add: (('*** ' , f pathName , ' skipped - unreadable or bad symbolic link ***') asText colorizeAllWith:(Color red darkened)).
+                            ] ifTrue:[
+                                f fileSize > (4024*1024) ifTrue:[
+                                    list add: (('*** ' , f pathName , ' skipped - too large ***') asText colorizeAllWith:(Color red darkened)).
+                                ] ifFalse:[
+                                    Stream lineTooLongErrorSignal handle:[:ex |
+                                        |cont|
 
-                                    "/ this typically happens, when a binary file is read linewise ...
-                                    cont := f readStream binary contentsOfEntireFile asString.
-                                    ignCaseInString ifTrue:[
-                                        contentsMatches := cont asLowercase includesString:contentsString asLowercase
-                                    ] ifFalse:[
-                                        contentsMatches := cont includesString:contentsString
-                                    ].
-                                ] do:[    
-                                    lines := f contents ? #().
-                                    ignCaseInString ifTrue:[
-                                        contentsMatches := (lines findFirst:[:l | l asLowercase includesString:contentsString asLowercase]) ~~ 0
-                                    ] ifFalse:[
-                                        contentsMatches := (lines findFirst:[:l | l includesString:contentsString]) ~~ 0
+                                        "/ this typically happens, when a binary file is read linewise ...
+                                        cont := f readStream binary contentsOfEntireFile asString.
+                                        ignCaseInString ifTrue:[
+                                            contentsMatches := cont asLowercase includesString:contentsString asLowercase
+                                        ] ifFalse:[
+                                            contentsMatches := cont includesString:contentsString
+                                        ].
+                                    ] do:[    
+                                        lines := f contents ? #().
+                                        ignCaseInString ifTrue:[
+                                            contentsMatches := (lines findFirst:[:l | l asLowercase includesString:contentsString asLowercase]) ~~ 0
+                                        ] ifFalse:[
+                                            contentsMatches := (lines findFirst:[:l | l includesString:contentsString]) ~~ 0
+                                        ].
                                     ].
                                 ].
                             ].
@@ -820,6 +844,7 @@
         subDirs do:[:dir |
             self
                 doFindFileNamed:namePatterns 
+                directories:searchDirectories
                 ignoreCase:ignCaseInName 
                 containingString:contentsString 
                 ignoreCaseInContents:ignCaseInString 
@@ -889,5 +914,5 @@
 !FindFileApplication class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FindFileApplication.st,v 1.8 2002-11-29 09:47:01 penk Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FindFileApplication.st,v 1.9 2003-02-02 15:51:29 cg Exp $'
 ! !